szBlast= 8 ' Nyan's Weapon Size
BlastSp= 3 ' Nyan's Weapon Speed
ammoMax= 5 ' Max Shots to Store
potency= 1 ' How Powerful Blaster is
hpMax= 5 ' Max Robustness Enemy Can Spawn
szBonus= 18 ' Bonus Pill's Size
szHBonus= szBonus/2
TmBonus= 10 ' Max Time (in Seconds) Bonus Pill is Available (Zero for Infinite)
' ===============================================================================
' Main Loop
' ===============================================================================
Loop:
If Running Then
'If GraphicsWindow.CanResize Then
'gw= GraphicsWindow.Width '<---- Comment this whole block of code if game is too sluggish!
'gh= GraphicsWindow.Height
'EndIf
Sprite[1]= Shapes.AddImage(Nyan1) ' Left
Sprite[2]= Shapes.AddImage(Nyan2) ' Right
Sprite[3]= Shapes.AddImage(Nyan1) ' Down (same image as left)
Sprite[4]= Shapes.AddImage(Nyan2) ' Up (same image as right)
Shapes.Rotate(Sprite[3] 270) ' Pre-rotate it downwards
Shapes.Rotate(Sprite[4] 270) ' Pre-rotate it upwards
GraphicsWindow.BrushColor= "Red
time= Shapes.AddText("0s") ' Time Elapsed
Shapes.Move(time 20,5)
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub CreateEnemyShapes
GraphicsWindow.FontSize= Math.Round(szFoe*.75)
GraphicsWindow.BrushColor= "DarkBlue
Shapes.Remove(tough)
tough= Shapes.AddText(health) ' Its toughness
If health < 1 Then
Shapes.HideShape(danger)
Shapes.HideShape(tough )
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Reset
score= 0
kills= 0
health= 0
ammo= 0
timing= -1
x= gwH ' Nyan's X Position
y= ghH ' Nyan's Y Position
delX= skip ' Nyan's Horizontal Movement
delY= 0 ' Nyan's Vertical Movement
Direction= 2 ' Nyan's Movement Direction (Left=1, Right=2, Down=3, Up=4)
Running= "True
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Clear
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Billboard
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Rainbow
If RainBow Then
GraphicsWindow.PenColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawEllipse(x + sizeH,y + sizeQ 3,3)
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub AdjustDimension
If Direction < 3 Then ' = 1 Or = 2
sizeX= x+size
sizeY= y+heightH
Else ' = 3 Or = 4
sizeX= x+height
sizeY= y+sizeH
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub HideSprites
For index= 1 To 4
Shapes.HideShape(Sprite[index])
EndFor
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub MoveSprites
If Direction <> LastDirection Then
HideSprites()
Shapes.Move(Sprite[Direction] x,y)
Shapes.ShowShape(Sprite[Direction])
LastDirection= Direction
Else
Shapes.Move(Sprite[Direction] x,y)
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub CheckBorders
If x < -sizeH Then
x= gw - sizeH
LastDirection= 0
ElseIf x > gw - sizeH Then
x= -sizeH
LastDirection= 0
EndIf
If y < -sizeH Then
y= gh - sizeH
LastDirection= 0
ElseIf y > gh + sizeH Then
y= -sizeH
LastDirection= 0
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub GenerateEnemy
If health < 1 And score > 0 And Math.Remainder(score 3) = 0 Then
health= Math.GetRandomNumber(hpMax)
bx= Math.GetRandomNumber(gw) ' Enemy's X position
by= Math.GetRandomNumber(gh) ' Enemy's Y position
Shapes.Move(danger bx,by)
Shapes.Move(tough bx,by)
Shapes.SetText(tough health)
Shapes.ShowShape(danger)
Shapes.ShowShape(tough )
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub MoveEnemy
If health > 0 Then
ChaseYou()
bx= bx + belX
by= by + belY
LimitEnemy()
Shapes.Move(danger bx, by)
Shapes.Move(tough bx+szQFoe,by)
LethalCollision()
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub ChaseYou
If bx < x Then
belX= skipH
Else
belX= -skipH
EndIf
If by < y Then
belY= skipV
Else
belY= -skipV
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub LimitEnemy
If bx < szHFoe Then
bx= szHFoe
ElseIf bx > gw - szFoe Then
bx= gw - szFoe
EndIf
If by < szQFoe Then
by= szQFoe
ElseIf by > gh - szFoe Then
by= gh - szFoe
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub LethalCollision
If sizeX >= bx And x <= bx+szHFoe And sizeY >= by And y <= by+szHFoe Then
Timer.Pause()
Sound.PlayMusic("T180 O2P2P8 L8GGG L2E- P24P8 L8FFF L2D R")
GraphicsWindow.ShowMessage("Game Over" "Here Lies NyanCat!")
Billboard()
Reset()
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub GenerateBlaster
If ammo > 0 Then
cx= x + sizeH ' BlasterShot has the same coordinates and direction as Nyan's
cy= y + sizeQ
celX= delX*BlastSp ' Movement is 'BlastSp' times faster than Nyan's
celY= delY*BlastSp
Shapes.Move(blast cx,cy)
Shapes.ShowShape(blast)
Sound.PlayClick()
ammo= ammo - 1
Fired= "True
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub MoveBlaster
If Fired Then
cx= cx + celX
cy= cy + celY
OuttaRange()
Shapes.Move(blast cx,cy)
CheckImpact()
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub OuttaRange
If cx < 0 Or cx > gw Or cy < 0 Or cy > gh Then
ClearBlaster()
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub ClearBlaster
Shapes.HideShape(blast)
Fired= "False
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub CheckImpact
If cx+szBlast >= bx And cx <= bx+szHFoe And cy+szBlast >= by And cy <= by+szHFoe Then
ClearBlaster()
health= health - potency
Shapes.SetText(tough Math.Round(health))
CheckAnnihilation()
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub CheckAnnihilation
If health < 1 Then
kills= kills + 1
Sound.PlayMusic("T160 O1 L30 GF# FE# D# DC# D# DFE# R")
Shapes.SetText(destroy kills)
Shapes.HideShape(danger)
Shapes.HideShape(tough )
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub GenerateFood
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub CreateSuperFood
If BonusFood <> "True" And score > 0 And Math.Remainder(score 5) = 0 Then
GraphicsWindow.PenColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
foodXX= Math.GetRandomNumber(gw - szBonus)
foodYY= Math.GetRandomNumber(gh - szBonus)
bonus= Shapes.AddEllipse(szBonus,szBonus)
Shapes.Move(bonus foodXX,foodYY)
TmLimit= timing + TmBonus
BonusFood= "True
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub EraseSuperFood
If BonusFood Then
BonusFood= "False
Shapes.Remove(bonus)
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub InspectFoodsPlusAmmo
'If Math.Abs(x-foodX) <= szFood And Math.Abs(y-foodY) <= szFood Then
If sizeX >= foodX And x <= foodX+szHFood And sizeY >= foodY And y <= foodY+szHFood Then
score= score + 1
ammo= ammo + 1
Sound.PlayChimesAndWait()
GenerateFood()
Shapes.SetText(display score)
EndIf
If BonusFood And sizeX >= foodXX And x <= foodXX+szHBonus And sizeY >= foodYY And y <= foodYY+szHBonus Then
score= score + 3
ammo= ammo + 2
Sound.PlayBellRingAndWait()
EraseSuperFood()
Shapes.SetText(display score)
EndIf
If TmBonus > 0 And timing > TmLimit Then
EraseSuperFood()
EndIf
If ammo > ammoMax Then
ammo= ammoMax
EndIf
Shapes.SetText(weapon, ammo)
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Keyboard
Key= GraphicsWindow.LastKey
If Key = "Left" Or Key = "A" Then
Direction= 1
delX= -skip
delY= 0
ElseIf Key = "Right" Or Key = "D" Then
Direction= 2
delX= skip
delY= 0
ElseIf Key = "Down" Or Key = "S" Then
Direction= 3
delX= 0
delY= skip
ElseIf Key = "Up" Or Key = "W" Then
Direction= 4
delX= 0
delY= -skip
ElseIf Key = "Space" Or Key = "J" Then
GenerateBlaster()
ElseIf Key = "Escape" Then
Sound.PlayChimeAndWait()
Program.End()
ElseIf Key = "Home" Or Key = "Delete" Then
Clear()
ElseIf Key = "Tab" Then
GraphicsWindow.BackgroundColor= GraphicsWindow.GetRandomColor()
Clear()
CreateEnemyShapes()
ElseIf Key = "Back" Then
If RainBow Then
RainBow= "False
Else
RainBow= "True
EndIf
ElseIf Key = "Return" Then
If Running Then
Running= "False
Timer.Pause()
Else
Running= "True
Elapse()
Timer.Resume()
EndIf
EndIf
EndSub
' ----------------------------------------------------------------------------------------------------------------------------------------
Sub Elapse