Jump to content
  • Advertisement

Archived

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

amreshr

DXBall questions (newbie questions)

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

Hi, I am a newbie to OpenGL, SDL, OpenAL and game programming in general, so please excuse. I am trying to make a small clone of DXBall/Breakout and have some questions that have cropped while trying to design the game. When the game starts, the mouse cursor disappears (not full screeb mode, but the paddle is controlled by the mouse. Is it because he has restricted the mouse movement along the x-axis, or hidden the cursor, but associated a rectangle with the cursor? If the mouse movement is restricted, then is it possible to do it is SDL? If the mouse is hidden, the mousedown event is not generated when I move the mouse to the extreme end (away from the main app window). How does he restrict the mouse movement to the game. How is angle of incedence of the ball to the paddle calculated atan((y2-y1)/(x2-x1)) or is he using the normals that are present for the surfaces? If so, how? The last one: How does he calculate the collision of the ball and the bricks? Is a matrix kept? or are the locations of each brick kept somewhere and collision detected for each movement (I think that this is very slow!). I can''t seem to figure this out! TIA Amresh ramresh@dsqsoft.com

Share this post


Link to post
Share on other sites
Advertisement
quote:

The last one: How does he calculate the collision of the ball and the bricks? Is a matrix kept? or are the locations of each brick kept somewhere and collision detected for each movement (I think that this is very slow!).



you can define a few areas... in this areas you put the bricks.. than you check in which area the ball is.. and than you just check for collisions...

i think it´s a bit faster

Share this post


Link to post
Share on other sites
Well, as far as collision detection goes, I''d bet he checks the ball against every brick every frame. Given a max of about 300 bricks and one ball, that''s only 300 detections a frame (1200 if he checks each wall of each brick) which is no problem for computers, really. I mean, one MHz is a million calculations per second, and 1200 times maybe a max of 300 frames per second (which there is no need for it to run at) is only about 350,000 tests. Granted each test takes several CPU operations.. but most computer nowadays run faster than 1 MHz.

As far as the mouse goes, there are a couple of differnet methods. I don''t remember the specifics of DXBall but any of the approaches you suggested would be valid solutions. Have you looked through the code at all?

/riley

Share this post


Link to post
Share on other sites
I don''t have the original code. I actually want to do this on my own and not port it, so I haven''t searched for the code. Hmm...should I search for the code
Thanks for the inputs on collision detection.


Amresh
ramresh@dsqsoft.com

Share this post


Link to post
Share on other sites
I made a Breakout type game a while ago, and this is what I did:

For the mouse input, the mouse can move anywhere, but the paddle that is controlled by the mouse only moves in the x-direction of the mouse. In other words, you don't restrict the mouse movement, you restrict the paddle movement.

Well, to calculate what angle the ball would move off after it hit a wall, paddle, or brick all I did was invert the x-coord and y-coord directions of the ball. It's not the most accurate representation of how a ball would move off of a paddle (especially if the ball is rotating or the paddle is not horizontally positioned), but it works.

For the collisions I had a variable that held the y-coord of the lowest brick, and if the ball was not above that line then it would not do any collision detection (except for hitting the walls and paddle). I did a similar thing for the paddle, if the y-coord of the ball was not near the bat then I didn't check a collision for the bat. Also, if the mouse's x-coord was past the walls of the playing field then I would not move the bat.

Checking the bricks I just had an array of boolean values and if a value was false I wouldn't display the brick and not do any collision detection on it. If it was then I would check the sides of each block.

I used a class for bricks, bats, balls, power-ups, and those little bullets that shoot of the paddle when that one power-up is collected. This simplifies things a lot, and allows to make different levels easier (I loaded the levels from a text file).

There are a lot of other things I did, it was my second real game after pong. I made it about a year and a half ago, but I think it was pretty neat, and a good educational thing as well. I did it in Java (an applet), but the same concepts apply to OpenGL etc. It will give you an idea, look at how the bat only moves with the x-coord of the mouse, that should help you.

You can play it here.

Good luck!

EDIT: The only thing I found that slowed it down was when I made it so the multi-ball thing doesn't stop making new balls at three, and I made it so that I would get like 500,000 muliti-ball powerups (making a million balls), and I had a LOT of those balls on the screen; that slowed things down considerably.

EDIT: Acutally kind of important, when I said I invert the x and y-coords I only inverted them both when I hit walls, the knob on the paddle, or the sides of the bricks. For ever other collision I only inverted the y-coord. I only inverted the y-coord when I hit the top wall.

EDIT: Doh, when I say I inverted the y-coords and x-coords I really meant I inverted the direction they traveled (the amount I increment the objects per frame)

Edited by - Floppy on November 25, 2001 12:24:02 AM
Edited by - Floppy on November 25, 2001 12:38:15 AM
Edited by - Floppy on November 25, 2001 12:42:36 AM

Edited by - Floppy on November 25, 2001 12:43:18 AM

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!