Computer Science Canada

pong help

Author:  LindenRulz [ Fri Feb 23, 2007 9:07 pm ]
Post subject:  pong help

I need help to detect if it hits the paddle or not and reflect if it does and quit if it doesn't. This is my code.

code:

var ballx, bally, rise, run, rad, u, yy, xx : int
ballx := maxx div 2
bally := maxy div 2
rad := 10
rise := 1
run := 3
View.Set ("offscreenonly")
loop
    var x, y, button : int
    Mouse.Where (x, y, button)
    Draw.FillOval (ballx, bally, rad, rad, blue)
    ballx := ballx + run
    bally := bally + rise
    if ballx > maxx or ballx < 0 then
        run := run * -1
    end if
    if bally > maxy or bally < 0 then
        rise := rise * -1
    end if
    View.Update
    delay (10)
    cls
    drawfillbox (x - 50, 0, x + 50, 10, red)
if bally = 10 and ballx < x - 51 and ballx > x + 51 then
exit
end if
    end loop
[/code]

Author:  rollerdude [ Sat Feb 24, 2007 5:56 pm ]
Post subject:  Re: pong help

well, i haven't run it yet, but by looking at it, i see this line

ballx < x - 51 and ballx > x + 51

if x=0 then ballx would have to be >51 and <-51

other than that, i seems allright

maybe you meant

ballx > x - 51 and ballx < x + 51

??

hope i could help

Author:  CodeMonkey2000 [ Sat Feb 24, 2007 8:12 pm ]
Post subject:  RE:pong help

You need to figure out the shortest distance between the mid-point of the ball and the top line of your paddle. If the distance is equal to or less than the radius of the ball then it has collided with your paddle and must now change direction, or else keep going.


: