
-----------------------------------
Garv
Thu Dec 03, 2009 11:09 am

Grade 12 Box Pong Game
-----------------------------------
It's my first version.
I'm open to criticism and corrections, give me your input!

%This is my first attempt at writing a game.
%Cody
%November 10, 2009
%Version 1.0
%This is a game for one, my goal is to convert to a game for two.
%********************************************

%This is where I will declare any global variables.
var fname : string := "Guest"
var answer : string (1)
var timescore:int :=0
var movepaddlex : int := 175
var movepaddley : int := 175
var hitfont := Font.New ("comicsans:14:bold") %this is the (font type:size:additions)
var titlefont := Font.New ("consolas:12:bold")
var instfont := Font.New ("couriernew:10:bold")
var welcfont := Font.New ("consolas:14:bold")
var getkey : array char of boolean
var x : int := 70 %this is the x variable where the ball is served from at the beginning of the game.
var y : int := 175 %this is the y variable where the ball is served from at the beginning of the game.
var score : int := 0 %this is hit counter to track hits
var dx, dy : int := 1
var overfont:=Font.New ("consolas:60:bold")
%********************************************

%This is where I will put my procedures.
%The first tast I have to do is draw the court.
% 640 x 400, with 0,0 at the bottom left hand corner.
%********************************************
%commands image off screen and then writes it to the screen when we use View.Update
View.Set ("nooffscreenonly")
%********************************************

%*******************************************
%this process will draw the ball and move it around the screen.
%A process declaration is much like a procedure declaration.
%but is activated by a fork statement, rather than a call.
%the fork statement starts a concurrent (parallel) execution of the process while the statements following the
%fork continue to execute.

procedure gameover
cls
Draw.Text("TRY AGAIN",120,150,overfont,cyan)
end gameover

%for paddle sound
process soundpaddle
    Music.Sound (400, 70)
    Music.SoundOff
end soundpaddle



process soundwall
    Music.Sound (50, 50)
    Music.SoundOff
end soundwall

process soundout
    Music.Sound (2000, 500)
    Music.SoundOff
end soundout

process moveball
    randint (y, 20, 280)
    randint (x, 50, 500)
    locatexy (x, y)
    drawfilloval (x, y, 5, 5, magenta)

    
       loop 
    delay (3)
        %controls ball bouncing off the top wall.
       
        if y = 335 then
            dy := -dy
            locate (2, 75)
                
        elsif x = 595 then
            dx := -dx
            locate (2, 75)
            score:=score+1
            put score
            
            if score=3 then
            delay(1)
            dx:=dx+1
            dy:=dy+1
            end if
            
            
                
                
            elsif x = movepaddlex-2 and y = movepaddley-2 then
                delay (500)
         Draw.Text("GAME OVER",120,150,overfont,red)
         delay(1000)
         cls
         
         
         


            end if

            drawfilloval (x, y, 5, 5, black)
            x := x + dx
            y := y + dy
            drawfilloval (x, y, 5, 5, magenta)

        end loop
    end moveball

    procedure drawpaddleup (clr : string) %this allows us to change the paddle colour
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, black)
        movepaddley += 1
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, white)
        View.Update
    end drawpaddleup

    procedure drawpaddledown (clr : string)
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, black)
        movepaddley += -1
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, white)
        View.Update
    end drawpaddledown

    procedure drawpaddleright (clr : string)
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, black)
        movepaddlex += 1
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, white)
        View.Update
    end drawpaddleright

    procedure drawpaddleleft (clr : string)
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, black)
        movepaddlex += -1
        drawfillbox (movepaddlex, movepaddley, movepaddlex + 40, movepaddley + 40, white)
        View.Update
    end drawpaddleleft



    %this procedure collects keyboard input and moves the paddle.

    procedure slidepaddle
        %read paddle movement direction

        loop
            Input.KeyDown (getkey)
            if getkey (KEY_UP_ARROW) then
                drawpaddleup ("white")
                delay (1)
            end if
            if getkey (KEY_DOWN_ARROW) then
                drawpaddledown ("white")
                delay (1)
            end if
            if getkey (KEY_RIGHT_ARROW) then
                drawpaddleright ("white")
                delay (1)
            end if
            if getkey (KEY_LEFT_ARROW) then
                drawpaddleleft ("white")
                delay (1)

            end if
            drawfillbox (600, 20, 610, 340, white)
            drawfillbox (45, 10, 610, 20, white)
            drawfillbox (45, 340, 610, 350, white)
            drawfillbox (45, 10, 55, 340, white)

            if (movepaddley = 299) then
                movepaddley := 299
            elsif (movepaddlex >= 559) then
                movepaddlex := 559
            elsif (movepaddlex 