% pong
% Potter
% pong.t
% March 2,2006
var winMain : int := Window.Open ("Graphics:781;541")
setscreen ("nocursor")
var col1 : int := 7 %colour 1 background
var col2 : int := 0 %colour 2 paddles,balland score
var delaytime : int := 10 %delay time for ball moving cause of new comp systme
%----------------------------------------------------
%starting variables (are reused)
var diff : string (1) % difficulty chose
var stop : int := 250 % delay time for start and comp move
%---------------------------------------------------------
var leave : int := 0
%------------------------ball variables
%x - x coordinate of ball
%y - y coordinate of ball
%movex - movement of x
%movey - movement of y
%size - size of ball
var x, y, movex, movey : int
var size : int := 10
x := maxx div 2 %ball start position
randint (y, 20, maxy - 20) %ball start position
movex := 2 %ball speed
movey := 2 %ball speed
%----------------------paddle variables
%padx1 - paddle x
%pady1 - paddle y
%padsizey - size of paddle
%padsizex - size of paddle
%move1 - moving y axis of paddle
var padx1, pady1, padsizey, padsizex : int
var move1 : string (1)
var movey1 : int
padx1 := 1 %user paddle start
pady1 := (maxy div 2) - (110 div 2) %user paddle start
movey1 := 40 %user move amount
%-------------------------------------------------paddle2 variables
%padx2 - paddle x
%pady2 - paddle y
%padsizey2 - size of paddle
%padsizex2 - size of paddle
%move2 - moving y axis of paddle
var padx2, pady2, padsizey2, padsizex2 : int
var movey2 : int
padx2 := maxx - 2 %comp. paddle start
pady2 := (maxy div 2) - (110 div 2) %comp. paddle start
movey2 := 20 %comp. move amount
%---------------------------------------------------------------------------
%usescore - user score
%compscore - comp score
var usescore, compscore : int := 0
%----------------------------------------------------------------
put " *****************************************************"
delay (stop)
put " * Welcome To Pong *"
delay (stop)
put " *Please enter the diffuculty your would like to play*"
delay (stop)
put " * 1.Easy *"
delay (stop)
put " * 2.Medium *"
delay (stop)
put " * 3.Hard *"
delay (stop)
put " * 4.Impossible *"
delay (stop)
put " *****************************************************"
delay (stop)
getch (diff)
loop
if ord (diff) = 49 then
put "Your Choose ", diff, ".Easy"
stop := 81
exit
elsif ord (diff) = 50 then
put "Your Choose ", diff, ".Medium"
stop := 9
exit
elsif ord (diff) = 51 then
put "Your Choose ", diff, ".Hard"
stop := 3
exit
elsif ord (diff) = 52 then
put "Your Choose ", diff, ".Impossible"
stop := 1
exit
else
put "Invaild Entry"
put "Please enter the diffuculty your would like to play"
getch (diff)
end if
end loop
put "Press Any Key to Continue"
getch (diff)
%----------------------------------------------------------------------------------------
setscreen ("offscreenonly")
%---------------------------------------------------------------------------------------
%bouncing the ball off the sides
process ball %moving ball
loop
%put "Press Any Key To Begin"
%getch (diff)
delay (100)
loop
delay (delaytime)
x := x + movex %moves ball
y := y + movey %moves ball
%ball bounces off screen
if x - size <= padsizex then % if ball in line with user paddle
if y - size <= padsizey and y + size >= pady1 then %if ball hits paddle
movex := -movex
movex := movex + 1
else % if ball misses user paddle
leave := 1
end if
end if
if x + size >= padx2 then % if ball in line with comp. paddle
if y - size <= padsizey2 and y + size >= pady2 then %if ball hits paddle
movex := -movex
movex := movex - 1
else % if ball misses paddle
leave := 2
end if
end if
if y >= maxy - 1 - 5 then %if ball hits top
movey := -movey
movey := movey - 1
elsif y <= 1 + 5 then %if ball hits bottom
movey := -movey
movey := movey + 1
end if
if leave = 1 or leave = 2 then
exit
end if
end loop
delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end ball
%___________________________________________________________________________________________
%moving the paddle1
process paddle1
loop
loop
padsizex := padx1 + 5 %paddle x and y 2 coordinates
padsizey := pady1 + 110
getch (move1) % paddle move command
%moves user paddle
if ord (move1) = 200 and padsizey <= maxy then %move up
pady1 := pady1 + movey1
elsif ord (move1) = 208 and pady1 >= 0 then %move down
pady1 := pady1 - movey1
end if
if leave = 1 or leave = 2 then
exit
end if
end loop
delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end paddle1
%________________________________________________________________________
%moving comp. paddle2
process paddle2
loop
loop
padsizex2 := padx2 + 5 %paddle x and y 2 coordinates
padsizey2 := pady2 + 110
delay (stop) % delay comp paddle
if y < pady2 + 55 then %if ball below middle of paddle
pady2 := pady2 - movey2
elsif y > padsizey2 - 55 then % if ball above middle paddle
pady2 := pady2 + movey2
end if
if leave = 1 or leave = 2 then
exit
end if
end loop
delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end paddle2
%-------------------------------------------------------------------
%all animations (ball,paddles,etc.)
process pics
loop
loop
drawfill (5,5,col1,col1) %background colour
%draws score
Text.LocateXY (maxx div 2 - 4, 40)
Text.ColourBack (col1)
Text.Colour (col2)
put "SCORE!!!"
Text.LocateXY (maxx div 2 - 4, 30)
Text.ColourBack (col1)
Text.Colour (col2)
put "USER - ", usescore
Text.LocateXY (maxx div 2 - 10, 20)
Text.ColourBack (col1)
Text.Colour (col2)
put "COMP. - ", compscore
%drawing any object goes here
drawfilloval (x, y, size, size, col2) %draws ball
drawfillbox (padx1, pady1, padsizex, padsizey, col2) % draws paddle
drawfillbox (padx2, pady2, padsizex2, padsizey2, col2) % draw comp
%paddle
View.Update
if leave = 1 or leave = 2 then
exit
end if
cls
end loop
delay (999)
exit when usescore = 5 or compscore = 5
end loop
end pics
%-----------------------------------------------------------------------------------
process score
loop
loop
if leave = 1 then % if user scores
compscore := compscore + 1
delay (1000)
leave := 0
elsif leave = 2 then % if comp scores
usescore := usescore + 1
delay (1000)
leave := 0
end if
exit when usescore = 5 or compscore = 5
end loop
exit when usescore = 5 or compscore = 5
end loop
end score
%-----------------------------------------------------------------------------
process reset
loop
delay (500)
if leave = 1 or leave = 2 then
var size : int := 10
x := maxx div 2 %ball start position
randint (y, 20, maxy - 20) %ball start position
movex := 2 %ball speed
movey := 2 %ball speed
padx1 := 1 %user paddle start
pady1 := (maxy div 2) - (110 div 2) %user paddle start
padx2 := maxx - 2 %comp. paddle start
pady2 := (maxy div 2) - (110 div 2) %comp. paddle start
end if
exit when usescore = 5 or compscore = 5
end loop
end reset
fork ball
fork paddle1
fork paddle2
fork pics
fork score
fork reset
Text.LocateXY (maxx div 2 - 4, 40)
put "SCORE!!!"
Text.LocateXY (maxx div 2 - 4, 30)
put "USER - ", usescore
Text.LocateXY (maxx div 2 - 10, 20)
put "COMP. - ", compscore
View.Update
|