function Find_Length (X1, Y1, X2, Y2 : int) : real
result sqrt (((X2 - X1) ** 2) + ((Y2 - Y1) ** 2))
end Find_Length
procedure Cross_Hairs (X, Y : int)
const C_C := 0
drawoval (X, Y, 50, 50, C_C)
Draw.ThickLine (X - 20, Y, X - 50, Y, 3, C_C)
Draw.ThickLine (X + 20, Y, X + 50, Y, 3, C_C)
Draw.ThickLine (X, Y - 20, X, Y - 50, 3, C_C)
Draw.ThickLine (X, Y + 20, X, Y + 50, 3, C_C)
drawline (X - 2, Y, X - 20, Y, C_C)
drawline (X + 2, Y, X + 20, Y, C_C)
drawline (X, Y - 2, X, Y - 20, C_C)
drawline (X, Y + 2, X, Y + 20, C_C)
drawline (X, 1, X, maxy, C_C)
drawline (1, Y, maxx, Y, C_C)
end Cross_Hairs
% these are the various sound effects
process Bang
sound (200, 100)
end Bang
process Crash
sound (100, 100)
end Crash
process Flash
sound (100, 100)
end Flash
% Constants
const SPEED := 1
const NUM_OF_ASTERIODS := 10
const NUM_OF_STARS := 100
const SIZE := 10
const TOTAL_TIME := 120
%vars
var Xm, Ym, Click : int
var Shot : boolean := false
var XA, YA : array 1 .. NUM_OF_ASTERIODS of int
var Length : array 1 .. NUM_OF_ASTERIODS of real
var PauseVar : char
var XS, YS : array 1 .. NUM_OF_STARS of int % to draw stars
var MenuTime : int
var Shields : int := 100
var TimeLeft : int
var Font1 : int := Font.New ("Avenida LET:30")
var Font2 : int := Font.New ("Avenida LET:12")
var Font3 : int := Font.New ("Copperplate:50")
var HC : int := 10
var IntToString : string
var RY : int
% these next two are used to make warnings flash on the screen
var WarningFlash : nat := 0
var HealthFlash : nat := 0
% explosion vars (used near the end to draw the explosion)
var XE, YE, XEX, YEX : int
setscreen ("graphics:max,max,nobuttonbar,offscreenonly")
for Index : 1 .. NUM_OF_ASTERIODS
randint (XA (Index), 1, maxx)
randint (YA (Index), maxy, maxy + 100)
end for
for Index : 1 .. NUM_OF_STARS
randint (XS (Index), 1, maxx)
randint (YS (Index), 1, maxy)
end for
colourback (7)
const MID_X := maxx div 2
const MID_Y := maxy div 2
cls
for Index : 1 .. NUM_OF_STARS
drawdot (XS (Index), YS (Index), 0)
end for
Font.Draw ("Base Protector", 1, MID_Y + 100, Font3, 12)
Font.Draw ("(press any key to continue)", 1, 20, Font1, 0)
View.Update
PauseVar := getchar
cls
color (0)
put "The purpose of this game is to defend your base on the moon while " ..
put "it is being evacuated from "
put "a meteor shower"
put ""
put "Use the mouse to shoot the meteors before they hit your base."
put "If one does hit your base the base's shields get dammaged."
put "The shield meter is located on the right hand side."
put ""
put "The progress of the evacuation is shown by the red bar at the top" ..
put " of the screen."
put "You win when the evacuation is complete."
put "You lose if the shields go down and the base is destroyed"
put ""
color (12)
put "(press any key to continue)"
View.Update
PauseVar := getchar
MenuTime := Time.Elapsed
loop
cls
for Index : 1 .. NUM_OF_STARS
drawdot (XS (Index), YS (Index), 0)
end for
TimeLeft := (TOTAL_TIME - ((Time.Elapsed / 1000) div 1) + MenuTime / 1000 div 1)
mousewhere (Xm, Ym, Click)
% what colour should the shield bar be?
if Shields < 50 and Shields > 20 then
HC := 14
elsif Shields <= 20 then
HealthFlash := HealthFlash + 1
if HealthFlash > 10 then
drawfillbox (maxx - 45, (Shields * 2) + 100, maxx - 15, 100, 14)
else
drawfillbox (maxx - 45, (Shields * 2) + 100, maxx - 15, 100, 12)
end if
if HealthFlash > 20 then
HealthFlash := 0
end if
HC := 12
end if
% HEALTH BAR
IntToString := intstr (Shields)
Font.Draw (IntToString + "%", maxx - 100, 50, Font1, 0)
drawbox (maxx - 50, (100 * 2) + 110, maxx - 10, 90, 0)
if Shields > 20 then
drawfillbox (maxx - 45, (Shields * 2) + 100, maxx - 15, 100, HC)
end if
% asteroid drawing
for Index : 1 .. NUM_OF_ASTERIODS
YA (Index) := YA (Index) - SPEED
if YA (Index) < 20 then
if Shields < 0 then
else
Shields := Shields - 5
fork Crash
end if
randint (XA (Index), 1, maxx)
randint (YA (Index), maxy, maxy + 100)
end if
drawfilloval (XA (Index), YA (Index), SIZE, SIZE, 15)
end for
% display time left
% IntToString := intstr (TimeLeft)
% Font.Draw ("Time left : " + IntToString, 1, maxy - 30, Font1, 10)
% evacuation bar
drawbox (20, maxy - 20, (TOTAL_TIME * 4) + 20, maxy - 10, 0)
drawfillbox (20, maxy - 18, 20 + (TimeLeft * 4), maxy - 12, 12)
% display a warning if the shields are down
if Shields = 0 then
WarningFlash := WarningFlash + 1
if WarningFlash > 10 then
Font.Draw ("WARNING!", MID_X + 200, MID_Y + 100, Font1, 12)
fork Flash
end if
if WarningFlash > 20 then
WarningFlash := 0
end if
end if
%
if Click = 1 then
% laser
Draw.ThickLine (Xm, Ym, MID_X, 20, 3, 12)
end if
if Click = 1 and Shot = false then
Shot := true
fork Bang
% check to see if a asteroid got hit
for Index : 1 .. NUM_OF_ASTERIODS
Length (Index) := Find_Length (Xm, Ym, XA (Index), YA (Index))
if Length (Index) < SIZE then
randint (XA (Index), 1, maxx)
randint (YA (Index), maxy, maxy + 100)
end if
end for
elsif Click = 0 then
Shot := false
end if
% base draw
drawfillbox (1, 1, maxx, 15, 15)
drawbox (1, -10, maxx, 15, 0)
drawoval (MID_X, 20, 20, 15, 12)
drawfilloval (MID_X, 20, 18, 13, 15)
drawfillbox (MID_X - 25, 20, MID_X + 25, 1, 15)
drawfillbox (MID_X - 10, 10, MID_X + 10, 5, 12)
% crosshair drawing
Cross_Hairs (Xm, Ym)
% pause the game when enter is hit
View.Update
% EXIT POINT
exit when Shields < 0 or TimeLeft < 0
delay (10)
end loop
% Win or lose
if Shields < 0 then
% this next bit draws the base blowing up
for Boom : 1 .. 50
randint (XE, 1, maxx)
randint (YE, 1, 20)
for Explosion : 1 .. 200
loop
randint (XEX, XE - 40, XE + 40)
randint (YEX, YE - 40, YE + 40)
exit when Find_Length (XE, YE, XEX, YEX) < 40
end loop
randint (RY, 1, 2)
if RY = 1 then
RY := 12
else
RY := 14
end if
drawdot (XEX, YEX, RY)
end for
View.Update
end for
Font.Draw ("You lose!", MID_X - 100, maxy - 100, Font3, 1)
else
cls
for Index : 1 .. NUM_OF_STARS
drawdot (XS (Index), YS (Index), 0)
end for
Font.Draw ("Mission Complete...", 10, maxy - 100, Font3, 0)
Font.Draw ("The station has been evacuated", MID_X - 300, MID_Y,
Font1, 12)
end if
View.Update
|