setscreen ("graphics:800;600")
var chars : array char of boolean
var score, timealive : real
var enemyreset : int
var playerx, playery, circle_1_radius : int
var enemyy1, enemyy2, circle_2_radius : int
var enemyx1 : array 0 .. 10 of int
var distance_between_centres : real
%assigning values to the variables for the circules
playerx := 700
playery := 300
circle_1_radius := 10
circle_2_radius := 10
enemyy1 := Rand.Int (20, 600)
enemyy2 := Rand.Int (20, 600)
enemyx1 (0) := 0
enemyx1 (1) := 0
score := 0
timealive := 0
enemyreset := 900
%main game
loop
Input.KeyDown (chars)
% move character
if chars (KEY_RIGHT_ARROW) then
playery := playery + 5
end if
if chars (KEY_LEFT_ARROW) then
playery := playery - 5
end if
cls
%character
drawfilloval (playerx, playery, circle_1_radius, circle_2_radius, red)
%time alive
put "TIME: ", timealive ..
%score
put " SCORE: ", score ..
%enemy
drawfilloval (enemyx1 (0), enemyy1, circle_1_radius, circle_2_radius, blue)
drawfilloval (enemyx1 (1), enemyy2, circle_1_radius, circle_2_radius, brightblue)
%Checks if enemy has past the player and resets at the start
if enemyx1 (1) > enemyreset then
enemyx1 (1) := 0
enemyy2 := Rand.Int (20, 599)
end if
if enemyx1 (0) > enemyreset then
enemyx1 (0) := 0
enemyy1 := Rand.Int (20, 600)
end if
delay (20)
%moves the enemys
enemyx1 (0) := enemyx1 (0) + 3
enemyx1 (1) := enemyx1 (1) + 3
%calculate the distance between the centres of the circles
distance_between_centres := sqrt ((playerx - enemyx1 (0)) ** 2 + (playery - enemyy1) ** 2)
distance_between_centres := sqrt ((playerx - enemyx1 (1)) ** 2 + (playery - enemyy2) ** 2)
%checks if the player got hit
if distance_between_centres <= circle_1_radius + circle_2_radius then
put " You got hit"
exit
end if
%counts score
score := score + 5
%counts time alive
timealive := timealive + 0.02
end loop
|