Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Breakout game-need help

Author
Message
Gloinchin 11
22
Years of Service
User Offline
Joined: 15th Mar 2004
Location:
Posted: 12th Jun 2004 05:08
I've started a breakout game and have all the objects set and have the ball moving up and down. But the problem is that the ball moves up and down anyway even when the paddle is not there. I would like to know what code or command could help me so that the ball only bounces when it hits the paddle? Any help will be appreciated and i've put my code here so look at it.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jun 2004 16:35
The change to get the ball to bounce only when the paddle was in the way was quite small - in fact you had the check for the paddle position in the wrong place. You needed to check the paddle position when the ball reaches the bottom of the screen, ie when Z reaches -14.

I've also made a few changes to fix your syncing problems. You should use SYNC ON to activate mamual control and SYNC to actually update the display.



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Gloinchin 11
22
Years of Service
User Offline
Joined: 15th Mar 2004
Location:
Posted: 12th Jun 2004 18:17
hey you were rite. It worked and I changed it to make the space between the ball and the paddle bigger. Thx a lot. You're really good at this stuff. But one other problem is that I don't know how to angle to ball properly so that if it hits the egdes or at an angle it will change into another direction. Here's my code:
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jun 2004 15:49
You just need to know the angle of reflection and subtract your current angle from that.

For example, the angle of reflection for the paddle is 0 (zero) degrees (ie, straight up).

If the ball is coming in at an angle of 45 degrees, then subtracting that from 0 gives you a new angle of 315 degrees when adjsuted back into the 0-360 range:

NewAngle# = wrapvalue( ReflectionAngle# - CurrentAngle# )


The left wall has a reflection angle of 90 degrees, the right is 270 degrees, the top wall is 180 degrees. The blocks have the same range of values depending on whichever side you bounce from.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2026-06-09 15:43:30
Your offset time is: 2026-06-09 15:43:30