summaryrefslogtreecommitdiff
path: root/gametypes.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'gametypes.bmx')
-rw-r--r--gametypes.bmx323
1 files changed, 307 insertions, 16 deletions
diff --git a/gametypes.bmx b/gametypes.bmx
index 4b0875a..caf9a24 100644
--- a/gametypes.bmx
+++ b/gametypes.bmx
@@ -23,51 +23,122 @@
Strict
Import noddybox.algorithm
Import "global.bmx"
+Import "particle.bmx"
+
+Const SHIP_TURN:Double=2
+Const SHIP_MAX_SPEED:Double=2.5
+Const SHIP_SPEED:Double=0.05
+Const SHIP_MIN_SPEED:Double=1
+
+Const MIN_TURN:Double=1
+Const MAX_TURN:Double=5.0
+Const MIN_SPEED:Double=1
+Const MAX_SPEED:Double=1.99
Type GameState
- Global score:Int=0
- Global x:Double=0
- Global y:Double=0
- Global ang:Int=0
- Global lives:Int=0
+ Global score:Int=0
+ Global x:Double=0
+ Global y:Double=0
+ Global ang:Double=0
+ Global speed:Double=SHIP_MIN_SPEED
+ Global lives:Int=3
+ Global level:Int=1
+ Global max_missile:Int=1
+ Global missile_turn:Double=0.5
+ Global missile_speed:Double=1
+ Global shield:Int=5*HERTZ
+ Global game_over:Int=False
+ Global hit:Int=False
Function Reset()
score=0
x=400
y=300
ang=0
+ speed=SHIP_MIN_SPEED
lives=3
+ SetLevel(1)
+ ShieldShip()
+ game_over=False
+ End Function
+
+ Function ShieldShip()
+ shield=5*HERTZ
+ End Function
+
+ Function ShieldDown()
+ lives:-1
+ hit=True
+ ShieldShip()
+ If lives<0 Then game_over=True
+ End Function
+
+ Function AddScore(s:Int)
+ score:+s
+ If score>GameConfig.hiscore
+ GameConfig.hiscore=score
+ EndIf
+ End Function
+
+ Function LevelUp()
+ SetLevel(level+1)
+ End Function
+
+ Function SetLevel(l:Int)
+ level=l
+ hit=False
+ max_missile=Min(50,l*2)
+ missile_turn=Min(MAX_TURN,MIN_TURN+Double(level)/4)
+ missile_speed=Min(MAX_SPEED,MIN_SPEED+Double(level)/4)
End Function
Function Control()
If KeyDown(GameConfig.kleft)
- ang:-2
- If ang<0 Then ang:+360
+ ang:-SHIP_TURN
End If
+
If KeyDown(GameConfig.kright)
- ang=(ang+2) Mod 360
+ ang:+SHIP_TURN
End If
+
+ If KeyDown(GameConfig.kthrust) And speed<=SHIP_MAX_SPEED
+ speed=Min(SHIP_MAX_SPEED,speed+SHIP_SPEED)
+ Else
+ speed=Max(SHIP_MIN_SPEED,speed-SHIP_SPEED/2)
+ End If
+
+ If KeyDown(GameConfig.kpause)
+ End If
+
+ If KeyHit(KEY_ESCAPE)
+ game_over=True
+ EndIf
End Function
Function Move()
- x=(x+Lookup.si[ang]*2) Mod 800
- y=(y-Lookup.co[ang]*2) Mod 600
+ x=(x+Sin(ang)*speed) Mod 800
+ y=(y-Cos(ang)*speed) Mod 600
If x<0 Then x:+800
If y<0 Then y:+600
Trail.Add()
+ If shield Then shield:-1
End Function
Function Display()
- Local s:String="LIVES "
+ Local s:String=""
For Local f:Int=1 To lives
s:+"~~"
Next
- GFX.font.Draw("SCORE",0,-0)
+ GFX.font.Draw("SCORE",0,0)
GFX.font.Draw(Number.Format(score),0,16,255,255,0)
- GFX.font.Centre(s,0)
+ GFX.font.Centre("SHIELDS",0)
+ GFX.font.Centre(s,16)
+
+ GFX.font.Draw("LEVEL " + level,0,584)
+ GFX.font.Draw("MISSILES " + MissileSet.Count(),623,584)
GFX.font.DrawRight("HISCORE",799,0)
GFX.font.DrawRight(Number.Format(GameConfig.hiscore),799,16,255,255,0)
@@ -93,18 +164,19 @@ End Type
Type Backdrop
+ Const NUM:Int=100
Global s:BackdropStar[]
Function Init()
- s=New BackdropStar[400]
+ s=New BackdropStar[NUM]
- For Local f:Int=0 To 399
+ For Local f:Int=0 Until NUM
s[f]=New BackdropStar
Next
End Function
Function Draw()
- For Local f:Int=0 To 399
+ For Local f:Int=0 Until NUM
SetColor(s[f].r,s[f].g,s[f].b)
DrawImage(GFX.star,s[f].x,s[f].y)
Next
@@ -167,3 +239,222 @@ Type Trail
SetScale(1,1)
End Function
End Type
+
+Type Missile
+ Field x:Double
+ Field y:Double
+ Field ang:Double
+ Field onscreen:Int
+ Field turn:Double
+ Field speed:Double
+
+ Method New()
+ Select Rand(1,4)
+ Case 1
+ x=Rand(0,800)
+ y=Rand(-100,0)
+ ang=180
+ Case 2
+ x=Rand(0,800)
+ y=Rand(600,700)
+ ang=0
+ Case 3
+ y=Rand(0,600)
+ x=Rand(-100,0)
+ ang=90
+ Case 4
+ y=Rand(0,600)
+ x=Rand(800,900)
+ ang=270
+ End Select
+ speed=Rnd(Max(MIN_SPEED,GameState.missile_speed-0.1),GameState.missile_speed)
+ turn=Rnd(Max(MIN_TURN,GameState.missile_turn-0.1),GameState.missile_turn)
+ onscreen=False
+ End Method
+
+ Method Update()
+ If onscreen
+ Local a:Double=ATan2(GameState.x-x,y-GameState.y)
+
+ If a<0 Then a:+360
+
+ a:-ang
+
+ If a<0
+ If a>-180
+ ang:-turn
+ Else
+ ang:+turn
+ EndIf
+ ElseIf a>0
+ If a>180
+ ang:-turn
+ Else
+ ang:+turn
+ EndIf
+ EndIf
+
+ ang=ang Mod 360
+ If ang<0 Then ang:+360
+ EndIf
+
+ SetRotation(ang)
+ x:+Sin(ang)*speed
+ y:-Cos(ang)*speed
+ DrawImage(GFX.missile,x,y)
+ CollideImage(GFX.missile,x,y,0,0,MISSILE_LAYER,Self)
+
+ If onscreen
+ x=x Mod 800
+ y=y Mod 600
+ If x<0 Then x:+800
+ If y<0 Then y:+600
+ Else
+ onscreen=(x>=0 And x<800 And y>=0 And y<600)
+ EndIf
+ End Method
+End Type
+
+Type MissileSet
+ Global plist:TList
+ Global create:Int
+ Global wait:Int
+
+ Function Init()
+ plist=CreateList()
+ create=0
+ End Function
+
+ Function StartLevel()
+ plist.Clear()
+ create=GameState.max_missile
+ wait=HERTZ
+ End Function
+
+ Function Count:Int()
+ Return plist.Count()
+ End Function
+
+ Function Update()
+ If wait=0
+ If create
+ plist.AddLast(New Missile)
+ create:-1
+ EndIf
+ wait=HERTZ
+ Else
+ wait:-1
+ EndIf
+
+ SetColor(255,255,255)
+
+ For Local m:Missile=EachIn plist
+ m.Update()
+ Next
+
+ SetRotation(0)
+ End Function
+
+ Function Nuke:Int()
+ Local c:Int=plist.Count()
+ For Local m:Missile=EachIn plist
+ Particles.AddExplosion(m.x,m.y)
+ Next
+ plist.Clear()
+ Return c
+ End Function
+
+ Function RemoveMissile(m:Missile)
+ plist.Remove(m)
+ End Function
+
+ Function AllDestroyed:Int()
+ Return (create=0 And plist.Count()=0)
+ End Function
+End Type
+
+
+Type Asteroid
+ Field x:Double
+ Field y:Double
+ Field dx:Double
+ Field dy:Double
+ Field ang:Double
+ Field angi:Double
+
+ Method New()
+ x=Rand(20,780)
+ y=Rand(20,580)
+ Repeat
+ dx=Rnd(-1,1)
+ dy=Rnd(-1,1)
+ Until dx<>0 And dy<>0
+
+ ang=Rand(360)
+
+ If Abs(dx)>Abs(dy)
+ angi=dx/2
+ Else
+ angi=dy/2
+ EndIf
+ End Method
+
+ Method Update()
+ ang:+angi
+ x=(x+dx) Mod 800
+ y=(y+dy) Mod 600
+ If x<0 Then x:+800
+ If y<0 Then y:+600
+ SetRotation(ang)
+ DrawImage(GFX.asteroid,x,y)
+ Local o:Object[]=CollideImage(GFX.asteroid,x,y,0,MISSILE_LAYER,ASTEROID_LAYER,Self)
+
+ If o
+ Particles.AddBigExplosion(x,y)
+ GameState.AddScore(10*GameState.level)
+ MissileSet.RemoveMissile(Missile(o[0]))
+ Return False
+ Else
+ Return True
+ EndIf
+ End Method
+End Type
+
+Type AsteroidSet
+ Global plist:TList
+
+ Function Init()
+ plist=CreateList()
+ End Function
+
+ Function StartLevel()
+ plist.Clear()
+ For Local f:Int=0 Until Max(5,GameState.max_missile)
+ plist.AddLast(New Asteroid)
+ Next
+ End Function
+
+ Function Update()
+ Local l:TEasyLink=TEasyLink.Create(plist)
+
+ While l.Value()
+ Local a:Asteroid=Asteroid(l.Value())
+
+ If (a.Update())
+ l.MoveNext()
+ Else
+ l.Remove()
+ EndIf
+ Wend
+ SetRotation(0)
+ End Function
+
+ Function Nuke()
+ Local c:Int=plist.Count()
+ For Local a:Asteroid=EachIn plist
+ Particles.AddExplosion(a.x,a.y)
+ Next
+ plist.Clear()
+ Return c
+ End Function
+End Type