orufet
07-20-2001, 12:36 AM
I'm making a simple game of pong, and I've run into a problem. When the ball bounces off of a paddle, it just goes back in the direction that it came from. How do I make the angle of the ball change when it hits the paddle?
Jacob Sheehy
http://www.sheehy.ca
Multitasking - screwing up several things at once
BillSoo
07-20-2001, 12:49 AM
Assuming that the paddles are vertical and the ball bounces left and right, you would keep the delta Y component of the velocity the same but make the deltaX component negative.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
orufet
07-20-2001, 12:55 AM
You assume correctly, but what do you mean by DeltaY and DeltaX?
Jacob Sheehy
http://www.sheehy.ca
Multitasking - screwing up several things at once
BillSoo
07-20-2001, 02:09 AM
If X and Y are positions, then the change in x and y is the velocity of x and y. In math terms, a change is referred to as Delta because that's the greek symbol that represents change.
So anyway, you probably have some routine like:
x = x + 5
y = y + 1
where 5 and 1 are the x velocity and y velocity respectively.
When you hit the paddle, you reverse the X component but leave the y alone so you would have
x = x -5
y = y + 1
In your actual code, you probably have these values stored in variables like:
x = x + dX
y = y + dY
so you can add/subtract a random component.
I seem to recall posting a breakout game to the games forum last year....that would show you how to use the paddles...
<a href="http://www.visualbasicforum.com/bbs/showthreaded.php?Cat=&Board=gp&Number=9818&page=&view=&sb=&o=">Found it HERE</a>
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder<P ID="edit"><FONT class="small"><EM>Edited by BillSoo on 07/20/01 03:15 AM.</EM></FONT></P>
andrewo
07-20-2001, 03:19 AM
I ran into that problem to
I havent tested this yet but it is what I am going to do....
for my moving up and down I have a value that is constantly added to the ball.top
so when ball hits top paddle the value = 1
so when ball hits bottom paddle the value = -1
so you could use this idea into making it + values on the position it hits the bat
like
this could scale the form.left to the same as the bat but in the middle of the bat and switch each time the ball hits it
a different bat
so you get the values coming from the bat so when the ball hits the bat determine where it hits hmm...now i have confused my self...excuse mee
~
orufet
07-20-2001, 02:14 PM
Thanks for the help, guys! I'm getting it now.....
Is there an easy way of making the ball follow the rule of light hitting a mirror? (The angle of incidence equals the angle of reflection). This would be a good way for the ball to act, but if not, then I have what I need!
Thanks again!
Jacob Sheehy
http://www.sheehy.ca
Multitasking - screwing up several things at once
andrewo
07-21-2001, 09:50 AM
I've half solved the problem...
heres some of my code that i am using
'Defining the Angle that the ball moves on
BallAngle = Ball.Left '+ Ball.Width / 2
Player1Angle = Player1.Left + Player1.Width / 2
Player2Angle = Player2.Left + Player2.Width / 2
'Which direction for the ball to move in
If Ball.Top = Player1.Top + Player1.Height And Player1Align = 1 Then
XSpeed.Caption = BallAngle - Player1Angle
End If
If Ball.Top = Player2.Top - Ball.Height And Player2Align = 1 Then
XSpeed.Caption = BallAngle - Player2Angle
End If
'Move the ball
Ball.Left = Ball.Left + XSpeed.Caption
Sleep 10 ' Actual speed of ball
Loop
~