warlords

Started by
2 comments, last by Driv3MeFar 17 years, 11 months ago
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
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.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
I need an algorithm for when the ball hits a castle wall
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.

This topic is closed to new replies.

Advertisement