Jump to content
  • Advertisement


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


Collision detection using DelphiX

This topic is 5923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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 )


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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!