Posted: Thu Dec 15, 2005 9:42 pm Post subject: bouncing ball
This code is driving me crazy cuz i can only give it the borders on the x axis, not y (even though my program looks like i tried to make a y border). can some1 plz tell me how to change it so the y border will actually work without changing everything? this is the code
code:
var x : int := 2
var y : int := 2
loop
if x <= 2 then
loop
exit when x >= 630 or y >= 390
delay (30)
cls
drawfilloval (x, y, 10, 10, 7)
x := x + 10
y := y + 2
end loop
end if
if x >= 630 then
loop
exit when x <= 2 or y <= 2 or y >= 630
delay (30)
cls
drawfilloval (x, y, 10, 10, 7)
x := x - 10
y := y - 2
end loop
end if
end loop
Mod edit: Code tags please, no triple posting, and no caps lock. Thanks.
Sponsor Sponsor
Bored
Posted: Thu Dec 15, 2005 9:47 pm Post subject: (No subject)
The problem with your program is really simple your changeing both the y and x directions when your ball hits the end of the x part of the screen. Try using a single loop and a variable to store xSpeed and ySpeed. When the ball hits its max or minimum x value have the xSpeed become - xSpeed therfore going the other way (bouncing). Do the same for your y