forums

TNT Basic Forums > Programming Q&A
Sprite Colisions?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-09-2004 22:21

Posted by:
venz

Find more posts by venz

I'm having a problem with sprite colision in my fighting game, when a player attacks their health goes down even if they are at opposite sides of the screen, here is the attack checking code.

'// Check Sucsesfull Attacks //
if Sprite Col (1,2) and gPlayer1punch > 0
beep
gPlayer2health = gPlayer2health - 10
gPlayer1punch = 0
end if
if Sprite Col(2,1) and gPlayer2punch > 0
beep
gPlayer1health = gPlayer1health -10
gPlayer2punch = 0
end if
'//*********//

01-09-2004 22:33

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Hm, seems like it should work to me. Maybe you're checking the wrong sprites.

01-09-2004 22:40

Posted by:
venz

Find more posts by venz

I only have 2 sprites, Sprite 1 for Player 1, and Sprite 2 for Player 2.

01-09-2004 22:44

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Maybe try this:

if not(Sprite Col (1,2)=-1) and gPlayer1punch > 0

01-09-2004 22:49

Posted by:
venz

Find more posts by venz

Well, now there are no collisions at all.... it could be time for some print debugging.

01-09-2004 22:56

Posted by:
venz

Find more posts by venz

I checked my code and the only colision checking is the code you just saw... so it has to be somthing with that.

01-10-2004 00:19

Posted by:
eric

Location:
earth

Click Here to Email eric   Find more posts by eric

collision

Sprite Col (1,2) is either true or false, so you need to be a bit more specific otherwise, the statement"if Sprite Col (1,2) and gPlayer1punch > 0" is the same as "if gPlayer1punch > 0", try this changes:



'// Check Sucsesfull Attacks //
if Sprite Col (1,2)=true and gPlayer1punch > 0
beep
gPlayer2health = gPlayer2health - 10
gPlayer1punch = 0
end if
if Sprite Col(2,1)=true and gPlayer2punch > 0
beep
gPlayer1health = gPlayer1health -10
gPlayer2punch = 0
end if
'//*********//

Good luck
eric

01-10-2004 04:15

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Actually, Eric, you can type
if x
and it will mean the same thing as
if x=true

In the same way, you can type
if sprite col(1,2)
and it will be
if sprite col(1,2)=true

So I don't think that's the problem. Sprite col returns the id of the sprite the test sprite is colliding with. So you would be looking to see that 2 is returned.

Venz, try
if sprite col(1,2)=2...
and
if sprite col(2,1)=1...

01-10-2004 15:45

Posted by:
venz

Find more posts by venz

Hm.... that worked, but why does sprite col return the ID that the first sprite colided with instead of just true or false...
Thanks a bunch!

01-10-2004 16:02

Posted by:
eric

Location:
earth

Click Here to Email eric   Find more posts by eric


True, eekaydee I did not realize that it returned the ID, not true or false. I usually use
"if sprite col(sprite1,sprite2)<>-1 then..."

The function returns the id of the sprite when you have a list of sprite to test.
"if sprite col(testSprite,fromSprite to sprite)=x then..."
where x is the sprite in collision.
since you are not testing a list of sprite guess what, it returns the sprite id anyway.
eric

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.