' Asteroid (rock) settings
rockSpeed = 1
rockColor = "white"
rockMin = 20 ' small size rock
rockTypes = 3 ' number of rock sizes (multiples of small rock size)
initRocks = 5
' Ammo settings
ammoSpeed = 5
ammoColor = "white"
ammoLife = 60 ' moves before auto destruct
ammoMax = 10
ammoSize = 5
' Player settings
playerColor = "white"
playerHeight = 30
playerWidth = 20
safeTime = 100 ' time player has to get out of the way on level up
' Point multiplier
pointsMultiply = 10
' Array name initialisation
rock = "rockArray"
rockAngle = "rockAngle"
rockSize = "rockSize"
ammo = "ammoArray"
ammoAngle = "ammoAngle"
ammoAge = "ammoAge"
' Re-order co-oridinates if they are the wrong way arround
If(px1 > px2) Then
tmp = px1
px1 = px2
px2 = tmp
EndIf
If(py1 > py2) Then
tmp = py1
py1 = py2
py2 = tmp
EndIf
' Check if each rock has hit something
For i = 1 To Array.GetItemCount(rock)
ax1 = Shapes.Getleft(Array.GetValue(rock, i))
ay1 = Shapes.GetTop(Array.GetValue(rock, i))
ax2 = ax1 + Array.GetValue(rockSize, i)
ay2 = ay1 + Array.GetValue(rockSize, i)
' Player collison
If(playerSafe < 1) Then
If ( (ax1 < px1 And ax2 > px1) Or (ax1 < px2 And ax2 > px2) ) Then
If ( (ay1 < py1 And ay2 > py1) Or (ay1 < py2 And ay2 > py2) ) Then
EndGame()
EndIf
EndIf
EndIf
' Ammo collison
For j = 1 to Array.GetItemCount(ammo)
bx1 = Shapes.Getleft(Array.GetValue(ammo, j))
by1 = Shapes.GetTop(Array.GetValue(ammo, j))
bx2 = bx1 + ammoSize
by2 = by1 + ammoSize
If ( (ax1 < bx1 And ax2 > bx1) Or (ax1 < bx2 And ax2 > bx2) ) Then
If ( (ay1 < by1 And ay2 > by1) Or (ay1 < by2 And ay2 > by2) ) Then
nextRemove = i
RemoveRock()
nextRemove = j
RemoveAmmo()
EndIf
EndIf
EndFor
EndFor
' Decrease the time player is safe
If (playerSafe > 0) Then
playerSafe = playerSafe - 1
EndIf
EndSub
' Add a new rock to the world
Sub AddRock
' Check if the next rock size/position has been specified
If (nextSize <> 0) Then
size = rockMin* nextSize
x = Shapes.GetLeft(nextPosition)
y = Shapes.GetTop(nextPosition)
nextSize = 0
Else
' Choose a random size and position
size = rockMin * Math.GetRandomNumber(rockTypes)
x = Math.GetRandomNumber(gameWidth - size)
y = Math.GetRandomNumber(gameHeight - size)
EndIf
' Remove a rock from the world and update score
Sub RemoveRock
removeSize = Array.GetValue(rockSize, nextRemove) / rockMin
' If not a mini rock
If (removeSize > 1) Then
' ... add new rocks until we have made up for it being broken apart...
While(removeSize > 0)
nextSize = Math.GetRandomNumber(removeSize - 1)
nextPosition = Array.GetValue(rock, nextRemove)
removeSize = removeSize - nextSize
AddRock()
EndWhile
' And give a point for a 'hit'
score = score + 1
Else
' We've destroyed it - give some extra points and
score = score + 5
EndIf
' Remove all references from the arrays
Shapes.Remove(Array.GetValue(rock, nextRemove))
For i = nextRemove To (Array.GetItemCount(rock) - 1)
Array.SetValue(rock, i, Array.GetValue(rock, i+1))
Array.SetValue(rockAngle, i, Array.GetValue(rockAngle, i+1))
Array.SetValue(rockSize, i, Array.GetValue(rockSize, i+1))
EndFor
Array.RemoveValue(rock, Array.GetItemCount(rock))
Array.RemoveValue(rockAngle, Array.GetItemCount(rockAngle))
Array.RemoveValue(rockSize, Array.GetItemCount(rockSize))
EndSub
' Check if the player has completed the level, if so, level up
Sub LevelCheck
If(Array.GetItemCount(rock) < 1) Then
nextSize = 0
For i = 1 To initRocks
AddRock()
EndFor
initRocks = initRocks + 1
' Give players some time to move out of the way
playerSafe = safeTime
EndIf
EndSub
' Add ammo to game
Sub Fire
' Remove additional ammo
While(Array.GetItemCount(ammo) > (ammoMax - 1))
nextRemove = 1
RemoveAmmo()
EndWhile
' Check ammo age
Sub AgeAmmo
While (Array.GetValue(ammoAge, 1) > ammoLife)
nextRemove = 1
RemoveAmmo()
EndWhile
EndSub
' Remove top Ammo
Sub RemoveAmmo
Shapes.Remove(Array.GetValue(ammo, nextRemove))
For i = nextRemove To (Array.GetItemCount(ammo) - 1)
Array.SetValue(ammo, i, Array.GetValue(ammo, i+1))
Array.SetValue(ammoAngle, i, Array.GetValue(ammoAngle, i+1))
Array.SetValue(ammoAge, i, Array.GetValue(ammoAge, i+1))
EndFor
Array.RemoveValue(ammo, Array.GetItemCount(ammo))
Array.RemoveValue(ammoAngle, Array.GetItemCount(ammoAngle))
Array.RemoveValue(ammoAge, Array.GetItemCount(ammoAge))
EndSub
' Display simple end game message box
Sub EndGame
play = 0
Shapes.Remove(player)
GraphicsWindow.ShowMessage("You scored " + (score * pointsMultiply) + " points. Thanks for Playing.", "Game Over!")
EndSub