/*
By : Geoff Stanley
Date : July 2003
Here is Geoff's Ultimate Pong Program, Enjoy!!
*/
%%%% Title Screen and Options Page%%%
%Key Variables%
var keys : array char of boolean
var select : int
%Fonts%
var font1 : int := Font.New ("raavi:24")
%procedures and procedure required variables
procedure drawoptions
cls
Font.Draw ("MURDER PONG", 35, 270, font1, 41)
locate (4, 15)
put "Play Game"
locate (6, 18)
put "Win"
locate (8, 17)
put "Speed"
locate (10, 15)
put "Handicap"
locate (12, 15)
put "Controls"
end drawoptions
var maxnumber : int
var minnumber : int
var changeso : int %Change in procedure selectoptions
var altered : int := 5 %Variable that will be altered in procedure selectoptions
procedure selectoptions
if keys (KEY_UP_ARROW) then
if altered = maxnumber then
altered := minnumber
else
altered += changeso
end if
delay (150)
end if
if keys (KEY_DOWN_ARROW) then
if altered = minnumber then
altered := maxnumber
else
altered -= changeso
end if
delay (150)
end if
end selectoptions
%Options%
var gameto : int := 4 %A player must win (gameto) games to win
var gametox2m1 : int % for best ## of ##, this is the last number.
var speed : int := 8 %The delay of the main loop will be: delay (speed)
var handi1 : int := 0 %Handicap for player 1
var handi2 : int := 0 %Handicap for player 2
loop %play another game loop
var winstart : int := Window.Open ("position:centre;centre,graphics:300;300,nobuttonbar,title:Pong,nocursor,offscreenonly")
var word : string := "MURDER PONG"
var height : int := 24
var x := 35
var y := 270
for rep : 1 .. length (word)
delay (100)
Font.Draw (word (rep), x, y, font1, 12)
x += (Font.Width (word (rep), font1))
View.Update
end for
delay (500)
%Options start here
loop
drawoptions
Input.KeyDown (keys)
maxnumber := 5
minnumber := 1
changeso := 1
selectoptions
select := altered
if select = 1 then
Draw.Box (110, 107, 185, 122, 2)
elsif select = 2 then
Draw.Box (110, 140, 185, 155, 2)
elsif select = 3 then
Draw.Box (110, 170, 185, 185, 2)
elsif select = 4 then
Draw.Box (110, 204, 185, 218, 2)
elsif select = 5 then
Draw.Box (110, 235, 185, 250, 2)
end if
if keys (KEY_ENTER) then
if select = 5 then
delay (150)
exit
elsif select = 4 then
delay (150)
loop
drawoptions
Input.KeyDown (keys)
Draw.Box (110, 204, 185, 218, 2)
maxnumber := 10
minnumber := 1
changeso := 1
altered := gameto
selectoptions
gameto := altered
gametox2m1 := gameto * 2 - 1
locate (maxrow - 2, 14)
put "Best ", gameto, " of ", gametox2m1
if keys (KEY_ENTER) then
altered := 4
delay (150)
exit
end if
View.Update
end loop
elsif select = 3 then
delay (150)
loop
drawoptions
Input.KeyDown (keys)
Draw.Box (110, 170, 185, 185, 2)
maxnumber := 9
minnumber := 3
changeso := 1
altered := speed
selectoptions
speed := altered
locate (maxrow - 2, 10)
put "Speed (3-9) : ", speed
if keys (KEY_ENTER) then
altered := 3
delay (150)
exit
end if
View.Update
end loop
elsif select = 2 then
select := 3
delay (150)
loop
drawoptions
Draw.Box (110, 140, 185, 155, 2)
locate (maxrow - 3, 5)
put "Player 1 Paddle Width ", handi1
locate (maxrow - 2, 5)
put "Player 2 Paddle Width ", handi2
locate (maxrow - 1, 5)
put "Back"
Input.KeyDown (keys)
maxnumber := 3
minnumber := 1
changeso := 1
altered := select
selectoptions
select := altered
if select = 3 then
Draw.FillOval (18, 65, 3, 3, 2)
elsif select = 2 then
Draw.FillOval (18, 50, 3, 3, 2)
elsif select = 1 then
Draw.FillOval (18, 35, 3, 3, 2)
end if
if keys (KEY_ENTER) then
maxnumber := 30
minnumber := -30
changeso := 3
if select = 3 then
delay (150)
loop
drawoptions
Draw.Box (110, 140, 185, 155, 2)
locate (maxrow - 3, 5)
put "Player 1 Paddle Width ", handi1
locate (maxrow - 2, 5)
put "Player 2 Paddle Width ", handi2
locate (maxrow - 1, 5)
put "Back"
Draw.FillOval (18, 65, 3, 3, 10)
Input.KeyDown (keys)
altered := handi1
selectoptions
handi1 := altered
if keys (KEY_ENTER) then
altered := 3
delay (150)
exit
end if
View.Update
end loop
elsif select = 2 then
delay (150)
loop
drawoptions
Draw.Box (110, 140, 185, 155, 2)
locate (maxrow - 3, 5)
put "Player 1 Paddle Width ", handi1
locate (maxrow - 2, 5)
put "Player 2 Paddle Width ", handi2
locate (maxrow - 1, 5)
put "Back"
Draw.FillOval (18, 50, 3, 3, 10)
Input.KeyDown (keys)
altered := handi2
selectoptions
handi2 := altered
if keys (KEY_ENTER) then
altered := 2
delay (150)
exit
end if
View.Update
end loop
elsif select = 1 then
altered := 2
delay (150)
exit
end if
end if
View.Update
end loop
elsif select = 1 then
delay (150)
loop
cls
%Draw Table
locate (2, 15)
put "Player 1"
locate (3, 17)
put "(top)"
locate (2, 25)
put "Player 2"
locate (3, 25)
put "(bottom)"
locate (4, 1)
put "Move Left"
locate (6, 1)
put "Move Right"
locate (8, 1)
put "Hold Ball"
locate (10, 1)
put "Fast Ball"
locate (12, 1)
put "Curve Left"
locate (14, 1)
put "Curve Right"
locate (4, 16)
put "Delete"
locate (6, 16)
put "Pg Down"
locate (8, 17)
put "End"
locate (10, 17)
put "Home"
locate (12, 16)
put "Insert"
locate (14, 16)
put "Pg Up"
locate (4, 29)
put "A"
locate (6, 29)
put "D"
locate (8, 29)
put "S"
locate (10, 29)
put "W"
locate (12, 29)
put "Q"
locate (14, 29)
put "E"
Draw.Line (1, 250, maxx, 250, black)
Draw.Line (95, 1, 95, maxy, black)
locate (maxrow - 1, maxcol div 2 - 2)
put "Back"
Draw.Box (117, 41, 155, 29, 2)
Input.KeyDown (keys)
if keys (KEY_ENTER) then
delay (150)
exit
end if
View.Update
end loop
end if
end if
View.Update
end loop
cls
locate (maxrow div 2 - 1, maxcol div 2 - 5)
put "GET READY!"
View.Update
delay (2500)
Window.Close (winstart)
%%%Game Beings%%%
var wingame : int := Window.Open ("position:centre;centre,graphics:max;max,nobuttonbar,title:Murder Pong")
colourback (0)
cls
var fontgoal : int := Font.New ("Book Antiqua:36:Italic")
var score1 : int := 0
var score2 : int := 0
Draw.FillBox (5, 5, 150, 10, 12)
const paddle1w : int := 60 + handi1
var paddle : int := Pic.New (5, 5, 5 + paddle1w, 10)
Draw.FillBox (5, 5, 150, 10, 12)
const paddle2w : int := 60 + handi2
var paddle2 : int := Pic.New (5, 5, 5 + paddle2w, 10)
const paddleh : int := 5
cls
Draw.FillOval (10, 10, 1, 1, 28)
Draw.Oval (10, 10, 3, 3, 27)
Draw.Oval (10, 10, 4, 4, 26)
Draw.Oval (10, 10, 5, 5, 24)
var ball : int := Pic.New (5, 5, 15, 15)
var balldx : int := 2
var balldy : int := 3
const ballh : int := 10
const ballw : int := 10
cls
View.Set ("offscreenonly")
%%%%%% THe main loop %%%%%%%
loop
var curveright1 : int := 0
var curveleft1 : int := 0
var curveright2 : int := 0
var curveleft2 : int := 0
var fastball1 : int := 0
var fastball2 : int := 0
balldx := 2
if balldy > 0 then
balldy := 3
else
balldy := -3
end if
var ballx : int := maxx div 2 - ballw div 2
var bally : int := maxy div 2 - ballh div 2
var paddle1x : int := maxx div 2 - paddle1w div 2
var paddle2x : int := maxx div 2 - paddle2w div 2
loop
cls
Input.KeyDown (keys)
%%%%Paddle 1 Controls%%
if keys (KEY_PGDN) then
paddle1x += 4
end if
if keys (KEY_DELETE) then
paddle1x -= 4
end if
if keys (KEY_END) then
if ballx > paddle1x and ballx < paddle1x + paddle1w and bally > maxy - 40 and bally < maxy - 30 then
fastball1 := 0
fastball2 := 0
ballx := paddle1x + paddle1w div 2
bally := maxy - 25 - ballh
end if
end if
if keys (KEY_HOME) then
if ballx > paddle1x and ballx < paddle1x + paddle1w and bally > maxy - 40 and bally < maxy - 30 then
fastball1 := 1
end if
end if
if keys (KEY_INSERT) then
if ballx > paddle1x and ballx < paddle1x + paddle1w and bally > maxy - 40 and bally < maxy - 30 then
curveleft1 += 1
end if
end if
if keys (KEY_PGUP) then
if ballx > paddle1x and ballx < paddle1x + paddle1w and bally > maxy - 40 and bally < maxy - 30 then
curveright1 += 1
end if
end if
%Don't let Paddle1 go off the screen
if paddle1x > maxx - paddle1w then
paddle1x := maxx - paddle1w
end if
if paddle1x < 0 then
paddle1x := 0
end if
Pic.Draw (paddle, paddle1x, maxy - 25 - paddleh, picMerge)
%%%Paddle 2 controls%%%%%
if keys ('d') then
paddle2x += 4
end if
if keys ('a') then
paddle2x -= 4
end if
if keys ('w') then
if ballx > paddle2x and ballx < paddle2x + paddle2w and bally > 30 and bally < 40 then
fastball2 := 1
end if
end if
if keys ('s') then
if ballx > paddle2x and ballx < paddle2x + paddle2w and bally > 30 and bally < 40 then
fastball1 := 0
fastball2 := 0
ballx := paddle2x + paddle2w div 2
bally := 35
end if
end if
if keys ('q') then
if ballx > paddle2x and ballx < paddle2x + paddle2w and bally > 30 and bally < 40 then
curveleft2 += 1
end if
end if
if keys ('e') then
if ballx > paddle2x and ballx < paddle2x + paddle2w and bally > 30 and bally < 40 then
curveright2 += 1
end if
end if
%Don't let Paddle2 go off the screen
if paddle2x > maxx - paddle2w then
paddle2x := maxx - paddle2w
end if
if paddle2x < 0 then
paddle2x := 0
end if
Pic.Draw (paddle2, paddle2x, 25, picMerge)
%%%%Ball Properties%%%%%%
if curveright1 = 1 then
if balldx = 3 then
balldx := 4
elsif balldx = 2 then
balldx := 3
elsif balldx = 1 then
balldx := 2
elsif balldx = 0 then
balldx := 1
elsif balldx = -1 then
balldx := 0
elsif balldx = -2 then
balldx := -1
elsif balldx = -3 then
balldx := -2
elsif balldx = -4 then
balldx := -3
end if
end if
if curveleft1 = 1 then
if balldx = -3 then
balldx := -4
elsif balldx = -2 then
balldx := -3
elsif balldx = -1 then
balldx := -2
elsif balldx = 0 then
balldx := -1
elsif balldx = 1 then
balldx := 0
elsif balldx = 2 then
balldx := 1
elsif balldx = 3 then
balldx := 2
elsif balldx = 4 then
balldx := 3
end if
end if
if curveright2 = 1 then
if balldx = 3 then
balldx := 4
elsif balldx = 2 then
balldx := 3
elsif balldx = 1 then
balldx := 2
elsif balldx = 0 then
balldx := 1
elsif balldx = -1 then
balldx := 0
elsif balldx = -2 then
balldx := -1
elsif balldx = -3 then
balldx := -2
elsif balldx = -4 then
balldx := -3
end if
end if
if curveleft2 = 1 then
if balldx = -3 then
balldx := -4
elsif balldx = -2 then
balldx := -3
elsif balldx = -1 then
balldx := -2
elsif balldx = 0 then
balldx := -1
elsif balldx = 1 then
balldx := 0
elsif balldx = 2 then
balldx := 1
elsif balldx = 3 then
balldx := 2
elsif balldx = 4 then
balldx := 3
end if
end if
if ballx < 10 or ballx > maxx - 10 then
balldx := -balldx
end if
if ballx > paddle1x and ballx < paddle1x + paddle1w and bally > maxy - 30 and bally < maxy - 20 then
fastball1 := 0
curveleft1 := 2
curveright1 := 2
curveleft2 := 0
curveright2 := 0
balldy := -balldy
end if
if ballx > paddle2x and ballx < paddle2x + paddle2w and bally > 20 and bally < 30 then
fastball2 := 0
curveleft2 := 2
curveright2 := 2
curveleft1 := 0
curveright1 := 0
balldy := -balldy
end if
ballx += balldx
bally += balldy
if fastball1 = 1 then
if balldy = -3 then
balldy := -5
end if
else
if balldy = -5 then
balldy := -3
end if
end if
if fastball2 = 1 then
if balldy = 3 then
balldy := 5
end if
else
if balldy = 5 then
balldy := 3
end if
end if
Pic.Draw (ball, ballx, bally, picMerge)
%%%%% SCORING%%%%
if bally < 0 then
score1 += 1
Font.Draw ("Player 1 Scores!!", 300, 400, fontgoal, green)
View.Update
loop
Input.KeyDown (keys)
exit when keys (KEY_ENTER)
end loop
end if
if bally > maxy then
score2 += 1
Font.Draw ("Player 2 Scores!!", 300, 400, fontgoal, green)
View.Update
loop
Input.KeyDown (keys)
exit when keys (KEY_ENTER)
end loop
end if
View.Update
exit when bally > maxy or bally < 0
delay (speed)
end loop
delay (500)
%Display current score
var gameover := false
if score1 = gameto then
loop
cls
locate (maxrow div 2 - 2, maxcol div 2 - 6)
put "PLAYER 1 WINS!!"
locate (maxrow div 2 - 1, maxcol div 2 - 4)
put score1, " - ", score2
View.Update
Input.KeyDown (keys)
if keys (KEY_ENTER) then
gameover := true
delay (150)
exit
end if
end loop
elsif score2 = gameto then
loop
cls
locate (maxrow div 2 - 2, maxcol div 2 - 6)
put "PLAYER 2 WINS!!"
locate (maxrow div 2 - 1, maxcol div 2 - 4)
put score1, " - ", score2
View.Update
Input.KeyDown (keys)
if keys (KEY_ENTER) then
gameover := true
delay (150)
exit
end if
end loop
else
loop
cls
locate (maxrow div 2 - 2, maxcol div 2 - 6)
put "P1 - P2"
locate (maxrow div 2 - 1, maxcol div 2 - 4)
put score1, " - ", score2
View.Update
Input.KeyDown (keys)
exit when keys (KEY_ENTER)
end loop
end if
exit when gameover = true
View.Update
end loop
Window.Close (wingame)
var playagain : string (1)
var gameclose := false
var winfinal : int := Window.Open ("position:centre;centre,graphics:300;300,nobuttonbar,title:Pong")
loop
locate (maxrow div 2 - 1, maxcol div 2 - 9)
put "Play again? y/n "
locate (maxrow div 2 - 1, maxcol div 2 + 8)
get playagain
if playagain = "y" or playagain = "Y" then
delay (150)
exit
elsif playagain = "n" or playagain = "N" then
gameclose := true
delay (150)
exit
else
locate (maxrow div 2 - 1, maxcol div 2 + 8)
put " "
end if
end loop
Window.Close (winfinal)
exit when gameclose = true
end loop
var winfinal := Window.Open ("position:centre;centre,graphics:300;50,nobuttonbar,title:Thanks for playing!,nocursor")
put " Thank you for playing Geoff's Pong"
put " Have a nice day "
var fontgoal : int := Font.New ("Book Antiqua:36:Italic")
Font.Free (font1)
Font.Free (fontgoal)
|