Sign in to follow this  

warlords

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

This topic is 4248 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this