I have an array that makes and drops some pucks. If the pucks collide with the bar or go past 85% of Y then they get deleted. I have my collision check in the main loop. Everything works great until the sprite gets deleted, on the next loop I get an error saying that it can't find the sprite. Well I hope it can't I deleted it. I am not sure on how to get around the error. Also I would prefer not to use if and elseif statements all the time but I am drawing a blank on how to change it. Any help is greatly appreciated.
rem
rem AGK Application
rem
rem Portrait App
SetDisplayAspect( 0.66 )
#include "gameplay.agc"
Global dim pucks[5]
Global puckI
Global bar1
Global bar2
Global bar3
background = createSprite ( loadImage("background.jpg"))
setSpriteSize (background, 100, 100)
puckI = loadImage("puck.png")
bar1 = createSprite ( loadImage("longBar.jpg"))
setSpriteSize (bar1, 10, 2)
setSpritePosition (bar1, 15,70)
setSpritePhysicsOn(bar1, 1)
setSpriteShape(bar1,2)
bar2 = createSprite ( loadImage("longBar.jpg"))
setSpriteSize (bar2, 10, 2)
setSpritePosition (bar2, 15,75)
setSpritePhysicsOn(bar2, 1)
setSpriteShape(bar2,2)
bar3 = createSprite ( loadImage("longBar.jpg"))
setSpriteSize (bar3, 10, 2)
setSpritePosition (bar3, 15,80)
setSpritePhysicsOn(bar3, 1)
setSpriteShape(bar3,2)
SetJoystickScreenPosition ( 50, 90, 16 )
loadPuck()
do
collisions()
move()
Sync()
loop
function move()
X# = GetJoystickX ( )
if X#>0
x# = getJoystickX()+1.2
endif
if x# < 0
X# = getJoystickX() -1.2
endif
SetSpritePosition ( bar1, GetSpriteX (bar1 ) +x# , 70 )
SetSpritePosition ( bar2, getSpriteX (bar2 ) + X# , 75 )
SetSpritePosition ( bar3, getSpriteX (bar3 ) + X# , 80 )
if ( GetSpriteX ( bar1 ) < 0 )
SetSpriteX ( bar1, 0 )
endif
if ( GetSpriteX ( bar2 ) < 0 )
SetSpriteX ( bar2, 0 )
endif
if ( GetSpriteX ( bar3 ) < 0 )
SetSpriteX ( bar3, 0 )
endif
if ( GetSpriteX ( bar1 ) > 90 )
SetSpriteX ( bar1,90 )
endif
if ( GetSpriteX ( bar2 ) > 90 )
SetSpriteX ( bar2,90 )
endif
if ( GetSpriteX ( bar3 ) > 90 )
SetSpriteX ( bar3, 90 )
endif
endfunction
Function loadPuck()
xx# = 5
//start array max number of fire balls at one time
for i=1 to 5
//load up the sprite set all the parameters in one nice array
pucks[i] = createSprite (puckI)
setSpriteSize(pucks[i],5,-1)
setSpritePhysicsOn(pucks[i],2)
setSpriteDepth(pucks[i],10)
setSpriteshape(pucks[i],1)
setSpritePosition (pucks[i], xx#, yy#)
xx# = xx#+5
next i
endfunction
function collisions()
for i = 1 to 5
if getSpriteCollision(pucks[i], bar1)= 1
deleteSprite (pucks[i])
elseif getSpriteCollision(pucks[i], bar2)= 1
deleteSprite (pucks[i])
elseif getSpriteCollision(pucks[i], bar3)= 1
deleteSprite (pucks[i])
endif
if getSpriteY(pucks[i])>= 85
deleteSprite (pucks[i])
endif
next i
endfunction