function Distance_Calc (X1, Y1, X2, Y2 : real4) : real4
result sqrt ((X1 - X2) ** 2 + (Y1 - Y2) ** 2)
end Distance_Calc
procedure Frame_Rate (var LastFrameTime : int, F_P_S : int)
if Time.Elapsed - LastFrameTime < F_P_S then
delay (F_P_S - (Time.Elapsed - LastFrameTime))
end if
LastFrameTime := Time.Elapsed
end Frame_Rate
procedure Display_Timer (LastTime, NewTime, X, Y, Font1, C : int)
var MiliTime : int
var Minutes, Seconds : int
var StringTime : string (10)
StringTime := ""
MiliTime := Time.Elapsed - LastTime
Seconds := MiliTime div 1000
Minutes := Seconds div 60
if Minutes < 10 then
StringTime := StringTime + "0"
end if
StringTime := StringTime + intstr (Minutes) + ":"
MiliTime := MiliTime - (MiliTime div 60) * 1000
loop
if Seconds >= 60 then
Seconds := Seconds - 60
else
exit
end if
end loop
if Seconds < 10 then
StringTime := StringTime + "0"
end if
StringTime := StringTime + intstr (Seconds)
Font.Draw (StringTime, X, Y, Font1, C)
end Display_Timer
function Angle_Calc (X1, Y1, X2, Y2 : real4) : real4
var Angle : real4
if X1 - X2 = 0 then
if Y1 > Y2 then
Angle := 90
else
Angle := 270
end if
elsif Y1 - Y2 = 0 then
if X1 > X2 then
Angle := 0
else
Angle := 180
end if
else
Angle := arctand ((sqrt ((Y1 - Y2) ** 2)) / (sqrt ((X1 - X2) ** 2)))
if Y1 < Y2 and X1 < X2 then
Angle := Angle + 180
elsif Y1 < Y2 and X1 > X2 then
Angle := 360 - Angle
elsif Y1 > Y2 and X1 < X2 then
Angle := 180 - Angle
end if
end if
result Angle
end Angle_Calc
%%%%%%%%% Drawing Enemies
procedure Draw_Enemy_Type1 (X, Y, Angle : int)
for Lines : 1 .. 5
drawline (round (cosd (Lines * (360 / 5) + Angle) * 10) + X,
round (sind (Lines * (360 / 5) + Angle) * 10) + Y,
round (cosd ((Lines + 1) * (360 / 5) + Angle) * 10) + X,
round (sind ((Lines + 1) * (360 / 5) + Angle) * 10) + Y
, 10)
end for
drawoval (X, Y, 5, 5, 10)
drawarc (X - round (cosd (Angle) * 15), Y - round (sind (Angle) * 15),
15, 15, Angle - 45, Angle + 45, 10)
drawline (X, Y, X + round (cosd (Angle) * 15), Y + round (sind (Angle) * 15), 10)
end Draw_Enemy_Type1
colorback (7)
cls
Draw_Enemy_Type1 (100, 100, 0)
procedure Spawn_Enemies (var X, Y, Angle : int, var C, Health : nat1)
case Rand.Int (1, 4) of
label 1 :
randint (X, 1, maxx)
Y := maxy + 200
Health := 100
C := 1
randint (Angle, 1, 360)
label 2 :
randint (X, 1, maxx)
Y := -200
Health := 100
C := 1
randint (Angle, 1, 360)
label 3 :
randint (Y, 1, maxy)
X := -200
Health := 100
C := 1
randint (Angle, 1, 360)
label :
randint (Y, 1, maxy)
X := maxx + 200
Health := 100
C := 1
randint (Angle, 1, 360)
end case
end Spawn_Enemies
%% enemy AI
procedure Enemy_AI_Type1 (XP, YP : int, var XE, YE, AngleE : int)
AngleE := round (Angle_Calc (XP, YP, XE, YE))
XE := round (XE + cosd (AngleE))
YE := round (YE + sind (AngleE))
end Enemy_AI_Type1
const FIRE_DELAY := 10
const NUM_OF_PROGS := 50
const GRAV_F := 0 %.032
const MAX_FORCE := 4.5
const ENEMY_TYPES := 4
const MAX_ENIMIES := 25
const FRAME_BUFFER := 10
type ENEMY_TYPE :
record
X, Y, Angle : int
Health : nat1
EnemyC : nat1
end record
type ENEMY_TYPE_ARRAY : array 1 .. MAX_ENIMIES of ENEMY_TYPE
type BULLET_RECORD :
record
XB, YB, VXB, VYB : real4
Shot : boolean
end record
type BULLET_TYPE : array 1 .. NUM_OF_PROGS of BULLET_RECORD
var XC : int
var YC : int
var Keys : array char of boolean
var AngleC : int
var XM, YM, Click : int
var Bullets : BULLET_TYPE
var Enemy : ENEMY_TYPE_ARRAY
var ShotNum, ShotCount : nat1
var Health : nat1
var Font1, Font2 : int
var BackGroundPic : int
var AngleE : int
var NumOfEnemies : nat1
var TimeRan : int
var TimeEndGame : int
var KillCount : nat
var TimeSinceLast : int
%procedure
setscreen ("graphics:600,600,nobuttonbar,offscreenonly")
colorback (7)
cls
for Stars : 1 .. 900
drawdot (Rand.Int (1, maxx), Rand.Int (1, maxy), 0)
end for
BackGroundPic := Pic.New (1, 1, maxx, maxy)
loop
KillCount := 0
XC := 300
YC := 300
for I : 1 .. NUM_OF_PROGS
Bullets (I).XB := 0
Bullets (I).YB := 0
Bullets (I).VXB := 0
Bullets (I).VYB := 0
Bullets (I).Shot := false
end for
Font1 := Font.New ("System:18")
Font2 := Font.New ("monofonto:18")
ShotNum := 1
ShotCount := 1
AngleC := 0
Health := 100
for E : 1 .. MAX_ENIMIES
Spawn_Enemies (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle,
Enemy (E).EnemyC, Enemy (E).Health)
end for
colorback (7)
cls
Font.Draw ("Peatore presents a test run version of ...", 1, maxy - 100,
Font2, 0)
Font.Draw ("AWESOME FUN-TIME SPACE SHOOTER GAME!!!!!",
0, maxy div 2 + 100, Font1, 12)
Font.Draw ("(PEW PEW! edition)", maxx div 2 - 200, maxy div 2 + 75, Font2, 0)
Font.Draw ("Press any key to continue", 1, 200, Font2, 12)
View.Update
loop
exit when hasch
end loop
View.Update
delay (2000)
color (10)
AngleE := 0
TimeRan := Time.Elapsed
%Display_Timer (LastTime, NewTime, X, Y, Font1, C : int)
loop
TimeSinceLast := Time.Elapsed
Pic.Draw (BackGroundPic, 0, 0, picCopy)
Display_Timer (TimeRan, 1, 200, maxy - 20, Font1, 12)
Font.Draw ("(Time Survived)", 170, maxy - 30, Font2, 0)
Font.Draw (natstr (KillCount), 10, 10, Font2, 12)
Font.Draw ("(Kill Counter)", 10, 25, Font2, 0)
mousewhere (XM, YM, Click)
Input.KeyDown (Keys)
AngleC := round (Angle_Calc (XM, YM, XC, YC))
if Keys ('d') and XC < maxx then
XC := XC + 2
end if
if Keys ('a') and XC > 1 then
XC := XC - 2
end if
if Keys ('w') and YC < maxy then
YC := YC + 2
end if
if Keys ('s') and YC > 1 then
YC := YC - 2
end if
% drawoval (XC, YC, 20, 20, 12)
drawoval (XC, YC, 7, 7, 12)
drawline (round (XC + (cosd (AngleC) * 10)
), round (YC + (sind (AngleC) * 10)
), round (XC + (cosd (AngleC) * 30)
), round (YC + (sind (AngleC) * 30)
), 12)
% drawoval (round (XC + (cosd (AngleC) * 30)
% ), round (YC + (sind (AngleC) * 30)
% ), 10, 10, 12)
drawarc (round (XC + (cosd (AngleC) * 10)
), round (YC + (sind (AngleC) * 10)
), 10, 10, AngleC + 50, AngleC - 50, 12)
drawarc (round (XC + (cosd (AngleC))
), round (YC + (sind (AngleC))
), 10, 10, AngleC - 90, AngleC + 90, 12
)
% drawoval (XC, YC, 40, 40, 12)
if Click = 1 then
ShotCount := ShotCount + 1
if ShotCount >= FIRE_DELAY then
ShotCount := 1
if ShotNum < NUM_OF_PROGS then
ShotNum := ShotNum + 1
else
ShotNum := 1
end if
Bullets (ShotNum).XB := round (XC + (cosd (AngleC)))
Bullets (ShotNum).YB := round (YC + (sind (AngleC)))
Bullets (ShotNum).Shot := true
Bullets (ShotNum).VXB := cosd (AngleC) * MAX_FORCE
Bullets (ShotNum).VYB := sind (AngleC) * MAX_FORCE
end if
end if
for I : 1 .. NUM_OF_PROGS
if Bullets (I).Shot then
drawoval (round (Bullets (I).XB), round (Bullets (I).YB), 3, 3, 12)
Bullets (I).XB := Bullets (I).XB + Bullets (I).VXB
Bullets (I).YB := Bullets (I).YB + Bullets (I).VYB
Bullets (I).VYB -= GRAV_F
for E : 1 .. MAX_ENIMIES
if Distance_Calc (Bullets (I).XB, Bullets (I).YB, Enemy (E).X, Enemy (E).Y) < 15 then
if Enemy (E).Health > 0 then
Enemy (E).Health := Enemy (E).Health - 100
Bullets (I).Shot := false
KillCount := KillCount + 1
end if
end if
end for
end if
end for
drawoval (XM, YM, 10, 10, 0)
drawline (XM, YM - 15, XM, YM + 15, 0)
drawline (XM + 15, YM, XM - 15, YM, 0)
locate (1, 1)
% put "Angle : ", AngleC
% health bar
if Keys (KEY_ENTER) then
XC := XM
YC := YM
end if
% ENEMIES
for E : 1 .. MAX_ENIMIES
if Enemy (E).Health > 0 then
Enemy_AI_Type1 (XC, YC, Enemy (E).X, Enemy (E).Y, Enemy (E).Angle)
Draw_Enemy_Type1 (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle)
if Distance_Calc (Enemy (E).X, Enemy (E).Y, XC, YC) <= 10 then
if Health > 0 then
Health := Health - 25
end if
Enemy (E).Health := 0
end if
else
Spawn_Enemies (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle,
Enemy (E).EnemyC, Enemy (E).Health)
end if
end for
drawbox (8, maxy - 20, 112, maxy - 10, 0)
drawfillbox (10, maxy - 19, 10 + Health + 1, maxy - 11, 12)
View.Update
exit when Health <= 0
Frame_Rate (TimeSinceLast, FRAME_BUFFER)
end loop
TimeEndGame := Time.Elapsed
for C : 1 .. maxy div 2 by 2
cls
drawfillbox (0, maxy, maxx, maxy - C, 12)
Font.Draw ("YOU ARE", 1, maxy div 2 + 15, Font2, 7)
Font.Draw ("DEAD!", 1, maxy div 2, Font2, 7)
View.Update
end for
delay (1000)
Font.Draw ("You lasted:", maxx div 2, maxy div 2 - 20, Font2, 12)
TimeEndGame := Time.Elapsed - TimeEndGame
Display_Timer (TimeRan + TimeEndGame, 1, 410, maxy div 2 - 20, Font1, 12)
View.Update
delay (100)
Font.Draw ("Your final kill-count is... ", 10, maxy div 2 - 100, Font2, 12)
for E : 1 .. KillCount
drawfillbox (9, maxx div 2 - 130, maxy, maxx div 2 - 170, 7)
Font.Draw (intstr (E), 10, maxy div 2 - 150, Font2, 12)
delay (10)
View.Update
end for
loop
mousewhere (XM, YM, Click)
if XM > 0 and XM < 250 and YM > 0 and YM < 20 then
drawfillbox (0, 0, 250, 20, 12)
if Click = 1 then
exit
end if
Font.Draw ("Click here to play again", 1, 1, Font2, 7)
else
drawfillbox (0, 0, 250, 20, 7)
Font.Draw ("Click here to play again", 1, 1, Font2, 12)
end if
View.Update
end loop
Input.Flush
KillCount := 0
cls
end loop
|