pong game help
Author |
Message |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
Posted: Sun Feb 19, 2006 9:03 am Post subject: pong game help |
|
|
k, so i got the ball to travel in a path I directed it, but now i want it 2 bounce off the walls (imade somethin like that on turing, but it was a lot easier). so my code is: <form includes a timer and a ball>
code: | Private Sub Timer1_Timer()
Dim dx As Integer
Dim dy As Integer
Dim shape1Right As Integer
Dim shape1Down As Integer
shape1Right = Shape1.Left + Shape1.Width
shape1Down = Shape1.Top - Shape1.Height
dx = 5
dy = 5
If Shape1.Top >= 4800 Then
dx = -dx
End If
If shape1Down <= 0 Then
dx = -dx
End If
If shape1Right >= 7800 Then
dy = -dy
End If
If Shape1.Left <= 0 Then
dy = -dy
End If
Shape1.Top = Shape1.Top + dx
Shape1.Left = Shape1.Left + dy
End Sub |
thnx for any help:) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
pavol
|
Posted: Sun Feb 19, 2006 9:58 am Post subject: (No subject) |
|
|
just curious, why are you using .Top to test if the ball is >= 4800 and then make dx negative? shouldn't you be using shape1.Left or shape1Right if you want to change dx, and shape1.Left and shape1Down if you want to change dy. |
|
|
|
|
![](images/spacer.gif) |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
Posted: Tue Feb 21, 2006 9:15 pm Post subject: (No subject) |
|
|
i used that just cuz 4 some reason thats wat works... iduno, its weird... |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Wed Feb 22, 2006 6:41 pm Post subject: (No subject) |
|
|
try something like this it should work. put the following code in your timer
code: |
'sets the boundary for the maximum left the ball can go to
If ball1.Left <= Form.Left Then
leftDir = 100
End If
'sets the boundary for the maximum right the ball can go to
If ball1.Left + ball1.Width >= Form.Left + Form.Width Then
leftDir = -100
End If
'sets the boundary for the maximum height the ball can go to
If ball1.Top <= Form.Top Then
topDir = 100
End If
|
note i did not use the same variables as u so just change the variable names ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|