So I am making a game and I need to figure out how to get my ball to bounce off the walls. My wall stops at 450 and I am in screen 9. Any help would be appreciated. I had bx = bx + 5 for the speed and had an if then statement.
if bx <=450 then
bx = bx - 5
and it stops the ball , but i can't quite figure out the code for the bounce.
Help with Bounce
One way to do it is to have a separate variable that will be used for incrementing the ball's position.
Essentially, you are using this second variable to help move the ball and also to control its direction...when you use the -balldirx what you're doing is reversing its sign, so if it was 5 it would become -5 and vice versa.
Make sense?
Code: Select all
DIM balldirx AS INTEGER
balldirx = 5
... code here ...
bx = bx + balldirx
IF bx> 449 OR bx < 1 THEN balldirx = -balldirx
Make sense?
Last edited by Nodtveidt on Fri Dec 14, 2007 11:10 pm, edited 1 time in total.
- coma8coma1
- Veteran
- Posts: 100
- Joined: Sat Dec 08, 2007 5:29 pm
- Location: Maryland, USA
- coma8coma1
- Veteran
- Posts: 100
- Joined: Sat Dec 08, 2007 5:29 pm
- Location: Maryland, USA