Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Grade 12 Box Pong Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Garv




PostPosted: Thu Dec 03, 2009 11:09 am   Post subject: 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 <= 20 then
dy := -dy
locate (2, 75)

elsif y >= 335 then
dy := -dy
locate (2, 75)

elsif x <= 60 then
dx := -dx
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 + 42 and x >= movepaddlex-2 and y <= movepaddley + 42 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 <= 21) then
movepaddley := 21
elsif (movepaddley >= 299) then
movepaddley := 299
elsif (movepaddlex >= 559) then
movepaddlex := 559
elsif (movepaddlex <= 56) then
movepaddlex := 56
end if

end loop
end slidepaddle



procedure drawcourt
cls

locate (2, 19)



%court floor
drawfillbox (20, 0, 620, 360, black)
%lines
drawfillbox (600, 20, 610, 340, white)
drawfillbox (45, 10, 610, 20, white)
drawfillbox (45, 340, 610, 350, white)

Font.Draw ("Welcome to Pong 1.0", 240, 385, titlefont, magenta)
Font.Draw ("The up and down arrow move the paddle.", 180, 367, instfont, blue)
Font.Draw ("Your hits: ", 460, 370, hitfont, red) %(message, x value, y value, font type, colour)
end drawcourt



%********************************************

%My first task is to draw the court.
%The thing i need to remember is the screen size is 640x480, with 0,0 at the bottom left corner.
%My instruction screen
procedure opening

Font.Draw ("Welcome to my One Player Pong Game.", 140, 220, welcfont, magenta)
View.Update
locate (13, 24)
put "Would you like to play? y or n." ..
View.Update
get answer
View.Update
if answer = "y" then
locate (14, 28)
put "What is your name? " ..
View.Update
get fname
View.Update
locate (15, 26)
put "Welcome to the game, ", fname, "."
View.Update
delay (2000)
drawcourt
fork moveball
slidepaddle
cls
opening
end if
if answer = "n" then

cls
locate (14, 28)
put "Maybe next time. Goodbye."

end if
end opening
opening
%**********************************************************



The end is still glitchy.
Hope to fix it soon.
Sponsor
Sponsor
Sponsor
sponsor
apomb




PostPosted: Thu Dec 03, 2009 11:11 am   Post subject: RE:Grade 12 Box Pong Game

This is the same as the grade 11 pong game...

Mods?
lufthansa747




PostPosted: Sat Dec 05, 2009 6:13 pm   Post subject: RE:Grade 12 Box Pong Game

it does not work. when i hit the ball i lose and if i let the ball jut go around me eventually it just gets stuck and goes up and down and my hits just start going up.what is the point of the game
mirhagk




PostPosted: Sat Dec 05, 2009 8:41 pm   Post subject: RE:Grade 12 Box Pong Game

isnt pong that game that has two paddles and the ball bounces between them??? and is it actually possible to win or something? and ps you can leave the boundaries by going to the top and then going as far as you can to either side.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: