health system not working.

BlitzPlus Forums/BlitzPlus Programming/health system not working.

DI(Posted 2012) [#1]
Hello!
I have some problems with my health system.
You have 3 life's, if you get hit by a bullet you are supposed to lose 1 life but instead you instantly die.

here's the full code: http://pastebin.com/jbgqGKyJ

I think this part of the code is the problem:

Function Fplayerscore()

If ImagesCollide(bullet1Image,bullet1X,bullet1Y,0,player2Image,player2X,player2Y,0) Then P1score = P1score - 1
If ImagesCollide(bullet2Image,bullet2X,bullet2Y,0,player1Image,player1X,player1Y,0) Then P2score = P2score - 1

If P1score = 0 Then stage = 2
If P2score = 0 Then stage = 3

End Function



DI(Posted 2012) [#2]
thanks for any help!


GfK(Posted 2012) [#3]
Your problem seems to be that at no point are you destroying the bullet once it has hit something. The upshot of that, is that it's in contact with the player for several screen refreshes/collision checks and wiping out all the lives one after the other.

When you detect a collision, destroy the bullet right away.


DI(Posted 2012) [#4]
I tried change the bullet1s Y to -20 if it collided with Player2 and the same thing for bullet2 but it didn't work :(

Just so you know, I'm really new to blitzplus.


indietom(Posted 2012) [#5]
Is there not a remove or destory command?


Matty(Posted 2012) [#6]
Simply remove the bullet when it has collided and you've handled the collision.