Wierd problem with collision detection

BlitzPlus Forums/BlitzPlus Beginners Area/Wierd problem with collision detection

Conman(Posted 2008) [#1]
Hey guys, im still learning and so far whenever i plug in the code for
If (ImageOverlap(alien\image,alien\x,alien\y,Laser\image,laser\x,laser\y))


and when i finish the rest of the parameters it says "object does not exist", but i have the lasers image in the same place as the source code. Whats happening??


GfK(Posted 2008) [#2]
It doesn't mean the image file is missing - it means the alien or laser object is missing, which narrows it down to two possibilites:

1. You haven't created it.
2. You've created it and deleted it somewhere else.

If you're doing any collision checks that would result in either object being deleted, do that last, as once an object has been deleted you can no longer work with it and you'll get the error you described.

If this doesn't help, post some code.


Conman(Posted 2008) [#3]
;Create the playing field
Global player1.player1 = New player1
player1\x = 400
player1\y = 500
player1\hitpoints = 5
player1\image2 = LoadImage("player1.bmp")
Global alien.alien = New alien
alien\x = 400
alien\y = 200
alien\xv = Rand(-5,5)
alien\yv = Rand(-5,5)
alien\image = LoadImage("enemy.bmp")
Global Laser.Laser = New Laser
Laser\x = player1\x
Laser\y = player1\y
Laser\image = LoadImage("laser.bmp")

I did create, when i run the debugger it says nothings wrong so i can't find a problem wrong with it.


amu lojes(Posted 2008) [#4]
if imageoverla(...)

delete alein (say ) ;or delete
endif

then the problem will occur

instead of deleting

put alien in another status


for al.alien = each alein

select al\status
case 0
drawimage alien,al\x,al\y,frmalien
if imageoverlap(...)
al\status = 1
endif

case 1

end selct


hope this should work


Conman(Posted 2008) [#5]
It always says "wend without while" whenever i try to run it after i put those lines of code in

;If player crashes into the enemy, reset the game
If (ImagesOverlap(player1\image2,player1\x,player1\y,alien\image,alien\x,alien\y))
player1\hitpoints = player1\hitpoints + 1
player1\x = 400
player1\y = 500
alien\x = 400
alien\y = 200
alien\xv = Rand(-15,15)
alien\yv = Rand(-15,15)
EndIf

;If player shoots alien, bring in a new one where it originally started
For alien.alien = Each alien
Select alien\status

Case 1
DrawImage alienimage, alien\x, alien\y,frmalien
If (ImagesOverlap(alien\image,alien\x,alien\y,Laser\image3,Laser\x,Laser\y))
alien\x = 400
alien\y = 200
Laser\x = player1\x
Laser\y = player1\y
alien\xv = Rand(-15,15)
alien\yv = Rand(-15,15)
alien\status = 1
EndIf
Case 2
DrawImage alienimage, alien\x,alien\y,frmalien
If (ImagesOverlap(alien\image,alien\x,alien\y,Bullet\image3,Bullet\x,Bullet\y))
alien\x = 400
alien\y = 200
Bullet\x = player1\x
Bullet\y = player1\y
alien\xv = Rand(-15,15)
alien\yv = Rand(-15,15)
alien\status = 2
EndIf
End Select


SuperSonic7(Posted 2008) [#6]
Well, do you have the "Wend" command anywhere in your program? Or "While" where it's not needed?