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.

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Oct 2007 17:32
I'm making a breakout game because I decided it's about time I made a complete game (besides pong!).
I'm not getting very far
I have a bat and ball and it works ok but if the ball is hit into the corners it gets "stuck" behind the screen boundaries; how do I solve this?
I don't know how I'm going to store the positions of all the bricks for each level.

I've set up a little collision effect thing for reflecting the ball's angle so that should work ok with the bricks too.
When the ball hits the bat I want the angle reflection to alter depending on where on the bat the ball hits, I can't work this out


Thanks in advance

"You must be someone's friend to make comments about them." - MySpace lied.
Phjon
19
Years of Service
User Offline
Joined: 28th Nov 2005
Location:
Posted: 30th Oct 2007 18:11
This is the first time I've attempted to assist anyone with their programming work.

For storing the positions of the bricks for each level, you could do the following:

1. Calculate how many bricks will fit into your playing area horizontally and vertically.

2. Use a text file to store the relative positions of the bricks. For example, if your playing area was 40 units by 40 units you would input into your text file 40 rows of 40 numbers. Zero would indicate that the position is empty and a number from 1 to 8 in your case would indicate that a brick was present of the indicated colour.

3. To read the file, you use the file commands and two nested for...next loops, and store the data in an array, in this case:



If you need something more detailed than the above, please ask, as this is just a general guide to solving this particular problem.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 31st Oct 2007 03:46
I created a level editor - it's much quicker in the long-run...

TDK_Man

Comrade Robski
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 31st Oct 2007 13:57 Edited at: 31st Oct 2007 15:42
Hey OBese

I entered a 3d pong game to the DBC challenge a while back:

http://forum.thegamecreators.com/?m=forum_view&b=10&t=97545&p=4

...which changes the angle of the ball depending on where you hit it. Surprisingly for me the code is actually quite readable, so I'll post the relevent subroutine here (but be sure to check out the full game to see how it works ) :

(EDIT: I see that you're using a vector to control the ball movement. In my example I've used separate x,y and z momentums to move the ball - IMHO this makes it easier to do things like bounce the ball off a wall (you simply reverse the appropriate momentum). Doing the same thing with vectors kinda made my brain hurt which is why I did it this way. Anyway, have a look at my example and see it you can take anything from it)



Object 1 is the ball
Objects 3 and 4 are the player and computer bats
momx#, momy# and momz# are the x,y,z momentum

The key lines are:

To have the ball bounce at an angle depending upon where on the bat it is hit:

momx#=momx#+((object position x(ball)-object position x(bat))/deflect#)


deflect# is a constant used to adjust the amount of deflection caused by the bat

To have the ball bounce off a wall:

if object position x(ball)<-100
position object ball,-100-(object position x(ball)+100),object position y(ball),object position z(ball)
momx#=0-momx#
endif


-100 is the x position of the wall, so for example if the ball finds itself at x=-105 then it is repositioned back to x=-95, and its x momentum reversed.

If the ball is at x=-120 then it is repositioned back at x=-80, and so on.

This gives a pretty realistic 'bouncing' effect, and the ball should never get stuck.

Hope that helps!

Login to post a reply

Server time is: 2025-05-31 20:54:27
Your offset time is: 2025-05-31 20:54:27