Archived

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

ServantOfGlaaki

Can someone help a newbie with some Breakout-style probs?

Recommended Posts

Hi there, I''m fairly experienced in Java programming, but have only just started programming games. My first project is a clone of Breakout (like Pong). My question is: How can I implement realistic physics. By this, I mean what do I have to do to get the ball to rebound off the bat at the correct angle? I understand what Maths must be done to work it out, but don''t know how to actually do it. Any help greatly appreciated. It''''s over for now... until yesterday begins again... tomorrow... tomorrow... tomorrow... [Powerman 5000 - Watch the Sky for Me]

Share this post


Link to post
Share on other sites
ZealousElixir    256
If you know the math, there is no issue with figuring out how it works.


if(Ball.x > MAX_X || Ball.x < MIN_X)
Ball.x =- Ball.x;

if (Ball.y < MIN_Y)
Ball. =- Ball.y;

//check ball->block collisions blah...
...

// check ball -> bottom edge collision
if (Ball.y > MAX_Y)
if (Ball.x < Paddle.x + PADDLE_WIDTH && Ball.x > Paddle.x)
//reflect ball off paddle
...
else
//ball is off the bottom of the screen
//restart or whatever
...


I don't know if that's what you want, but that's as good as I can do from what you asked.

Later,
ZE.

EDITED for formatting and code issues.

Edited by - ZealousElixir on December 18, 2001 5:39:08 PM

Share this post


Link to post
Share on other sites
Jonathon    122
Hey, ServantOfGlaaki, welcome to Gamedev!

I just wanted to say that if you are programming your game in Java, you might do well to post your question in the Java Development forum. That''s where I generally post my Java programming questions, and everyone has been very helpful. The Beginner forum is a great place to start. But keep in mind that while not everyone who visits this forum is familiar with Java, you''re bound to find many people in the Java Development forum who have cut their teeth on projects like that which you are currently working on.


Jonathon
quote:
"Mathematics are one of the fundamentaries of educationalizing our youths." -George W. Bush

"When a nation is filled with strife, then do patriots flourish." - Lao Tzu


Share this post


Link to post
Share on other sites