Archived

This topic is now archived and is closed to further replies.

Flare

Collision detection using DelphiX

Recommended Posts

Hello! I''m working on a 2D hockey game in Delphi using the GDK DelphiX and I have a problem I can''t solve: I have made it possible for the player (there is only one at this stage) to pick upp the puck by skating over it, and that was pretty easy. Next step is to make the player shoot the puck by pressing a button, and here comes my problem: since I use the collision detection to tell if the player sprite has collided with the puck sprite in order to get the player to pick up the puck, I have a hard time getting him to let it go, because everytime the puck passes "through" the player sprite it sets off the collision procedure and makes the player pick up the puck again. If I, on the other hand, turn the collision detection off when I press the shot button then the player will shoot the puck, but since I have turned the collision detection off, he won''t be able to pick it up again, and I haven''t figured out how to activate it again. I hope someone understands what I''m after although the explanation is a little fuzzy! Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Hi...

You could try something ... But it''s near Brutal force ...

Declare a "t" integer value ...

Now , when the player presses the button to release the puck type this code :

t := 1000;
(for example)

then, at each timer refresh, decrease the t value of your timer interval ...(but always >= 0)

You''ll just have to do a test :

if t = 0 then [... Do collision test] ;

That''s all ...

I know that it''s not very ... cool ... But ... I haven''t found other way to do it (for the moment )

Bye
Avatar

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How about taking the bounding box for your player sprite and making the puck appear at the edge of it before it "shoots" away? I dunno, perhaps something like going circular: if your player sprite is 25x100, make the puck appear at the edges of an invisible circle with a radius of 50, centered at the center of your player sprite.

That way, there''s no brute force calculating, you just use a formula. Would involve some trig, but once you''ve got it set up, it should work without any maintenance, and you could easily "port" the forumla to objects of different sizes.

Share this post


Link to post
Share on other sites