bouncing ball off of walls
Author |
Message |
iop
|
Posted: Wed May 19, 2004 7:08 pm Post subject: bouncing ball off of walls |
|
|
I have a ball that starts out in the middle of the screen, drops down. From there, I need the ball to start bouncing around the whole screen. My problem is that the screen isnt the average Turing screen. I have mine edited to cover the whole area of the computer screen of the computer that my program is running on. I would love some help on how I could make the ball bounce around the whole screen. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Wed May 19, 2004 7:19 pm Post subject: (No subject) |
|
|
http://www.compsci.ca/v2/viewtopic.php?t=75
Collision detection.
Also:
- you most likely will need to check for the ball's position. So...
code: |
var ballX, ballY : int := 0
%...some code drawing ball etc.
if ballX < maxx then
ballX += 1
else
ballX -= 1
end if
% This checks to see if the ball has reached the end of the screen...this
% is really not good code...don't use it...it's just demonstrating how things
% would be done.
|
|
|
|
|
|
|
PhOeNiX-47
|
Posted: Wed May 19, 2004 8:08 pm Post subject: (No subject) |
|
|
Well, first of all ur ball needs to go in a direction using a variable. Make sure the if u hit a wall make the direction change Let me show you.
code: |
View.Set ("offscreenonly")
var row_change := 1
var row := 200
loop
cls
row := row + row_change
drawfilloval (300, row, 25, 25, black)
if row = 25 then
row_change := row_change * -1
elsif row = maxy - 25 then
row_change := row_change * -1
end if
View.Update
delay (1)
end loop
|
Hope that helps you... |
|
|
|
|
|
|
|