
-----------------------------------
ashvinthecha
Thu Jun 04, 2009 4:38 pm

PONG HELP -  Need help bouncing ball off paddle?
-----------------------------------
I dont know how to say if ballx hits the paddle then the dirRight causes the ball to bounce the other way


setscreen ("offscreenonly")
var x : int
var y : int
var p1 : string
var p2 : string
var ashvin := 100
var ashvin2 := 180
var ashvin3 := 100
var ashvin4 := 180
var ballx := maxx div 2
var bally := maxy div 2
var background := white
var getKey : array char of boolean

procedure Screen
    drawfillbox (0, 0, maxx, maxy, background)
    drawfillbox (20, ashvin, 30, ashvin2, black)
    drawfillbox (maxx - 20, ashvin3, maxx - 30, ashvin4, black)
end Screen

procedure MoveP1Up
    drawfillbox (20, ashvin2, 30, ashvin, background)
    ashvin += 2
    ashvin2 += 2
    drawfillbox (20, ashvin2, 30, ashvin, black)
    delay (3)
end MoveP1Up
procedure MoveP1Down
    drawfillbox (20, ashvin2, 30, ashvin, background)
    ashvin -= 2
    ashvin2 -= 2
    drawfillbox (20, ashvin2, 30, ashvin, black)
    delay (3)
end MoveP1Down
procedure MoveP2Up
    drawfillbox (maxx - 20, ashvin3, maxx - 30, ashvin4, background)
    ashvin3 += 2
    ashvin4 += 2
    drawfillbox (maxx - 20, ashvin3, maxx - 30, ashvin4, black)
    delay (3)
end MoveP2Up
procedure MoveP2Down
    drawfillbox (maxx - 20, ashvin3, maxx - 30, ashvin4, background)
    ashvin3 -= 2
    ashvin4 -= 2
    drawfillbox (maxx - 20, ashvin3, maxx - 30, ashvin4, black)
    delay (3)
end MoveP2Down
process balldir
    var dirUp : boolean := true
    var dirRight : boolean := true
    loop
        cls
        if dirUp then
            if bally >= 10 then
                bally := bally - 5
            else
                dirUp := false
            end if
        else
            if bally = 10 then
                ballx := ballx - 5
            else
                dirRight := false
            end if
        else
            if ballx 