warlords
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
More compactly,
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement