Ok, it seems the same every run, just changes every reset of the sim!
I would show some code but it ain't easy to do with it being an editor an all! but here is all the code anyhow...
rem
rem AGK Application
rem
rem Landscape App
SetDisplayAspect( 1024.0 / 600.0 )
global physicsmode = 1
global physicsshape = 2
global cursorsprite = 6000
global cursorimage = 95
global swidth = 2
global sheight = 2
global gridx=1
global maxlayers = 8
global gridy=1
global layer=0
global state=0
global bricklimit=4999
global bricknum=0
global brickcount=0
global maxscroll=380
global minscroll=0
global scrollx#
global scrolly#
global level=1
global mode=0
global minimages=98
global maximages=126
global physicsrun=0
global angle#=0
global t$
global d$
global l$
global li$
global pss$
global ps$
global prrr$
global pshape$
rem ************** Setup tiles type ****************
type Ttiles
xloc as integer
yloc as integer
spritenumber as integer
physicstype as integer
spriteshape as integer
sizex as integer
sizey as integer
imagenumber as integer
spritedepth as integer
spriteangle as integer
imagenum as integer
sprdepth as integer
spritetype as integer
sprgroup as integer
spritelayer as integer
endtype
rem ************** Setup Mouse type *****************
type Tmouse
x1#
y1#
x2#
y2#
x3
y3
endtype
global Mouse as Tmouse
dim tile[5000,maxlayers] as Ttiles
dim deleted[5000]
SetPhysicsDebugOn()
init()
prrr$="Physics Shape = "
d$="Current Physics Mode = "
li$="Editing Level Number "
info$="Press h for help"
t$=d$+str(layer)
createtext(1,t$)
createtext(2,l$)
createtext(3,pshape$)
createtext(4,info$)
settextposition(4,70,1)
fixtexttoscreen(4,1)
settextcolor(4,255,3,3,200)
settextsize(1,3)
settextsize(2,3)
settextsize(3,3)
fixtexttoscreen(1,1)
fixtexttoscreen(2,1)
fixtexttoscreen(3,1)
rem ***************** Main Loop *****************
rem ***************** Clear the Level and set default values *******
clear_level()
Do
t$=d$+pm$
SetTextString(1,t$)
SetTextPosition(1,0,5)
l$=li$+str(level)
settextstring(2,l$)
settextposition(2,0,2)
select physicsmode
case 0:
pm$="Non"
Endcase
case 1:
pm$="Static"
endcase
case 2:
pm$="Dynamic"
endcase
case 3:
pm$="Kinematic"
endcase
endselect
select physicsshape
case 1
prr$="Circle"
endcase
case 2
prr$="Rectangle"
endcase
case 3
prr$="polygon"
endcase
endselect
pshape$=prrr$+prr$
SetTextString(3,pshape$)
SetTextPosition(3,0,9)
setspriteposition(cursorsprite,mouse.x3,mouse.y3)
handle_keys()
control()
scroll_control()
sync()
StepPhysics(0.02)
Loop
rem ***********************************************************
function handle_keys()
if getrawkeypressed(76)
inc layer
if layer>=maxlayers
layer=0
endif
endif
rem ********************** F2 to save ********************
if getrawkeypressed(113)
save(level)
endif
rem ********************** F1 to Load ********************
if getrawkeypressed(112)
clear_level()
load_level(level)
endif
rem ********************** Clear the Whole Level *************
if getrawkeypressed(67)
clear_level()
endif
rem ********************** Turn On All Physics ***************
rem ************* key 'p' runs physics simulation ************
if getrawkeypressed(80)
physicsrun=1
endif
if physicsrun=1
physicsrun=0
for r=0 to maxlayers
for n=1 to bricklimit
if tile[n,r].physicstype >0
setspritephysicson(n,tile[n,r].physicstype)
setspriteshape(n,tile[n,r].spriteshape)
endif
next r
next n
endif
rem **************** Adjust Physics type ***************
rem Use key 'm' to cycle through modes
if getrawkeypressed(77)
inc physicsmode
if physicsmode>3
physicsmode=0
endif
endif
if getrawkeypressed(78)
inc physicsshape
if physicsshape>3
physicsshape=1
endif
endif
rem ****************** Adjust sprites size.. ******************
rem ******************'a'= smaller width .. 'd'= bigger width .. *******************
rem ****************** Keys 'w'= smaller heigth .. 's'= larger heigth *******************
if getrawkeypressed(68)
swidth=swidth+1
setspritesize(cursorsprite,swidth,sheight)
endif
if getrawkeypressed(65) and swidth>1
swidth=swidth-1
setspritesize(cursorsprite,swidth,sheight)
endif
if getrawkeypressed(87) and sheight>1
sheight=sheight-1
setspritesize(cursorsprite,swidth,sheight)
endif
if getrawkeypressed(83)
sheight=sheight+1
setspritesize(cursorsprite,swidth,sheight)
endif
rem ****************** Scroll through textures with + and - keys
if getrawkeypressed(219) and cursorimage>minimages
dec cursorimage
setspriteimage(cursorsprite,cursorimage)
endif
if getrawkeypressed(221) and cursorimage<maximages
inc cursorimage
setspriteimage(cursorsprite,cursorimage)
endif
rem ****************** Rotate Sprite using key 'r'
if getrawkeypressed(82)
angle#=angle#+45.5
setspriteangle(cursorsprite,angle#)
endif
if getrawkeypressed(86)
angle#=0
setspriteangle(cursorsprite,angle#)
endif
rem ***********************************************************************************
endfunction
function control()
state=getpointerpressed()
if state>0
select mode
`*** Placement Mode
case 0
for n=1 to bricklimit
if tile[n,layer].xloc = Mouse.x3 and tile[n,layer].yloc = Mouse.y3 and tile[n,layer].spritenumber <>0
found=1
f=tile[n,layer].spritenumber
exit
endif
next n
if found=0 and brickcount<bricklimit
for n=1 to bricklimit
if deleted[n]>0
founddeleted=1
sprnum=n
exit
endif
next n
if founddeleted =0
inc brickcount
inc bricknum
id2=bricknum
else
id2=sprnum
inc brickcount
deleted[sprnum]=0
Endif
if getspriteexists(id2) = 0
tile[id2,layer].xloc = Mouse.x3
tile[id2,layer].yloc = Mouse.y3
tile[id2,layer].spritenumber = id2
tile[id2,layer].imagenum = cursorimage
tile[id2,layer].sizex=swidth
tile[id2,layer].sizey=sheight
tile[id2,layer].physicstype = physicsmode
tile[id2,layer].spriteshape=physicsshape
tile[id2,layer].sprdepth =2
tile[id2,layer].spritetype = myspritetype
tile[id2,layer].sprgroup=myspritegroup
tile[id2,layer].spritelayer=layer
createsprite(id2,cursorimage)
setspritesize(id2,tile[id2,layer].sizex,tile[id2,layer].sizey)
print("sprite number "+str(tile[id2,layer].spritenumber))
setspriteangle(id2,getspriteangle(cursorsprite))
tile[id2,layer].spriteangle= getspriteangle(id2)
setspriteposition(id2,tile[id2,layer].xloc,tile[id2,layer].yloc)
setspritedepth(id2,tile[id2,layer].sprdepth)
endif
endif
endcase
`*** Edit Mode
case 1
r=getspritehit(getspritex(cursorsprite),getspritey(cursorsprite))
if r>0
if tile[r,layer].spritelayer = layer
deletesprite(r)
tile[r,layer].xloc = 0
tile[r,layer].yloc = 0
tile[r,layer].spritenumber = 0
tile[r,layer].imagenum = 0
tile[r,layer].physicstype = 0
tile[r,layer].sprdepth = 0
tile[r,layer].spritelayer=0
dec brickcount
deleted[r]=1
endif
endif
endcase
endselect
endif
FillMouse(gridx,gridy)
endfunction
function scroll_control()
x#=getvirtualjoystickx(1)
y#=getvirtualjoysticky(1)
ohx#=getspritex(cursorsprite)
ohy#=getspritey(cursorsprite)-1
if x#<>0 or y#<>0
scrollx#=scrollx#+x#
scrolly#=scrolly#+y#
if scrollx#>maxscroll
scrollx#=maxscroll
endif
if scrollx#<minscroll
scrollx#=minscroll
endif
if scrolly#>maxscroll
scrolly#=maxscroll
endif
if scrolly#<minscroll
scrolly#=minscroll
endif
y1=y1-scrolly#
x1=x1-scrollx#
SetViewOffset( scrollx#,scrolly# )
endif
endfunction
rem ********* initialize function ***********
function init()
mode$="Placement Mode"
loadimage(cursorimage,"cursor.png")
loadimage(96,"overhead.png")
loadimage(97,"grass2.png")
loadimage(98,"hole.png")
loadimage(99,"ball.png")
loadimage(100,"redbrick.png")
loadimage(101,"redbrick.png")
loadimage(102,"bluebrick2.png")
loadimage(103,"greenbrick.png")
loadimage(104,"physicsbuttonup.png")
loadimage(105,"physicsbuttondown.png")
loadimage(106,"savebuttonup.png")
loadimage(107,"savebuttondown.png")
loadimage(108,"joystickouter.png")
loadimage(109,"joystickinner.png")
loadimage(110,"loadbuttonup.png")
loadimage(111,"loadbuttondown.png")
loadimage(112,"clearbuttonup.png")
loadimage(113,"clearbuttondown.png")
loadimage(114,"sizebuttonplusup.png")
loadimage(115,"sizebuttonplusdown.png")
loadimage(116,"sizebuttonminusup.png")
loadimage(117,"sizebuttonminusdown.png")
loadimage(118,"shapebuttonup.png")
loadimage(119,"shapebuttondown.png")
loadimage(120,"panel.png")
loadimage(121,"gfxbuttonplusup.png")
loadimage(122,"gfxbuttonplusdown.png")
loadimage(123,"gfxbuttonminusup.png")
loadimage(124,"gfxbuttonminusdown.png")
loadimage(125,"pool_table.png")
loadimage(126,"concrete.png")
setclearcolor(0,25,0)
clearscreen()
createsprite(cursorsprite,cursorimage)
`setspriteoffset(cursorsprite,0,0)
setspritesize(cursorsprite,swidth,sheight)
setspritedepth(cursorsprite,0)
addvirtualjoystick(1,90,90,10)
setvirtualjoystickimageinner(1,109)
setvirtualjoystickimageouter(1,108)
endfunction
function FillMouse(gridx,gridy)
Mouse.x1#=getpointerx()
Mouse.y1#=getpointery()
Mouse.x2#=screentoworldx(Mouse.x1#)
Mouse.y2#=screentoworldy(Mouse.y1#)
Mouse.x3=floor(Mouse.x2#/gridx)*gridx
Mouse.y3=floor(Mouse.y2#/gridy)*gridy
endfunction
function save(level)
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".dat"
myfile = OpenToWrite(f$, 0)
for r=0 to maxlayers
for n = 1 to bricklimit
writeinteger (myfile,tile[n,r].xloc)
writeinteger (myfile,tile[n,r].yloc)
writeinteger (myfile,tile[n,r].imagenum)
writeinteger (myfile,tile[n,r].spritenumber)
writeinteger (myfile,tile[n,r].sizex)
writeinteger (myfile,tile[n,r].sizey)
writeinteger (myfile,tile[n,r].physicstype)
writeinteger (myfile,tile[n,r].sprgroup)
writeinteger (myfile,tile[n,r].sprdepth)
writeinteger (myfile,tile[n,r].spriteangle)
writeinteger (myfile,tile[n,r].spriteshape)
writeinteger (myfile,tile[n,r].spritetype)
writeinteger (myfile,tile[n,r].spritelayer)
`************** Layer 2 data ********************
next n
next r
print ("SAVED!")
closefile (myfile)
endfunction
function clear_level()
for n=1 to bricklimit
if getspriteexists(n)
deletesprite(n)
deleted[n]=0
endif
next n
for r=0 to maxlayers
for n=1 to bricklimit
tile[n,r].xloc = 0
tile[n,r].yloc = 0
tile[n,r].imagenum = 0
tile[n,r].spritenumber = 0
tile[n,r].sizey= 0
tile[n,r].physicstype =0
tile[n,r].sprgroup = 0
tile[n,r].sprdepth = 0
tile[n,r].spriteangle = 0
tile[n,r].spriteshape = 2
tile[n,r].spritetype = 0
tile[n,r].spritelayer = 0
next n
next r
brickcount = 0
bricknum=0
endfunction
function load_level(level)
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".dat"
if getfileexists(f$) =0
print (" level file doesn't exist ")
sync()
found3=1
endif
if found3=0
myfile = OpenToread(f$)
`brickcount = readinteger (myfile)
print ("Please wait")
for r=0 to maxlayers
for n = 1 to bricklimit
xl = readinteger (myfile)
yl = readinteger (myfile)
im = readinteger (myfile)
sn= readinteger (myfile)
sx = readinteger (myfile)
sy = readinteger (myfile)
pt = readinteger (myfile)
sprg = readinteger (myfile)
sprd = readinteger (myfile)
spra=readinteger (myfile)
sprshape= readinteger (myfile)
sprtype= readinteger (myfile)
sprlayer = readinteger (myfile)
`****
tile[n,r].xloc = xl
tile[n,r].yloc = yl
tile[n,r].imagenum = im
tile[n,r].spritenumber = sn
tile[n,r].sizex= sx
tile[n,r].sizey= sy
tile[n,r].physicstype = pt
tile[n,r].sprgroup = sprg
tile[n,r].sprdepth = sprd
tile[n,r].spriteangle = spra
tile[n,r].spriteshape = sprshape
tile[n,r].spritetype = sprtype
tile[n,r].spritelayer = sprlayer
if tile[n,r].spritenumber <> 0
inc brickcount
inc bricknum
createsprite(tile[n,r].spritenumber,tile[n,r].imagenum)
setspritesize(tile[n,r].spritenumber,tile[n,r].sizex,tile[n,r].sizey)
setspriteangle(tile[n,r].spritenumber,tile[n,r].spriteangle)
setspriteposition(tile[n,r].spritenumber,tile[n,r].xloc,tile[n,r].yloc)
setspritedepth(tile[n,r].spritenumber,tile[n,r].sprdepth)
endif
next n
next r
closefile (myfile)
endif
endfunction
Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk