%-----------------------------------------------------------------------------
% Title of Program : Ping Pong Game
% Purpose : It's a game with some crazy rules or let's say No rules
% Author : Anas Obaisi
% Date : last edited December 19, 2002, 9:18 e
%-----------------------------------------------------------------------------
%-----------------------------------------------------------------------------
%Variable Dictionary
%-----------------------------------------------------------------------------
var b, n : int %Cordenates of the cercle centre
var chars : array char of boolean %Arrys
var x : int % the center of the circle
var y : int % the center of the circle
var dx : int %The Change in x
var dy : int %The Change in y
var picID : int %The ball image
var picBack : int %the Background Picture
var t : array 1 .. 8 of int := init (100, 100, 135, 185, 220, 220, 185, 135) %initiling the lines of the polygon
var z : array 1 .. 8 of int := init (100, 150, 185, 185, 150, 100, 65, 65) %initiling the lines of the polygon
var distance : real
var cx : int := 5
var cy : int := 5
%-----------------------------------------------------------------------------
%Setting Values For Variables
%-----------------------------------------------------------------------------
x := 100 %assigning where the centre of the circle must be
y := 240 %assigning where the centre of the circle must be
dx := Rand.Int (10, 15) %setting the changes of x to random number
dy := Rand.Int (10, 15) %setting the changes of y to random number
b := 100 %Centre of the Circle
n := 100 %Centre of the Circle
% distance := ((b - x) * (b - x) + (n - y) * (n - y)) ** 0.5
%-----------------------------------------------------------------------------
% SET SCREEN SETTINGS
%-----------------------------------------------------------------------------
setscreen ("graphics:v16") % sets the screen for vga mode 640 x 480
setscreen ("nocursor") % Turn off cursor
setscreen ("noecho") % Do not echo keys
%----------------------------------------------------------------------------
%Drawing the intor screen
%----------------------------------------------------------------------------
Draw.FillBox (0, 0, maxx, maxy, black)
delay (1000)
Draw.FillPolygon (t, z, 8, brightblue)
Draw.Polygon (t, z, 8, cyan)
delay (1000)
var font4 : int
font4 := Font.New ("Palatino:40:bold,italic")
Font.Draw ("Welcome", 200, 300, font4, green)
delay (1000)
put "Try to prevent the bouncy ball from going behind your big circle"
delay (3000)
%----------------------------------------------------------------------------
%Play Music while the program is running
%----------------------------------------------------------------------------
process Rock
loop
Music.PlayFile ("Seymor.mid")
end loop
end Rock
fork Rock
%----------------------------------------------------------------------------
%Drawing Background
%----------------------------------------------------------------------------
Draw.FillBox (0, 0, maxx, maxy, 10)
for v : 80 .. 640 by 80
Draw.Line (v, 0, v, 480, 0)
end for
for h : 60 .. 640 by 60
Draw.Line (0, h, 640, h, 0)
end for
drawbox (0, 0, maxx, maxy, 1)
drawbox (4, 4, maxx - 4, maxy - 4, 1)
drawfill (1, 1, 1, 1)
%---------------------------------------------------------------------------
% Capture Image as Background and Draw it
%---------------------------------------------------------------------------
picBack := Pic.New (0, 0, maxx, maxy)
Pic.Draw (picBack, 0, 0, picCopy)
cls
%---------------------------------------------------------------------------
%Drawing the Ball
%---------------------------------------------------------------------------
procedure ran
for j : 1 .. 2
randint (x, 200, maxx - 400)
randint (y, 300, maxy - 200)
randint (dx, 1, 5)
randint (dy, 1, 5)
end for
end ran
Draw.Oval (x, y, 10, 10, blue)
Draw.Dot (105, 240, 3)
Draw.Fill (105, 240, blue, blue)
picID := Pic.New (90, 200, 115, 250)
%---------------------------------------------------------------------------
%looping and setting the walls
%---------------------------------------------------------------------------
loop
distance := ((b - x) * (b - x) + (n - y) * (n - y)) ** 0.5
if distance < 10 %if collision
then
cx := round(dx * dx + dy * dy) ** 0.5 * ((b - x) / (b - x + n - y))
cy := round(dx * dx + dy * dy) ** 0.5 * ((n - y) / (b - x + n - y))
end if
if distance < 50 then
dx := -dx
end if
Pic.Draw (picBack, 0, 0, picCopy)
Pic.Draw (picID, x, y, picMerge)
delay (40)
x := x + dx
if x >= maxx - 20 or x <= 0 then
dx := -dx
end if
y := y + dy
if y >= maxy - 50 or y <= -30 then
dy := -dy
end if
%-----------------------------------------------------------------------------
%Make The Big Circle move using the Keyboared
%-----------------------------------------------------------------------------
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
n := n + cy
elsif chars (KEY_RIGHT_ARROW) then
b := b + cx
elsif chars (KEY_LEFT_ARROW) then
b := b - cx
elsif chars (KEY_DOWN_ARROW) then
n := n - cy
end if
drawoval (b, n, 40, 40, red)
delay (5)
end loop
|