I've been trying some more with function this time but still no luck. I also think a 1-pixel difference is too small.
rem config
hide mouse
sync rate 75
sync on
autocam off
backdrop on
color backdrop rgb(0,0,0)
rem loading images and set variables/constants
load image "player.bmp", 1
load image "bullet.bmp", 2
load image "enemy.bmp", 3
dim enemyx(20)
dim enemyy(20)
for n=1 to 20
initializeenemy(n)
next n
position mouse 0,400
rem main game loop
do
playerx = mousex()
playery = mousey()
for x=1 to 20
moveenemy(x)
collision(enemyx(x),enemyy(x),firex,firey)
next x
gosub player
sync
loop
function collision(EnemyX, EnemyY, BulletX, BulletY)
print "ENEMYX:"; EnemyX; "BulletX:"; BulletX;" - EnemyY:"; EnemyY; "BulletY:";BulletY
if BulletY = EnemyY
if BulletX = EnemyX
hide sprite 3
endif
endif
endfunction
function initializeenemy(n)
enemyx(n) = rnd(600)
enemyy(n) = -1 * (rnd(500))
endfunction
function moveenemy(num)
enemyy(num) = enemyy(num) + 3
sprite num,enemyx(num),enemyy(num),3
sprite 2, enemyx(num),enemyy(num),2
if enemyy(num) > 480
initializeenemy(num)
endif
endfunction
player:
if playerx < 0 : playerx = 0
else if playerx > 608 : playerx = 608
endif : endif
if playery < 400 : playery = 400
else if playery > 450 : playery = 450
endif : endif
clicked = mouseclick()
if clicked = 1
if playerfired = 0
gosub shoot
endif
endif
if playerfired = 1
gosub movebullets
endif
sprite 1,playerx,playery,1
show sprite 1
return
shoot:
playerfired = 1
firex = playerx
firey = playery - 5
return
movebullets:
firey = firey - 10
sprite 2,firex,firey,2
show sprite 2
if firey < 0
hide sprite 2
playerfired = 0
endif
return
I'd rather just use SPRITE HIT or SPRITE COLLISION but I don't know exactly what to use for the parameters and where to place it...
Trying to help where I can [Newbie status
]