% Air Hockey V.3
View.Set ("graphics:800;600,title:Air Hockey, offscreenonly, nocursor")
var puckX, puckY : int := 0
var pad1X, pad1Y, button : int := 0
var pad2X, pad2Y : int := 0
var changeX, changeY := 10
var playerScore, compuScore : int := 0
var sign1X : int := 0
var sign2X : int := 480
var font1 : int := Font.New ("Courier New:40:bold")
var font2 : int := Font.New ("Courier New:20:bold")
var font3 : int := Font.New ("Courier New:10:bold")
var timeLeft : int := 6000
var keyPressed : string (1)
var signSwitch : boolean := false
var overTime : boolean := false
procedure Reset (restart : boolean)
changeX := -10
changeY := -10
puckX := 650
puckY := 300
pad2X := 740
pad2Y := 250
if restart then
playerScore := 0
compuScore := 0
timeLeft := 6000
overTime := false
end if
end Reset
procedure Intro
loop
Text.Cls
Font.Draw ("Press any key to continue", 260, 25, font3, blue)
Font.Draw ("Air Hockey", sign1X, 500, font1, blue)
Font.Draw ("Air Hockey", sign2X, 100, font1, blue)
Font.Draw ("Instructions", 350, 450, font3, blue)
Font.Draw ("Move the mouse to block the puck", 250, 400, font3, blue)
Font.Draw ("from entering your net", 250, 380, font3, blue)
Font.Draw ("Keyboard:", 250, 325, font3, blue)
Font.Draw ("p - Pauses the game", 250, 305, font3, blue)
Font.Draw ("x - Exits current game and", 250, 275, font3, blue)
Font.Draw (" returns to this screen", 250, 255, font3, blue)
Font.Draw ("r - Refreshs the screen", 250, 235, font3, blue)
Font.Draw ("Each game lasts one minute", 250, 170, font3, blue)
if sign1X <= 0 then
signSwitch := true
elsif sign1X >= 460 then
signSwitch := false
end if
if signSwitch then
sign1X += 1
sign2X -= 1
elsif signSwitch = false then
sign1X -= 1
sign2X += 1
end if
View.Update
exit when hasch
Time.Delay (10)
end loop
Reset (true)
end Intro
loop
Intro
loop
% Time
timeLeft -= 2
if timeLeft <= 0 then
if playerScore > compuScore then
Font.Draw ("Player Wins", 300, 240, font2, black)
View.Update
getch (keyPressed)
Intro
elsif playerScore < compuScore then
Font.Draw ("Computer Wins", 285, 240, font2, black)
View.Update
getch (keyPressed)
Intro
elsif playerScore = compuScore then
timeLeft := 0
overTime := true
end if
end if
% Controls
Mouse.Where (pad1X, pad1Y, button)
if pad1X >= 365 then
pad1X := 365
elsif pad1X <= 35 then
pad1X := 35
end if
if pad1Y >= 465 then
pad1Y := 465
elsif pad1Y <= 35 then
pad1Y := 35
end if
if hasch then
getch (keyPressed)
if keyPressed = "p" then
getch (keyPressed)
elsif keyPressed = "r" then
puckX := 600
puckY := 250
pad1X := 50
pad1Y := 250
pad2X := 700
pad2Y := 250
elsif keyPressed = "x" then
exit
end if
end if
% Computer
if changeX >= 0 then
pad2X += 3
elsif changeX <= 0 then
pad2X -= 3
end if
if changeY >= 0 then
pad2Y += 3
elsif changeY <= 0 then
pad2Y -= 3
end if
if pad2X >= 765 then
pad2X := 765
elsif pad2X <= 35 then
pad2X := 35
end if
if pad2Y >= 465 then
pad2Y := 465
elsif pad2Y <= 35 then
pad2Y := 35
end if
% Puck
puckX += changeX
puckY += changeY
if whatdotcolor (puckX + 11, puckY) = red then
changeX := -changeX
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX - 11, puckY) = red then
changeX := -changeX
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX, puckY + 11) = red then
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX, puckY - 11) = red then
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX + 13, puckY + 13) = red then
changeX := -changeX
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX + 13, puckY - 13) = red then
changeX := -changeX
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX - 13, puckY + 13) = red then
changeX := -changeX
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if whatdotcolor (puckX - 13, puckY - 13) = red then
changeX := -changeX
changeY := -changeY
puckX += changeX
puckY += changeY
end if
if puckX <= 10 or puckX >= 790 then
changeX := -changeX
sound (500, 10)
end if
if puckY <= 10 or puckY >= 490 then
changeY := -changeY
sound (500, 10)
end if
% Graphics
Text.Cls
locate (29, 80)
Font.Draw ("Player", maxx div 2 - 300, maxy - 50, font2, black)
Font.Draw (intstr (playerScore), maxx div 2 - 260, maxy - 85, font2, black)
Font.Draw ("Computer", maxx div 2 + 175, maxy - 50, font2, black)
Font.Draw (intstr (compuScore), maxx div 2 + 235, maxy - 85, font2, black)
if overTime then
Font.Draw ("Over Time", maxx div 2 - 170, maxy - 60, font1, black)
else
Font.Draw (realstr (timeLeft / 100, 0), maxx div 2 - 80, maxy - 60, font1, black)
end if
Draw.FillMapleLeaf (300, 20, 480, 200, red)
Draw.FillMapleLeaf (300, 480, 480, 300, red)
Draw.Box (10, 10, 790, 490, black)
Draw.FillBox (0, 175, 10, 325, purple)
Draw.FillBox (790, 175, 800, 325, purple)
Draw.FillOval (pad1X, pad1Y, 25, 25, red)
Draw.FillOval (pad2X, pad2Y, 25, 25, red)
Draw.FillOval (puckX, puckY, 10, 10, black)
% Scoring
if puckX + 10 >= maxx - 10 and puckY > 185 and puckY < 315 then
Reset (false)
playerScore += 1
Font.Draw ("Goal", 355, 240, font2, black)
View.Update
getch (keyPressed)
end if
if puckX - 10 <= 10 and puckY > 185 and puckY < 315 then
Reset (false)
compuScore += 1
Font.Draw ("Goal", 355, 240, font2, black)
View.Update
getch (keyPressed)
end if
% Others
View.Update
Time.Delay (10)
end loop
end loop |