Computer Science Canada

pls help me wit my program

Author:  shoobyman [ Wed Jan 11, 2006 9:08 am ]
Post subject:  pls help me wit my program

ok this is my program, i need help to make the ball bounce off of the paddle :

var x, y, button : int
var paddleHEIGHT: int:=5
var objectVX, objectVY, x2, y2 : int
objectVY := 10
objectVX := 10
x2 := maxx div 2
y2 := maxy div 2
const ballRad : int := 5
setscreen ("offscreenonly")
loop
delay (30)
cls
mousewhere (x, y, button)

drawfillbox (x,13,x+60,paddleHEIGHT,black)

drawfilloval (x2, y2, ballRad, ballRad, black)
x2 += objectVX
y2 += objectVY
if x2 > maxx - 5 then
objectVX := -objectVX
elsif x2 < 5 then
objectVX := -objectVX
elsif y2 > maxy - 5 then
objectVY := -objectVY
elsif y2 < 5 then
objectVY := -objectVY
end if
View.Update
end loop

Author:  codemage [ Wed Jan 11, 2006 10:35 am ]
Post subject: 

Do a search for pong. There have been many, many posts about this already - where you can find your answer.

Author:  do_pete [ Wed Jan 11, 2006 10:38 am ]
Post subject: 

Whenever the ball hits a paddle go
code:
Ball_X_Speed *= -1

Author:  pavol [ Wed Jan 11, 2006 10:50 am ]
Post subject: 

use an if statement to check where the ball is. ex:
code:
if x2 > x and x2 < x + 60 and y2 <  13 then
    y2 := -y2
end if


: