I know this repost is only related by the fact that it is still about the editor i am trying to write, but could you please tell me the best way to ensure that i dont place more than one sprite at the current pointer location? this is the code I have so far to give you a grasp of how it is setup:
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
global cursorimage = 600
global gridx=8
global gridy=4
sprite=cre
global pointer = 600
global bricklimit=500
global brickcount = 0
global buttonload = 1
global buttonsave = 2
global buttonclear = 3
global brickimage = 1
type brick
xloc as integer
yloc as integer
imagenum as integer
endtype
dim brick[500] as brick
init()
`*********************************************** Main Loop **************************************
do
print("Number of bricks: "+str(brickcount))
print("poop: "+str(v))
x1=floor(getpointerx()/gridx)
y1=floor(getpointery()/gridy)
setspriteposition(pointer,x1*gridx,y1*gridy)
lb = getvirtualbuttonstate(buttonload)
sb = getvirtualbuttonstate(buttonsave)
cb = getvirtualbuttonstate(buttonclear)
state=getpointerstate()
if v = 0
if state>0 and brickcount<bricklimit
inc brickcount
createsprite(brickcount,brickimage)
SetSpriteGroup ( brickcount,2)
setspritesize(brickcount,8,4)
setspriteposition (brickcount,x1*gridx,y1*gridy)
brick[brickcount].xloc = x1*gridx
brick[brickcount].yloc = y1*gridy
brick[brickcount].imagenum = brickimage
endif
endif
if lb>0
clear_level()
load_level()
endif
if sb > 0
save_level()
endif
if cb > 0
clear_level()
endif
Print("hello world")
setspritedepth(pointer,1)
Sync()
loop
`************************************************************************************************
`
`
`
`
`
`
`************************************************* Init Function ********************************
function init()
cursorimage = loadimage("cursor.png")
brickimage = loadimage("redbrick.png")
createsprite(pointer,cursorimage)
mx# = getpointerx()
my# = getpointery()
setspriteposition(pointer,mx#,my#)
setspritesize(pointer,8,4)
AddVirtualButton(buttonload,10,10,5)
AddVirtualButton(buttonsave,10,30,5)
AddVirtualButton(buttonclear,80,10,5)
endfunction
`************************************************************************************************
`
`
`
`
`************************************************ Load Function *********************************
function load_level()
myfile = OpenToread("Test2.dat")
`brickcount = readinteger (myfile)
for n = 1 to bricklimit
xl = readinteger (myfile)
yl = readinteger (myfile)
im = readinteger (myfile)
brick[n].xloc = xl
brick[n].yloc = yl
brick[n].imagenum = im
if brick[n].imagenum <> 0
inc brickcount
createsprite (brickcount,brick[n].imagenum)
SetSpriteGroup ( brickcount,2)
setspritesize(brickcount,8,4)
setspriteposition(brickcount,brick[n].xloc,brick[n].yloc)
endif
next n
closefile (myfile)
print("loaded!!")
endfunction
`************************************************************************************************
`
`
`
`
`************************************************ Save Function *********************************
function save_level()
myfile = OpenToWrite("Test2.dat", 0)
`writeinteger (myfile,brickcount)
for n = 1 to bricklimit
writeinteger (myfile,brick[n].xloc)
writeinteger (myfile,brick[n].yloc)
writeinteger (myfile,brick[n].imagenum)
next n
closefile (myfile)
print ("saved !!")
endfunction
`************************************************************************************************
`
`
`
`
`*********************************************** Clear Function *********************************
function clear_level
deleteallsprites()
createsprite(pointer,cursorimage)
setspritesize(pointer,8,4)
brickcount = 0
sync()
endfunction
`************************************************************************************************
I have included this zip of the project file if anyone is interested
thanks again for any help
Modified the code slightly in the zip but only added to the reset function to clear the brick type fields
rem
rem AGK Application
rem
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
global cursorimage = 700
global gridx=8
global gridy=4
sprite=cre
global pointer = 700
global bricklimit=600
global brickcount = 0
global buttonload = 1
global buttonsave = 2
global buttonclear = 3
global brickimage = 1
type brick
xloc as integer
yloc as integer
imagenum as integer
endtype
dim brick[600] as brick
init()
`*********************************************** Main Loop **************************************
do
print("Number of bricks: "+str(brickcount))
print("poop: "+str(v))
x1=floor(getpointerx()/gridx)
y1=floor(getpointery()/gridy)
setspriteposition(pointer,x1*gridx,y1*gridy)
lb = getvirtualbuttonstate(buttonload)
sb = getvirtualbuttonstate(buttonsave)
cb = getvirtualbuttonstate(buttonclear)
state=getpointerstate()
`**************** Place a brick at current pointer location
if state>0 and brickcount<bricklimit
inc brickcount
createsprite(brickcount,brickimage)
SetSpriteGroup ( brickcount,2)
setspritesize(brickcount,8,4)
setspriteposition (brickcount,x1*gridx,y1*gridy)
brick[brickcount].xloc = x1*gridx
brick[brickcount].yloc = y1*gridy
brick[brickcount].imagenum = brickimage
endif
endif
if lb>0
clear_level()
load_level()
endif
if sb > 0
save_level()
endif
if cb > 0
clear_level()
endif
Print("hello world")
setspritedepth(pointer,1)
Sync()
loop
`************************************************************************************************
`
`
`
`
`
`
`************************************************* Init Function ********************************
function init()
cursorimage = loadimage("cursor.png")
brickimage = loadimage("redbrick.png")
createsprite(pointer,cursorimage)
mx# = getpointerx()
my# = getpointery()
setspriteposition(pointer,mx#,my#)
setspritesize(pointer,8,4)
AddVirtualButton(buttonload,10,10,5)
AddVirtualButton(buttonsave,10,30,5)
AddVirtualButton(buttonclear,80,10,5)
endfunction
`************************************************************************************************
`
`
`
`
`************************************************ Load Function *********************************
function load_level()
myfile = OpenToread("Test2.dat")
`brickcount = readinteger (myfile)
for n = 1 to bricklimit
xl = readinteger (myfile)
yl = readinteger (myfile)
im = readinteger (myfile)
brick[n].xloc = xl
brick[n].yloc = yl
brick[n].imagenum = im
if brick[n].imagenum <> 0
inc brickcount
createsprite (brickcount,brick[n].imagenum)
SetSpriteGroup ( brickcount,2)
setspritesize(brickcount,8,4)
setspriteposition(brickcount,brick[n].xloc,brick[n].yloc)
endif
next n
closefile (myfile)
print("loaded!!")
endfunction
`************************************************************************************************
`
`
`
`
`************************************************ Save Function *********************************
function save_level()
myfile = OpenToWrite("Test2.dat", 0)
`writeinteger (myfile,brickcount)
for n = 1 to bricklimit
writeinteger (myfile,brick[n].xloc)
writeinteger (myfile,brick[n].yloc)
writeinteger (myfile,brick[n].imagenum)
next n
closefile (myfile)
print ("saved !!")
endfunction
`************************************************************************************************
`
`
`
`
`*********************************************** Clear Function *********************************
function clear_level
deleteallsprites()
createsprite(pointer,cursorimage)
setspritesize(pointer,8,4)
brickcount = 0
for n=1 to brickcount
brick[n].xloc = 0
brick[n].yloc = 0
brick[n].imagenum = 0
next n
sync()
endfunction
`************************************************************************************************
Hail to the king, baby!