
-----------------------------------
do_pete
Wed Oct 05, 2005 11:44 am

bullet-time pong
-----------------------------------
This is my first ever turing game. This game may not work on some computers for some strange reason. It used to have background music and sound effects but I couldn't attach those so this is just the program.
Please Tell me about any bugs, suggestion, or comments that you have.
Feel free to edit the code but please give me some credit or else...

%                                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                  %%          PETER'S PONG v.1.12           %%
%                                  %%         Programed by Peter Do          %%
%                                  %%   Background Music by Aaron Liblong    %%
%                                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

const RADIUS : int := 10
const SLOWMAX : int := 500
const ACCELERATION : real := 0.2
const UP_ARROW : char := chr (200)
const LEFT_ARROW : char := chr (203)
const RIGHT_ARROW : char := chr (205)

%                                                GLOBAL VARIABLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var keys : array char of boolean
var right, left, Speed : int := 1
var RSpeed : real := 0.1
var a, b, c, d, m, s, x, y, cheats, cheats2, cheatsyes : int := 0
var rx, ry : real := 0.0
var BoxX1, BoxY1, BoxX2, BoxY2, WallPosition, Box2X1, Box2Y1, Box2X2, Box2Y2 : int := 200
var answer, answer2, answer3, answer4, Score, buttonnumber, buttonupdown : int := 0
var Score2, Score3 : string
var SlowMotion : int := 1000
var WallSpeed : int := 5
var RSlowMotion : real := 0
%                                                    FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Right (x : int) : int
    result x + Speed
end Right

function Left (x : int) : int
    result x - Speed
end Left

function Up (y : int) : int
    result y + Speed
end Up

function Down (y : int) : int
    result y - Speed
end Down

function RealRight (rx : real) : real
    result rx + 0.1
end RealRight

function RealLeft (rx : real) : real
    result rx - 0.1
end RealLeft

function RealUp (ry : real) : real
    result ry + 0.1
end RealUp

function RealDown (ry : real) : real
    result ry - 0.1
end RealDown

%                                                    PROCEDURES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure CentreFont (s : string, x, y, f, clr : int)
    var w : int := Font.Width (s, f)
    Font.Draw (s, x - w div 2, y, f, clr)
end CentreFont

procedure YouLose
    var answer, AX1, AX2, BX1, BX2, Y1, Y2 : int

    

    Score2 := intstr (Score)

    Score3 := "Your score is " + Score2

    for decreasing c : 31 .. 16
        CentreFont ("YOU LOSE!", maxx div 2, maxy div 2 + 25, Font.New ("Impact:70:bold"), c)
        CentreFont (Score3, maxx div 2, maxy div 2 - 22, Font.New ("Impact:30"), c)
        View.Update
        delay (50)
    end for
    cls
    CentreFont ("YOU LOSE!", maxx div 2, maxy div 2 + 25, Font.New ("Impact:70:bold"), black)
    CentreFont (Score3, maxx div 2, maxy div 2 - 22, Font.New ("Impact:30"), black)
    View.Update

    AX1 := 275
    AX2 := 315

    BX1 := 325
    BX2 := 365

    Y1 := 115
    Y2 := 135

    delay (1000)
    for decreasing c2 : 31 .. 16
        CentreFont ("Would you like to quit?", maxx div 2, maxy div 2 + -50, Font.New ("Impact:14"), c2)
        CentreFont ("Yes        No", maxx div 2, maxy div 2 - 80, Font.New ("Impact:14"), c2)
        Draw.Box (AX1, Y1, AX2, Y2, c2)
        Draw.Box (BX1, Y1, BX2, Y2, c2)
        View.Update
        delay (50)
    end for


    Draw.Box (AX1, Y1, AX2, Y2, black)
    Draw.Box (BX1, Y1, BX2, Y2, black)
    View.Update

    loop
        var x, y, b : int := 0
        mousewhere (x, y, b)

        if x > AX1 and x < AX2 and y > Y1 and y < Y2 then
            Draw.Box (AX1, Y1, AX2, Y2, brightred)
            View.Update
            if b = 1 then
                answer3 := 1
                exit
            end if
        elsif x > BX1 and x < BX2 and y > Y1 and y < Y2 then
            Draw.Box (BX1, Y1, BX2, Y2, brightred)
            View.Update
            if b = 1 then
                answer3 := 2
                exit
            end if
        else
            Draw.Box (AX1, Y1, AX2, Y2, black)
            Draw.Box (BX1, Y1, BX2, Y2, black)
            View.Update
        end if
    end loop

    for c : 31 .. 16
        CentreFont ("YOU LOSE!", maxx div 2, maxy div 2 + 25, Font.New ("Impact:70:bold"), c)
        CentreFont (Score3, maxx div 2, maxy div 2 - 22, Font.New ("Impact:30"), c)
        CentreFont ("Would you like to quit?", maxx div 2, maxy div 2 + -50, Font.New ("Impact:14"), c)
        CentreFont ("Yes        No", maxx div 2, maxy div 2 - 80, Font.New ("Impact:14"), c)

        Draw.Box (AX1, Y1, AX2, Y2, c)
        Draw.Box (BX1, Y1, BX2, Y2, c)

        View.Update
        delay (50)

    end for



    m := 0
