Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

warlords

This topic is 4465 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

I am programming an warlords clone using openGL and c++.I have drawn the ball and the paddles and the castles,I need an algorithm for collision detection of when the ball hits the castle walls, and the paddles, I am trying to avoid alot of complex math and physics,here is my collision detection so far: //check for collision detection if (x+20.0 > i && x < i+80.0f && y < 40.0f) { ystep=-ystep; } if (x+20.0 > i && x < i+80.0f && y > 580.0f) { ystep=-ystep; } this checks to see if the ball hits the paddle

Share this post


Link to post
Share on other sites
Advertisement
More compactly,

if (x + 20.0f > i && x < i + 80.0f)
if (y < 40.0f or y > 580.0f)
ystep -= ystep;


What is your specific question? You'll need to provide a little more information about your design for a better response.

OT, it's typically a good idea to use consts instead of literal values. Doing so will make your code much more flexible if the dimensions of your screen, castle, or paddle changes in the future.

Share this post


Link to post
Share on other sites
you posted this same question a few days earlier (http://www.gamedev.net/community/forums/topic.asp?topic_id=389421), there's really no need to double-post.

I'm not too familiar with the game, but as I mentioned in the earlier thread there's a pretty simply way to test for collision between a circle and a wall:

|
| (C)
|
|
|
o-->N
P

Given a circle with center C, radius R, and a wall originating at point P with a (normalized) outward (I said inward last time, which was a mistake, sorry) normal N:

vector v = C - P;
projection of v onto n = (v dotproduct N) * N;
if (magnitude(projection) <= R)
//collision occured

Hope it helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!