%%game window
var game_window : int
game_window := Window.Open ("Graphics: max;max, title: Basic Astroids")
View.Set ("offscreenonly, noecho, nocursor, nobuttonbar")
%%Variables
%%for the back ground stars
var xStar : array 1 .. 50 of int
var yStar : array 1 .. 50 of int
%%randomize their variables
for i : 1 .. 50
randint (xStar (i), 0, maxx)
randint (yStar (i), 0, maxy)
end for
%%ship points
var xPoint : array 1 .. 3 of real
var yPoint : array 1 .. 3 of real
var rotate : real := 0
var angle : real := 90
var keys : array char of boolean
var game_level : int := 0
var score : int := 0
var oldscore : int := 0
var life : int := 3
var leave_for : boolean := false
%%ship speed
var xSpeed : real := 0
var ySpeed : real := 0
%%ships bullets
type Bullets :
record
x : real
y : real
xdir : real
ydir : real
distance : real
end record
var Bullet : flexible array 0 .. 0 of Bullets
var chance_to_spawn_upgrade : int := 2
%%Declare and Set Center Point
var xCenter : real
var yCenter : real
%%astroids
type astroids :
record
x : int
y : int
xs : int %%speed (it;ll be for direction too)
ys : int
size : int
amount : int
end record
var Astroid : flexible array 0 .. 0 of astroids
%%set value's
xPoint (1) := 100 %%(1) = left, 2 = top, 3 = right
yPoint (1) := 100
xPoint (2) := 105
yPoint (2) := 120
xPoint (3) := 110
yPoint (3) := 100
%%procs
%%this will rotate the ship points
proc Rotate_Ship (var x : real, var y : real, var cx : real, var cy : real, var deg : real) %%gets chords per point
%%temperary variables
var tempx : real
var tempy : real
tempx := ((x - cx) * cosd (deg) - (y - cy) * sind (deg)) + cx %Rotate x Point
tempy := ((x - cx) * sind (deg) + (y - cy) * cosd (deg)) + cy %Rotate y Point
%%reset the vars
x := tempx
y := tempy
end Rotate_Ship
%%this will draw anything needed in the game
proc Drawing
%%the back ground screen
Draw.FillBox (0, 0, maxx, maxy, black)
for i : 1 .. 50
Draw.FillOval (xStar (i), yStar (i), 1, 1, white)
end for
%%display (level/score/life)
color (gray)
colorback (black)
locate (2, 10)
put "Level: ", game_level
locate (2, 50)
put "Lives: ", life
locate (2, 90)
put "Score: ", score
%%the ship
drawline (round (xPoint (1)), round (yPoint (1)), round (xPoint (2)), round (yPoint (2)), white)
drawline (round (xPoint (2)), round (yPoint (2)), round (xPoint (3)), round (yPoint (3)), white)
drawline (round (xPoint (3)), round (yPoint (3)), round (xPoint (1)), round (yPoint (1)), white)
%%bullets
for i : 1 .. upper (Bullet)
Draw.FillOval (round (Bullet (i).x), round (Bullet (i).y), 1, 1, white)
end for
%%astroids
for i : 1 .. upper (Astroid)
Draw.Oval (Astroid (i).x, Astroid (i).y, Astroid (i).size, Astroid (i).size, white)
end for
end Drawing
%%this will shoot the bullet
proc Shooting
Input.KeyDown (keys)
%%spawns you a bullet
if keys (KEY_CTRL) then %%shoots the bullet
if upper (Bullet) + 1 <= 3 then
if upper (Bullet) <= 0 then
new Bullet, upper (Bullet) + 1
Bullet (upper (Bullet)).x := xPoint (2)
Bullet (upper (Bullet)).y := yPoint (2)
Bullet (upper (Bullet)).xdir := cosd (angle) * 10
Bullet (upper (Bullet)).ydir := sind (angle) * 10
Bullet (upper (Bullet)).distance := 350
elsif Bullet (upper (Bullet)).distance < 300 then %%i add this for a delay without slowing game
new Bullet, upper (Bullet) + 1
Bullet (upper (Bullet)).x := xPoint (2)
Bullet (upper (Bullet)).y := yPoint (2)
Bullet (upper (Bullet)).xdir := cosd (angle) * 10
Bullet (upper (Bullet)).ydir := sind (angle) * 10
Bullet (upper (Bullet)).distance := 350
end if
end if
end if
%%move bullets
for i : 1 .. upper (Bullet)
Bullet (i).x += Bullet (i).xdir
Bullet (i).y += Bullet (i).ydir
Bullet (i).distance -= 5
end for
%%kill bullets
for i : 1 .. upper (Bullet)
if Bullet (i).distance <= 0 then
Bullet (i) := Bullet (upper (Bullet))
new Bullet, upper (Bullet) - 1
exit
end if
end for
end Shooting
proc Add_Astroids (var amount : int)
if amount >= 12 then %total astroids
new Astroid, upper (Astroid) + 12
else %%your not that far.. (1 astroid per level)
new Astroid, upper (Astroid) + amount
end if
%%to spawn them
for i : 1 .. upper (Astroid)
randint (Astroid (i).x, 1, 4)
%%setting astroids off screen to stop the effect of (teleportation)
if Astroid (i).x = 1 then %%set off to left
Astroid (i).x := -20
randint (Astroid (i).y, 20, maxy - 20)
randint (Astroid (i).ys, -5, 5)
randint (Astroid (i).xs, 1, 5) %%make it aim to center
elsif Astroid (i).x = 2 then %%set it to right
Astroid (i).x := maxx + 20
randint (Astroid (i).y, 20, maxy - 20)
randint (Astroid (i).ys, -5, 5)
randint (Astroid (i).xs, -5, -1)
elsif Astroid (i).x = 3 then %%set at top
Astroid (i).y := maxy + 20
randint (Astroid (i).x, 20, maxx - 20)
randint (Astroid (i).xs, -5, 5)
randint (Astroid (i).ys, -5, -1)
else %%bottom
Astroid (i).y := -20
randint (Astroid (i).x, 20, maxx - 20)
randint (Astroid (i).xs, -5, 5)
randint (Astroid (i).ys, 1, 5)
end if
Astroid (i).size := 40 %%custom size
end for
end Add_Astroids
%%this will move everything
proc Move_Obsticles
Input.KeyDown (keys)
%%rotates the ship
if keys (KEY_LEFT_ARROW) then
rotate := 6
elsif keys (KEY_RIGHT_ARROW) then
rotate := -6
else
rotate := 0
end if
%%reste the center variables for the ship
xCenter := (xPoint (1) + xPoint (2) + xPoint (3)) / 3
yCenter := (yPoint (1) + yPoint (2) + yPoint (3)) / 3
%%rotates the 3 points
for i : 1 .. 3
Rotate_Ship (xPoint (i), yPoint (i), xCenter, yCenter, rotate)
end for
angle += rotate %%so i know which way my ship is facing
%%sets ships speed
if keys (KEY_UP_ARROW) then
xSpeed += cosd (angle) * .2
ySpeed += sind (angle) * .2
%%going TopRight
if xSpeed > 10 then
xSpeed := 10
elsif ySpeed > 10 then
ySpeed := 10
%%going BottomLeft
elsif xSpeed < -10 then
xSpeed := -10
elsif ySpeed < -10 then
ySpeed := -10
end if
end if
%%moves the ship
xCenter += xSpeed
yCenter += ySpeed
for i : 1 .. 3
xPoint (i) += xSpeed
yPoint (i) += ySpeed
end for
%%For astroids
%%if no astroids then...
if upper (Astroid) <= 0 then
game_level += 1
Add_Astroids (game_level) %%will spawn astroids
end if
%%move the astroids
for i : 1 .. upper (Astroid)
Astroid (i).x += Astroid (i).xs
Astroid (i).y += Astroid (i).ys
end for
end Move_Obsticles
%%boundries for everything
proc Boundries
%%makes the ship warp
if xPoint (1) < 1 and xPoint (2) < 1 and xPoint (3) < 1 then
for i : 1 .. 3
xPoint (i) += maxx
end for
elsif xPoint (1) > maxx - 1 and xPoint (2) > maxx - 1 and xPoint (3) > maxx - 1 then
for i : 1 .. 3
xPoint (i) -= maxx
end for
end if
if yPoint (1) < 1 and yPoint (2) < 1 and yPoint (3) < 1 then
for i : 1 .. 3
yPoint (i) += maxy
end for
elsif yPoint (1) > maxy - 1 and yPoint (2) > maxy - 1 and yPoint (3) > maxy - 1 then
for i : 1 .. 3
yPoint (i) -= maxy
end for
end if
%%make the bullets warp
for i : 1 .. upper (Bullet)
if Bullet (i).x >= maxx - 1 then
Bullet (i).x -= maxx
elsif Bullet (i).x <= 1 then
Bullet (i).x += maxx
end if
if Bullet (i).y >= maxy - 1 then
Bullet (i).y -= maxy
elsif Bullet (i).y <= 1 then
Bullet (i).y += maxy
end if
end for
%%warp astroids
for i : 1 .. upper (Astroid)
if Astroid (i).x + Astroid (i).size <= 0 then
Astroid (i).x += maxx - Astroid (i).x
elsif Astroid (i).x >= maxx then
Astroid (i).x -= maxx + Astroid (i).size
end if
if Astroid (i).y + Astroid (i).size <= 0 then
Astroid (i).y += maxy - Astroid (i).y
elsif Astroid (i).y >= maxy then
Astroid (i).y -= maxy + Astroid (i).size
end if
end for
%%shoot the astroid
for i : 1 .. upper (Astroid)
leave_for := false
for j : 1 .. upper (Bullet)
if Bullet (j).x <= Astroid (i).x + Astroid (i).size and Bullet (j).x >= Astroid (i).x - Astroid (i).size and
Bullet (j).y <= Astroid (i).y + Astroid (i).size and Bullet (j).y >= Astroid (i).y - Astroid (i).size then
% this will make smaller astroids as you shoot them
if Astroid (i).size > 10 then
if Astroid (i).size = 40 then
score += 20
oldscore += 20
else
score += 50
oldscore += 50
end if
new Astroid, upper (Astroid) + 1 %%add's 1 for breaking onto two
Astroid (upper (Astroid)) := Astroid (i)
Astroid (i).xs += 1
Astroid (upper (Astroid)).xs -= 1
Astroid (i).ys += 1
Astroid (upper (Astroid)).ys -= 1
Astroid (i).size -= Astroid (i).size div 2
Astroid (upper (Astroid)).size -= Astroid (upper (Astroid)).size div 2
else %%this KILLS the small ones
score += 100
oldscore += 100
if i = upper (Astroid) then
new Astroid, upper (Astroid) - 1
else
Astroid (i) := Astroid (upper (Astroid))
new Astroid, upper (Astroid) - 1
end if
end if
leave_for := true
%%kill the bullet used
Bullet (j) := Bullet (upper (Bullet))
new Bullet, upper (Bullet) - 1
exit %%needed to kill the bullet correctly.
end if
end for
if leave_for = true then
exit
end if
end for
%%add's a life at a certain pointage's
if oldscore >= 1240 then %(equivilent to 2 astroids)
oldscore -= 1240
life += 1
end if
%%ship collition (means you lose)
for i : 1 .. upper (Astroid)
leave_for := false
for j : 1 .. 3 %%the ships points
if xPoint (j) <= Astroid (i).x + Astroid (i).size and xPoint (j) >= Astroid (i).x - Astroid (i).size and
yPoint (j) <= Astroid (i).y + Astroid (i).size and yPoint (j) >= Astroid (i).y - Astroid (i).size then
if xPoint (j) < 300 then
for h : 1 .. 3
xPoint (h) += 200
end for
else
for h : 1 .. 3
xPoint (h) -= 200
end for
end if
if yPoint (j) < 300 then
for h : 1 .. 3
yPoint (h) += 200
end for
else
for h : 1 .. 3
yPoint (h) -= 200
end for
end if
life -= 1 %%take off a life
end if
end for
end for
end Boundries
%%main loop
loop
Input.KeyDown (keys)
cls
Drawing %%draws everything
Move_Obsticles %%moves ship/astroids
Boundries %%what it says
Shooting %%creats/moves bullets
%%Exit the game
if keys (KEY_ESC) then
exit
end if
%%or lose
if life <= 0 then
exit
end if
View.Update
delay (20)
end loop
Window.Close (game_window)
|