end YouLose

procedure SureQuit

    var answer, AX1, AX2, BX1, BX2, Y1, Y2 : int
    AX1 := 275
    AX2 := 315

    BX1 := 325
    BX2 := 365

    Y1 := 195
    Y2 := 215

    cls

    CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), black)

    for decreasing c : 31 .. 16
        CentreFont ("Are you sure you want to quit?", maxx div 2, maxy div 2 + +30, Font.New ("Impact:14"), c)
        CentreFont ("Yes        No", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
        Draw.Box (AX1, Y1, AX2, Y2, c)
        Draw.Box (BX1, Y1, BX2, Y2, c)
        View.Update
        delay (50)
    end for

    CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), black)
    CentreFont ("Are you sure you want to quit?", maxx div 2, maxy div 2 + +30, Font.New ("Impact:14"), black)
    CentreFont ("Yes        No", maxx div 2, maxy div 2, Font.New ("Impact:14"), black)

    Draw.Box (AX1, Y1, AX2, Y2, black)
    Draw.Box (BX1, Y1, BX2, Y2, black)

    View.Update

    loop
        var x, y, b : int := 0
        mousewhere (x, y, b)

        if x > AX1 and x < AX2 and y > Y1 and y < Y2 then
            Draw.Box (AX1, Y1, AX2, Y2, brightred)
            View.Update
            if b = 1 then
                answer2 := 1
                exit
            end if
        elsif x > BX1 and x < BX2 and y > Y1 and y < Y2 then
            Draw.Box (BX1, Y1, BX2, Y2, brightred)
            View.Update
            if b = 1 then
                answer2 := 2
                exit
            end if
        else
            Draw.Box (AX1, Y1, AX2, Y2, black)
            Draw.Box (BX1, Y1, BX2, Y2, black)
            View.Update
        end if
    end loop
    if answer2 = 1 then
        for c : 16 .. 31
            CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), c)
            CentreFont ("Are you sure you want to quit?", maxx div 2, maxy div 2 + +30, Font.New ("Impact:14"), c)
            CentreFont ("Yes        No", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            Draw.Box (AX1, Y1, AX2, Y2, c)
            Draw.Box (BX1, Y1, BX2, Y2, c)
            View.Update
            delay (50)
        end for
    else
        for c : 16 .. 31
            CentreFont ("Are you sure you want to quit?", maxx div 2, maxy div 2 + +30, Font.New ("Impact:14"), c)
            CentreFont ("Yes        No", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            Draw.Box (AX1, Y1, AX2, Y2, c)
            Draw.Box (BX1, Y1, BX2, Y2, c)
            View.Update
            delay (50)
        end for
    end if
    m := 1
end SureQuit

procedure menu

    var X1, X2, AY1, AY2, BY1, BY2, CY1, CY2 : int
    X1 := 270
    X2 := 370

    AY1 := 225
    AY2 := 245

    BY1 := 195
    BY2 := 215

    CY1 := 185
    CY2 := 165

    cls

    if m = 0 then
        for decreasing c : 31 .. 16
            CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), c)
            CentreFont ("Play", maxx div 2, maxy div 2 + 30, Font.New ("Impact:14"), c)
            CentreFont ("Help", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            CentreFont ("Quit", maxx div 2, maxy div 2 - 30, Font.New ("Impact:14"), c)
            Draw.Box (X1, AY1, X2, AY2, c)
            Draw.Box (X1, BY1, X2, BY2, c)
            Draw.Box (X1, CY1, X2, CY2, c)
            View.Update
            delay (50)
        end for
    elsif m = 1 then
        CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), black)
        for decreasing c : 31 .. 16
            CentreFont ("Play", maxx div 2, maxy div 2 + 30, Font.New ("Impact:14"), c)
            CentreFont ("Help", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            CentreFont ("Quit", maxx div 2, maxy div 2 - 30, Font.New ("Impact:14"), c)
            Draw.Box (X1, AY1, X2, AY2, c)
            Draw.Box (X1, BY1, X2, BY2, c)
            Draw.Box (X1, CY1, X2, CY2, c)
            View.Update
            delay (50)
        end for

    end if

    CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), black)
    CentreFont ("Play", maxx div 2, maxy div 2 + 30, Font.New ("Impact:14"), black)
    CentreFont ("Help", maxx div 2, maxy div 2, Font.New ("Impact:14"), black)
    CentreFont ("Quit", maxx div 2, maxy div 2 - 30, Font.New ("Impact:14"), black)

    View.Update
    loop
        var x, y, button, middle : int := 0
        mousewhere (x, y, button)
        left := button mod 10             
        middle := (button - left) mod 100 
        right := button - middle - left   
        
        Input.KeyDown (keys)

        if keys (RIGHT_ARROW) and keys (LEFT_ARROW) and left = 1 then
            cheats := 1
        end if

        if x > X1 and x < X2 and y > AY1 and y < AY2 then
            Draw.Box (X1, AY1, X2, AY2, brightred)
            View.Update
            if button = 1 then
                answer := 1
                exit
            end if
        elsif x > X1 and x < X2 and y > BY1 and y < BY2 then
            Draw.Box (X1, BY1, X2, BY2, brightred)
            View.Update
            if button = 1 then
                answer := 2
                exit
            end if
        elsif x > X1 and x < X2 and y < CY1 and y > CY2 then
            Draw.Box (X1, CY1, X2, CY2, brightred)
            View.Update
            if button = 1 then
                answer := 3
                exit
            end if
        elsif x >= 0 and x  X1 and x < X2 and y > AY1 and y < AY2 then
            Draw.Box (X1, AY1, X2, AY2, brightred)
            View.Update
            if b = 1 then
                answer4 := 1
                exit
            end if
        elsif x > X1 and x < X2 and y > BY1 and y < BY2 then
            Draw.Box (X1, BY1, X2, BY2, brightred)
            View.Update
            if b = 1 then
                answer4 := 2
                exit
            end if
        elsif x > X1 and x < X2 and y < CY1 and y > CY2 then
            Draw.Box (X1, CY1, X2, CY2, brightred)
            View.Update
            if b = 1 then
                answer4 := 3
                exit
            end if
        elsif x > X1 and x < X2 and y < DY1 and y > DY2 then
            Draw.Box (X1, DY1, X2, DY2, brightred)
            View.Update
            if b = 1 then
                answer4 := 4
                exit
            end if

        else
            Draw.Box (X1, AY1, X2, AY2, black)
            Draw.Box (X1, BY1, X2, BY2, black)
            Draw.Box (X1, CY1, X2, CY2, black)
            Draw.Box (X1, DY1, X2, DY2, black)
            View.Update
        end if
    end loop

    if answer4 = 1 or answer4 = 2 or answer4 = 3 then
        for c : 16 .. 31
            CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), c)
            CentreFont ("Continue", maxx div 2, maxy div 2 + 30, Font.New ("Impact:14"), c)
            CentreFont ("Restart", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            CentreFont ("Help", maxx div 2, maxy div 2 - 30, Font.New ("Impact:14"), c)
            CentreFont ("Quit", maxx div 2, maxy div 2 - 60, Font.New ("Impact:14"), c)
            Draw.Box (X1, AY1, X2, AY2, c)
            Draw.Box (X1, BY1, X2, BY2, c)
            Draw.Box (X1, CY1, X2, CY2, c)
            Draw.Box (X1, DY1, X2, DY2, c)
            View.Update
            delay (50)
        end for
        return
    else
        CentreFont ("Peter's Pong", maxx div 2, maxy div 2 + 70, Font.New ("Impact:20:bold,underline"), black)
        for c : 16 .. 31
            CentreFont ("Continue", maxx div 2, maxy div 2 + 30, Font.New ("Impact:14"), c)
            CentreFont ("Restart", maxx div 2, maxy div 2, Font.New ("Impact:14"), c)
            CentreFont ("Help", maxx div 2, maxy div 2 - 30, Font.New ("Impact:14"), c)
            CentreFont ("Quit", maxx div 2, maxy div 2 - 60, Font.New ("Impact:14"), c)
            Draw.Box (X1, AY1, X2, AY2, c)
            Draw.Box (X1, BY1, X2, BY2, c)
            Draw.Box (X1, CY1, X2, CY2, c)
            Draw.Box (X1, DY1, X2, DY2, c)
            View.Update
            delay (50)
        end for
    end if
    cls
    m := 0

end GameMenu

procedure Help
    var X1, X2, AY1, AY2 : int
    X1 := 270
    X2 := 370

    AY1 := 75
    AY2 := 96

    cls
    for decreasing c : 31 .. 16
        CentreFont ("Peter's Pong Help", maxx div 2, maxy div 2 + 110, Font.New ("Impact:16:bold,underline"), c)
        CentreFont ("Control the two paddles with the mouse.", maxx div 2, maxy div 2 + 90, Font.New ("Impact:12"), c)
        CentreFont ("Try to stop the ball from passing your", maxx div 2, maxy div 2 + 70, Font.New ("Impact:12"), c)
        CentreFont ("paddles. The more you hit the ball with", maxx div 2, maxy div 2 + 50, Font.New ("Impact:12"), c)
        CentreFont ("the paddle the more it speeds up. Your", maxx div 2, maxy div 2 + 30, Font.New ("Impact:12"), c)
        CentreFont ("score is the amount of times you hit", maxx div 2, maxy div 2 + 10, Font.New ("Impact:12"), c)
        CentreFont ("the ball. Pressing the left mouse button", maxx div 2, maxy div 2 - 10, Font.New ("Impact:12"), c)
        CentreFont ("makes you go into slow-motion. The green", maxx div 2, maxy div 2 - 30, Font.New ("Impact:12"), c)
        CentreFont ("bar on the right is the amount of time", maxx div 2, maxy div 2 - 50, Font.New ("Impact:12"), c)
        CentreFont ("that you can go into slow-motion. Right", maxx div 2, maxy div 2 - 70, Font.New ("Impact:12"), c)
        CentreFont ("clicking brings up the in-game menu", maxx div 2, maxy div 2 - 90, Font.New ("Impact:12"), c)
        CentreFont ("Return", maxx div 2, maxy div 2 - 120, Font.New ("Impact:14"), c)
        Draw.Box (X1, AY1, X2, AY2, c)
        delay (50)
        View.Update
    end for

    Draw.Box (X1, AY1, X2, AY2, black)

    View.Update

    loop
        var x, y, b : int := 0
        mousewhere (x, y, b)
        if x > X1 and x < X2 then
            if y > AY1 and y < AY2 then
                Draw.Box (X1, AY1, X2, AY2, brightred)
                View.Update
                if b = 1 then
                    answer := 1
                    exit
                end if
            else
                Draw.Box (X1, AY1, X2, AY2, black)
                View.Update
            end if
        end if
    end loop
    for c : 16 .. 31
        CentreFont ("Peter's Pong Help", maxx div 2, maxy div 2 + 110, Font.New ("Impact:16:bold,underline"), c)
        CentreFont ("Control the two paddles with the mouse.", maxx div 2, maxy div 2 + 90, Font.New ("Impact:12"), c)
        CentreFont ("Try to stop the ball from passing your", maxx div 2, maxy div 2 + 70, Font.New ("Impact:12"), c)
        CentreFont ("paddles. The more you hit the ball with", maxx div 2, maxy div 2 + 50, Font.New ("Impact:12"), c)
        CentreFont ("the paddle the more it speeds up. Your", maxx div 2, maxy div 2 + 30, Font.New ("Impact:12"), c)
        CentreFont ("score is the amount of times you hit", maxx div 2, maxy div 2 + 10, Font.New ("Impact:12"), c)
        CentreFont ("the ball. Pressing the left mouse button", maxx div 2, maxy div 2 - 10, Font.New ("Impact:12"), c)
        CentreFont ("makes you go into slow-motion. The green", maxx div 2, maxy div 2 - 30, Font.New ("Impact:12"), c)
        CentreFont ("bar on the right is the amount of time", maxx div 2, maxy div 2 - 50, Font.New ("Impact:12"), c)
        CentreFont ("that you can go into slow-motion. Right", maxx div 2, maxy div 2 - 70, Font.New ("Impact:12"), c)
        CentreFont ("clicking brings up the in-game menu", maxx div 2, maxy div 2 - 90, Font.New ("Impact:12"), c)
        CentreFont ("Return", maxx div 2, maxy div 2 - 120, Font.New ("Impact:14"), c)
        Draw.Box (X1, AY1, X2, AY2, c)
        View.Update
        delay (50)
    end for
    m := 0
end Help

procedure Credits
    for decreasing c : 31 .. 16
        CentreFont ("Programmed by Peter Do", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), c)
        View.Update
        delay (50)
    end for

    CentreFont ("Programmed by Peter Do", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), black)
    delay (200)

    for c : 16 .. 31
        CentreFont ("Programmed by Peter Do", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), c)
        View.Update
        delay (50)
    end for

    cls

    for decreasing c : 31 .. 16
        CentreFont ("Music by Aaron Liblong", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), c)
        View.Update
        delay (50)
    end for

    CentreFont ("Music by Aaron Liblong", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), black)
    delay (200)

    for c : 16 .. 31
        CentreFont ("Music by Aaron Liblong", maxx div 2, maxy div 2, Font.New ("Impact:20:bold"), c)
        View.Update
        delay (50)
    end for

    cls

    for decreasing c : 31 .. 16
        CentreFont ("Peter's Pong", maxx div 2, maxy div 2, Font.New ("Impact:70:bold"), c)
        View.Update
        delay (50)
    end for

    CentreFont ("Peter's Pong", maxx div 2, maxy div 2, Font.New ("Impact:70:bold"), black)
    delay (200)

    for c : 16 .. 31
        CentreFont ("Peter's Pong", maxx div 2, maxy div 2, Font.New ("Impact:70:bold"), c)
        View.Update
        delay (50)
    end for

    cls
end Credits

procedure Restart
    %These randint statements randomize the direction(a and b) and the location (x and y)
    randint (x, 220, 420)
    randint (y, 1, 200)
    randint (a, 0, 1)
    randint (b, 0, 1)

    rx := x
    ry := y
    c := 1
    s := 0
    Speed := 1
    RSpeed := 1
    SlowMotion := SLOWMAX
    RSlowMotion := SLOWMAX
end Restart


procedure CheckHit1
    if y >= 400 - RADIUS then
        b := 0
        c := (c + 1) mod 15
    elsif y = maxy - 50 then
        WallPosition := maxy - 50
    end if
    if WallPosition 