summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.bmx741
-rw-r--r--hiscore.bmx391
-rw-r--r--sounds.bmx257
-rw-r--r--vectoroids.bmx411
4 files changed, 933 insertions, 867 deletions
diff --git a/game.bmx b/game.bmx
index 29ebd9d..8b88300 100644
--- a/game.bmx
+++ b/game.bmx
@@ -1,347 +1,394 @@
-' Vectoroids
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-Import noddybox.vector
-Import noddybox.bitmapfont
-Import noddybox.vectorgfx
-Import "types.bmx"
-Import "sounds.bmx"
-
-Type TGame
-
- Field score:Int
- Field astlist:TList
- Field bullets:TList
- Field lives:Int
- Field ship:TVectorGfxObject
- Field lifeship:TVectorGfxObject
- Field shotdelay:Int
- Field deaddelay:Int
- Field x:Double
- Field y:Double
- Field dx:Double
- Field dy:Double
- Field waiting:Int
- Field freq:Int
- Field hit:Int
- Field hyperdelay:Int
- Field waitdelay:Int
- Field leveldelay:Int
- Field minspeed:Double
- Field maxspeed:Double
- Field numast:Int
- Field extralife:Int
- Field saucerdelay:Int
- Field saucertime:Int
- Field saucershot:Int
- Field saucer:TSaucer
-
- Method New()
- score=0
- astlist=CreateList()
- bullets=CreateList()
- lives=2
- ship=GameGFX.ship.Clone()
- lifeship=GameGFX.ship.Clone()
- deaddelay=250
- waiting=True
- waitdelay=500
- x=GraphicsWidth()/2
- y=GraphicsHeight()/2
- dx=0
- dy=0
- ship.ang=0
- ship.x=x
- ship.y=y
- leveldelay=0
- extralife=10000
-
- lifeship.y=5
- lifeship.scale=0.5
-
- minspeed=0.1
- maxspeed=1.0
- numast=5
-
- saucertime=120*50
- saucerdelay=0
- saucershot=150
-
- NewLevel()
- End Method
-
- Method NewLevel()
- TAsteroid.minspeed=minspeed
- TAsteroid.maxspeed=maxspeed
- For Local f:Int=0 Until numast
- astlist.AddLast(TAsteroid.Create())
- Next
- freq=30
- hit=0
- bullets.Clear()
- shotdelay=0
- hyperdelay=0
- End Method
-
- Method CheckShipLaunch()
- Local x1:Int=GraphicsWidth()/2-100
- Local y1:Int=GraphicsHeight()/2-100
- Local x2:Int=GraphicsWidth()/2+100
- Local y2:Int=GraphicsHeight()/2+100
-
- If waitdelay=0 Or KeyHit(GameConfig.khyper)
- FlushKeys()
- waiting=False
- EndIf
-
- waitdelay:-1
-
- For Local a:TAsteroid=EachIn astlist
- If saucer Or (a.x>x1 And a.x<x2 And a.y>y1 And a.y<y2)
- SetAlpha(0.7-Float(waitdelay)/1000.0)
- ship.Draw()
- SetColor(255,0,0)
- DrawLine(x1,y1,x2,y1)
- DrawLine(x2,y1,x2,y2)
- DrawLine(x2,y2,x1,y2)
- DrawLine(x1,y2,x1,y1)
- SetColor(255,255,255)
- SetAlpha(1)
-
- GameGFX.font.Centre("press hyperspace to launch early",150)
-
- Return
- EndIf
- Next
-
- waiting=False
- End Method
-
- Method Play:Int()
- Cls
-
- If waiting And lives>=0
- CheckShipLaunch()
- EndIf
-
- If astlist.Count()=0
- If leveldelay=0
- leveldelay=200
- Else
- leveldelay:-1
- If leveldelay=0
- numast=Min(20,numast+2)
- minspeed=Min(0.5,minspeed+0.05)
- maxspeed=Min(2.0,maxspeed+0.05)
- saucertime=Max(10,saucertime-20)
- saucershot=Max(25,saucershot-10)
- NewLevel()
- EndIf
- EndIf
- EndIf
-
- If lives>-1 And saucer=Null
- saucerdelay:+1
-
- If saucerdelay>saucertime
- saucerdelay=0
- If score<10000
- saucer=TSaucer.Create(True,saucershot)
- ElseIf score<20000
- saucer=TSaucer.Create(Rand(0,1),saucershot)
- Else
- saucer=TSaucer.Create(False,saucershot)
- EndIf
- EndIf
- EndIf
-
-
- If lives>-1 And Not waiting
- If KeyDown(GameConfig.kleft)
- ship.ang:-20
- If ship.ang<0
- ship.ang:+3600
- EndIf
- EndIf
-
- If KeyDown(GameConfig.kright)
- ship.ang=(ship.ang+20) Mod 3600
- EndIf
-
- If KeyDown(GameConfig.kthrust)
- Sounds.PlayerThrust(True)
- dx=Min(2,Max(-2,dx+Lookup.si[ship.ang]*0.1))
- dy=Min(2,Max(-2,dy+Lookup.co[ship.ang]*0.1))
- Else
- Sounds.PlayerThrust(False)
- EndIf
-
- If KeyDown(GameConfig.khyper) And hyperdelay=0
- x=Rand(10,GraphicsWidth()-10)
- y=Rand(10,GraphicsHeight()-10)
- dx=0
- dy=0
- hyperdelay=100
- EndIf
-
- If KeyDown(GameConfig.kfire) And shotdelay=0
- Sounds.PlayerFire()
- bullets.AddLast(TShot.Create(ship))
- shotdelay=25
- EndIf
-
- If shotdelay>0
- shotdelay:-1
- EndIf
-
- If hyperdelay>0
- hyperdelay:-1
- EndIf
-
- If KeyHit(KEY_ESCAPE)
- lives=-1
- TParticleMachine.AsteroidExplosion(ship.x,ship.y)
- Sounds.ShipExplosion()
- EndIf
-
- x:+dx
- y:+dy
-
- If x<0
- x:+GraphicsWidth()
- EndIf
-
- If x>=GraphicsWidth()
- x:-GraphicsWidth()
- EndIf
-
- If y<0
- y:+GraphicsHeight()
- EndIf
-
- If y>=GraphicsHeight()
- y:-GraphicsHeight()
- EndIf
-
- ship.x=x
- ship.y=y
- EndIf
-
- SetAlpha(0.7)
-
- For Local a:TAsteroid=EachIn astlist
- a.Update()
- Next
-
- For Local f:Int=1 To lives
- lifeship.x=f*9
- lifeship.Draw()
- Next
-
- SetAlpha(1)
-
- GameGFX.font.Centre(score,0)
- SetColor(255,255,255)
- If lives<0
- For Local s:TShot=EachIn bullets
- s.Update(bullets,astlist,saucer)
- Next
- Else
- For Local s:TShot=EachIn bullets
- Local sc:Int=s.Update(bullets,astlist,saucer)
- score:+sc
-
- If sc
- If score>extralife
- If extralife=10000
- extralife=50000
- Else
- extralife:+50000
- EndIf
- lives:+1
- Sounds.ExtraLife()
- EndIf
-
- hit:+1
- If hit>3
- hit=0
- If freq>15
- freq:-1
- EndIf
- EndIf
- EndIf
- Next
- EndIf
-
- Local hit:Int=False
-
- If saucer
- SetAlpha(0.7)
- If lives>-1 And Not waiting
- hit=saucer.Update(ship)
- Else
- saucer.Update(Null)
- EndIf
-
- SetAlpha(1)
-
- If saucer.Finished()
- saucer=Null
- Sounds.NoSaucer()
- EndIf
- EndIf
-
- If lives<0
- deaddelay:-1
- GameGFX.font.Centre("game over",292)
- Else
- If Not waiting
- SetAlpha(0.7)
-
- If hit Or Collides(ship.DrawToPointList())
- TParticleMachine.ShipExplosion(ship.x,ship.y)
- Sounds.ShipExplosion()
-
- lives:-1
- x=GraphicsWidth()/2
- y=GraphicsHeight()/2
- dx=0
- dy=0
- ship.ang=0
- ship.x=x
- ship.y=y
- waiting=True
- waitdelay=500
- FlushKeys()
- EndIf
-
- SetAlpha(1)
- EndIf
- EndIf
-
- TParticleMachine.Process()
- Sounds.Update(freq)
-
- FlushMem
- Flip
-
- Return deaddelay>0
- End Method
-
- Method Collides:Int(list:TList)
- For Local a:TAsteroid=EachIn astlist
- For Local p:TVectorGfxPoint=EachIn list
- If a.obj.IsInside(p.x,p.y)
- Return True
- EndIf
- Next
- Next
-
- Return False
- End Method
-
-End Type
+' Vectoroids
+'
+' Copyright 2005 Ian Cowburn
+'
+' $Id$
+'
+Strict
+Import noddybox.vector
+Import noddybox.bitmapfont
+Import noddybox.vectorgfx
+Import "types.bmx"
+Import "sounds.bmx"
+
+Type TGame
+
+ Field score:Int
+ Field astlist:TList
+ Field bullets:TList
+ Field lives:Int
+ Field ship:TVectorGfxObject
+ Field lifeship:TVectorGfxObject
+ Field shotdelay:Int
+ Field deaddelay:Int
+ Field x:Double
+ Field y:Double
+ Field dx:Double
+ Field dy:Double
+ Field waiting:Int
+ Field freq:Int
+ Field hit:Int
+ Field hyperdelay:Int
+ Field waitdelay:Int
+ Field leveldelay:Int
+ Field minspeed:Double
+ Field maxspeed:Double
+ Field numast:Int
+ Field extralife:Int
+ Field saucerdelay:Int
+ Field saucertime:Int
+ Field saucershot:Int
+ Field saucer:TSaucer
+
+ Method New()
+ score=0
+ astlist=CreateList()
+ bullets=CreateList()
+ lives=2
+ ship=GameGFX.ship.Clone()
+ lifeship=GameGFX.ship.Clone()
+ deaddelay=250
+ waiting=True
+ waitdelay=500
+ x=GraphicsWidth()/2
+ y=GraphicsHeight()/2
+ dx=0
+ dy=0
+ ship.ang=0
+ ship.x=x
+ ship.y=y
+ leveldelay=0
+ extralife=10000
+
+ lifeship.y=5
+ lifeship.scale=0.5
+
+ minspeed=0.1
+ maxspeed=1.0
+ numast=5
+
+ saucertime=120*50
+ saucerdelay=0
+ saucershot=150
+
+ NewLevel()
+ End Method
+
+ Method NewLevel()
+ TAsteroid.minspeed=minspeed
+ TAsteroid.maxspeed=maxspeed
+ For Local f:Int=0 Until numast
+ astlist.AddLast(TAsteroid.Create())
+ Next
+ freq=30
+ hit=0
+ bullets.Clear()
+ shotdelay=0
+ hyperdelay=0
+ End Method
+
+ Method CheckShipLaunch()
+ Local x1:Int=GraphicsWidth()/2-100
+ Local y1:Int=GraphicsHeight()/2-100
+ Local x2:Int=GraphicsWidth()/2+100
+ Local y2:Int=GraphicsHeight()/2+100
+
+ If waitdelay=0 Or KeyHit(GameConfig.khyper)
+ FlushKeys()
+ waiting=False
+ EndIf
+
+ waitdelay:-1
+
+ For Local a:TAsteroid=EachIn astlist
+ If saucer Or (a.x>x1 And a.x<x2 And a.y>y1 And a.y<y2)
+ SetAlpha(0.7-Float(waitdelay)/1000.0)
+ ship.Draw()
+ SetColor(255,0,0)
+ DrawLine(x1,y1,x2,y1)
+ DrawLine(x2,y1,x2,y2)
+ DrawLine(x2,y2,x1,y2)
+ DrawLine(x1,y2,x1,y1)
+ SetColor(255,255,255)
+ SetAlpha(1)
+
+ GameGFX.font.Centre("press hyperspace to launch early",150)
+
+ Return
+ EndIf
+ Next
+
+ waiting=False
+ End Method
+
+ Method Pause()
+ Local i:Timage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,MASKEDIMAGE|DYNAMICIMAGE|FILTEREDIMAGE)
+
+ GrabImage(i,0,0)
+ MidHandleImage(i)
+
+ Local a:Int[]=[0,0,0,0,0,0,0,0]
+ Local ac:Int[]=[7,6,5,4,3,2,1,0]
+
+ Sounds.Pause()
+
+ While Not KeyHit(GameConfig.kpause)
+ Cls
+
+ Local al:Double=0.3
+
+ For Local f:Int=0 Until a.length
+ SetAlpha(al)
+ SetRotation(a[f])
+ SetScale(al,al)
+ DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2)
+ If ac[f]>0
+ ac[f]:-1
+ Else
+ a[f]:+1
+ EndIf
+ al:+0.1
+ Next
+
+ SetRotation(0)
+ SetScale(1,1)
+ GameGFX.font.Centre("paused",GraphicsHeight()/2-16)
+
+ Flip
+ Wend
+
+ SetAlpha(1)
+ SetRotation(0)
+ SetScale(1,1)
+
+ FlushKeys
+ Sounds.EndPause()
+ End Method
+
+ Method Play:Int()
+ Cls
+
+ If waiting And lives>=0
+ CheckShipLaunch()
+ EndIf
+
+ If astlist.Count()=0
+ If leveldelay=0
+ leveldelay=200
+ Else
+ leveldelay:-1
+ If leveldelay=0
+ numast=Min(20,numast+2)
+ minspeed=Min(0.5,minspeed+0.05)
+ maxspeed=Min(2.0,maxspeed+0.05)
+ saucertime=Max(10,saucertime-20)
+ saucershot=Max(25,saucershot-10)
+ NewLevel()
+ EndIf
+ EndIf
+ EndIf
+
+ If lives>-1 And saucer=Null
+ saucerdelay:+1
+
+ If saucerdelay>saucertime
+ saucerdelay=0
+ If score<10000
+ saucer=TSaucer.Create(True,saucershot)
+ ElseIf score<20000
+ saucer=TSaucer.Create(Rand(0,1),saucershot)
+ Else
+ saucer=TSaucer.Create(False,saucershot)
+ EndIf
+ EndIf
+ EndIf
+
+
+ If lives>-1 And Not waiting
+ If KeyDown(GameConfig.kleft)
+ ship.ang:-20
+ If ship.ang<0
+ ship.ang:+3600
+ EndIf
+ EndIf
+
+ If KeyDown(GameConfig.kright)
+ ship.ang=(ship.ang+20) Mod 3600
+ EndIf
+
+ If KeyDown(GameConfig.kthrust)
+ Sounds.PlayerThrust(True)
+ dx=Min(2,Max(-2,dx+Lookup.si[ship.ang]*0.1))
+ dy=Min(2,Max(-2,dy+Lookup.co[ship.ang]*0.1))
+ Else
+ Sounds.PlayerThrust(False)
+ EndIf
+
+ If KeyDown(GameConfig.khyper) And hyperdelay=0
+ x=Rand(10,GraphicsWidth()-10)
+ y=Rand(10,GraphicsHeight()-10)
+ dx=0
+ dy=0
+ hyperdelay=100
+ EndIf
+
+ If KeyDown(GameConfig.kfire) And shotdelay=0
+ Sounds.PlayerFire()
+ bullets.AddLast(TShot.Create(ship))
+ shotdelay=25
+ EndIf
+
+ If shotdelay>0
+ shotdelay:-1
+ EndIf
+
+ If hyperdelay>0
+ hyperdelay:-1
+ EndIf
+
+ If KeyHit(KEY_ESCAPE)
+ lives=-1
+ TParticleMachine.AsteroidExplosion(ship.x,ship.y)
+ Sounds.ShipExplosion()
+ EndIf
+
+ x:+dx
+ y:+dy
+
+ If x<0
+ x:+GraphicsWidth()
+ EndIf
+
+ If x>=GraphicsWidth()
+ x:-GraphicsWidth()
+ EndIf
+
+ If y<0
+ y:+GraphicsHeight()
+ EndIf
+
+ If y>=GraphicsHeight()
+ y:-GraphicsHeight()
+ EndIf
+
+ ship.x=x
+ ship.y=y
+ EndIf
+
+ SetAlpha(0.7)
+
+ For Local a:TAsteroid=EachIn astlist
+ a.Update()
+ Next
+
+ For Local f:Int=1 To lives
+ lifeship.x=f*9
+ lifeship.Draw()
+ Next
+
+ SetAlpha(1)
+
+ GameGFX.font.Centre(score,0)
+ SetColor(255,255,255)
+ If lives<0
+ For Local s:TShot=EachIn bullets
+ s.Update(bullets,astlist,saucer)
+ Next
+ Else
+ For Local s:TShot=EachIn bullets
+ Local sc:Int=s.Update(bullets,astlist,saucer)
+ score:+sc
+
+ If sc
+ If score>extralife
+ If extralife=10000
+ extralife=50000
+ Else
+ extralife:+50000
+ EndIf
+ lives:+1
+ Sounds.ExtraLife()
+ EndIf
+
+ hit:+1
+ If hit>3
+ hit=0
+ If freq>15
+ freq:-1
+ EndIf
+ EndIf
+ EndIf
+ Next
+ EndIf
+
+ Local hit:Int=False
+
+ If saucer
+ SetAlpha(0.7)
+ If lives>-1 And Not waiting
+ hit=saucer.Update(ship)
+ Else
+ saucer.Update(Null)
+ EndIf
+
+ SetAlpha(1)
+
+ If saucer.Finished()
+ saucer=Null
+ Sounds.NoSaucer()
+ EndIf
+ EndIf
+
+ If lives<0
+ deaddelay:-1
+ GameGFX.font.Centre("game over",292)
+ Else
+ If Not waiting
+ SetAlpha(0.7)
+
+ If hit Or Collides(ship.DrawToPointList())
+ TParticleMachine.ShipExplosion(ship.x,ship.y)
+ Sounds.ShipExplosion()
+
+ lives:-1
+ x=GraphicsWidth()/2
+ y=GraphicsHeight()/2
+ dx=0
+ dy=0
+ ship.ang=0
+ ship.x=x
+ ship.y=y
+ waiting=True
+ waitdelay=500
+ FlushKeys()
+ EndIf
+
+ SetAlpha(1)
+ EndIf
+ EndIf
+
+ TParticleMachine.Process()
+ Sounds.Update(freq)
+
+ Flip
+
+ If KeyHit(GameConfig.kpause)
+ Pause()
+ EndIf
+
+ Return deaddelay>0
+ End Method
+
+ Method Collides:Int(list:TList)
+ For Local a:TAsteroid=EachIn astlist
+ For Local p:TVectorGfxPoint=EachIn list
+ If a.obj.IsInside(p.x,p.y)
+ Return True
+ EndIf
+ Next
+ Next
+
+ Return False
+ End Method
+
+End Type
diff --git a/hiscore.bmx b/hiscore.bmx
index 5c4311b..ce18e01 100644
--- a/hiscore.bmx
+++ b/hiscore.bmx
@@ -1,196 +1,195 @@
-' Vectoroids
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-Import "types.bmx"
-
-Type THiscore
-
- Const NUM:Int=5
- Field score:THiscoreEnt[]
- Field col:Int[]
- Field coli:Int[]
-
- Function Load:THiscore()
- Local o:THiscore=New THiscore
-
- o.score=New THiscoreEnt[NUM]
- o.col=New Int[NUM]
- o.coli=New Int[NUM]
-
- For Local f:Int=0 Until NUM
- o.col[f]=254-f*20
- o.coli[f]=1
- Next
-
- Local s:TStream=ReadStream("vectoroids.hiscore")
-
- If s=Null
- For Local f:Int=0 Until NUM
- o.score[f]=THiscoreEnt.Create("SV",10000-f*2000)
- Next
- Else
- s=LittleEndianStream(s)
-
- For Local f:Int=0 Until NUM
- Local sc:Int=s.ReadInt()
- Local n:String=s.ReadLine()
- o.score[f]=THiscoreEnt.Create(n,sc)
- Next
-
- s.Close()
- EndIf
-
- Return o
- End Function
-
- Method Save()
- Local s:TStream=WriteStream("vectoroids.hiscore")
-
- If s=Null
- Return
- EndIf
-
- s=LittleEndianStream(s)
-
- For Local sc:THiscoreEnt=EachIn score
- s.WriteInt(sc.score)
- s.WriteLine(sc.name)
- Next
-
- s.Close()
- End Method
-
- Method Display(y:Int)
- GameGFX.font.Centre("ALL TIME HIGH SCORES",y)
- y:+20
-
- For Local f:Int=0 Until NUM
- GameGFX.font.DrawColoured(score[f].name,300,y,col[f],col[f],col[f])
- Local l:Int=GameGFX.font.TextWidth(score[f].score)
- GameGFX.font.DrawColoured(score[f].score,500-l,y,col[f],col[f],col[f])
- y:+10
- col[f]:+coli[f]
-
- If col[f]=255 Or col[f]=150
- coli[f]=-coli[f]
- EndIf
- Next
- End Method
-
- Method Check(sc:Int)
- If sc<score[NUM-1].score
- Return
- EndIf
-
- Local done:Int=False
- Local a:String="abcdefghijklmnopqrstuvwxyz{}"
- Local cur:Int=0
- Local nm:String=""
- Local last:Int=0
- Local del:Int=0
- Local tx:Int=GraphicsWidth()/2-GameGFX.font.TextWidth("___")
- Local press:Int=False
-
- While Not done
- Cls
-
- GameGFX.font.Centre("enter your name for",0)
- GameGFX.font.Centre("the hall of fame",20)
-
- SetScale(2,2)
- GameGFX.font.Draw("___",tx,300)
- GameGFX.font.Draw(nm+a[cur..cur+1],tx,300)
- SetScale(1,1)
-
- If del
- del:-1
- EndIf
-
- If KeyDown(GameConfig.kleft)
- If last<>GameConfig.kleft Or del=0
- If last=GameConfig.kleft
- del=5
- Else
- del=20
- EndIf
- last=GameConfig.kleft
- cur:-1
- If cur<0
- cur:+a.length
- EndIf
- EndIf
- press=True
- ElseIf KeyDown(GameConfig.kright)
- If last<>GameConfig.kright Or del=0
- If last=GameConfig.kright
- del=5
- Else
- del=20
- EndIf
- last=GameConfig.kright
- cur:+1
- If cur=a.length
- cur=0
- EndIf
- EndIf
- press=True
- Else
- press=False
- last=0
- del=0
- EndIf
-
- If KeyHit(GameConfig.khyper)
- Local c:String=a[cur..cur+1]
-
- If c="{"
- If nm.length>1
- nm=nm[0..nm.length-1]
- ElseIf nm.length=1
- nm=""
- EndIf
- Else If c="}"
- done=True
- Else
- nm:+c
- If nm.length=3
- done=True
- EndIf
- EndIf
- EndIf
-
- Flip
- FlushMem
- Wend
-
- score[NUM-1]=THiscoreEnt.Create(nm.ToUpper(),sc)
- score.Sort()
- Save()
- End Method
-End Type
-
-Type THiscoreEnt
- Field score:Int
- Field name:String
-
- Function Create:THiscoreEnt(name:String, score:Int)
- Local o:THiscoreEnt=New THiscoreEnt
- o.score=score
- o.name=name
- Return o
- End Function
-
- Method Compare(o:Object)
- Local os:THiscoreEnt=THiscoreEnt(o)
-
- If os
- Return os.score-score
- Else
- Return 0
- EndIf
- End Method
-End Type
+' Vectoroids
+'
+' Copyright 2005 Ian Cowburn
+'
+' $Id$
+'
+Strict
+Import "types.bmx"
+
+Type THiscore
+
+ Const NUM:Int=5
+ Field score:THiscoreEnt[]
+ Field col:Int[]
+ Field coli:Int[]
+
+ Function Load:THiscore()
+ Local o:THiscore=New THiscore
+
+ o.score=New THiscoreEnt[NUM]
+ o.col=New Int[NUM]
+ o.coli=New Int[NUM]
+
+ For Local f:Int=0 Until NUM
+ o.col[f]=254-f*20
+ o.coli[f]=1
+ Next
+
+ Local s:TStream=ReadStream("vectoroids.hiscore")
+
+ If s=Null
+ For Local f:Int=0 Until NUM
+ o.score[f]=THiscoreEnt.Create("SV",10000-f*2000)
+ Next
+ Else
+ s=LittleEndianStream(s)
+
+ For Local f:Int=0 Until NUM
+ Local sc:Int=s.ReadInt()
+ Local n:String=s.ReadLine()
+ o.score[f]=THiscoreEnt.Create(n,sc)
+ Next
+
+ s.Close()
+ EndIf
+
+ Return o
+ End Function
+
+ Method Save()
+ Local s:TStream=WriteStream("vectoroids.hiscore")
+
+ If s=Null
+ Return
+ EndIf
+
+ s=LittleEndianStream(s)
+
+ For Local sc:THiscoreEnt=EachIn score
+ s.WriteInt(sc.score)
+ s.WriteLine(sc.name)
+ Next
+
+ s.Close()
+ End Method
+
+ Method Display(y:Int)
+ GameGFX.font.Centre("ALL TIME HIGH SCORES",y)
+ y:+20
+
+ For Local f:Int=0 Until NUM
+ GameGFX.font.DrawColoured(score[f].name,300,y,col[f],col[f],col[f])
+ Local l:Int=GameGFX.font.TextWidth(score[f].score)
+ GameGFX.font.DrawColoured(score[f].score,500-l,y,col[f],col[f],col[f])
+ y:+10
+ col[f]:+coli[f]
+
+ If col[f]=255 Or col[f]=150
+ coli[f]=-coli[f]
+ EndIf
+ Next
+ End Method
+
+ Method Check(sc:Int)
+ If sc<score[NUM-1].score
+ Return
+ EndIf
+
+ Local done:Int=False
+ Local a:String="abcdefghijklmnopqrstuvwxyz{}"
+ Local cur:Int=0
+ Local nm:String=""
+ Local last:Int=0
+ Local del:Int=0
+ Local tx:Int=GraphicsWidth()/2-GameGFX.font.TextWidth("___")
+ Local press:Int=False
+
+ While Not done
+ Cls
+
+ GameGFX.font.Centre("enter your name for",0)
+ GameGFX.font.Centre("the hall of fame",20)
+
+ SetScale(2,2)
+ GameGFX.font.Draw("___",tx,300)
+ GameGFX.font.Draw(nm+a[cur..cur+1],tx,300)
+ SetScale(1,1)
+
+ If del
+ del:-1
+ EndIf
+
+ If KeyDown(GameConfig.kleft)
+ If last<>GameConfig.kleft Or del=0
+ If last=GameConfig.kleft
+ del=5
+ Else
+ del=20
+ EndIf
+ last=GameConfig.kleft
+ cur:-1
+ If cur<0
+ cur:+a.length
+ EndIf
+ EndIf
+ press=True
+ ElseIf KeyDown(GameConfig.kright)
+ If last<>GameConfig.kright Or del=0
+ If last=GameConfig.kright
+ del=5
+ Else
+ del=20
+ EndIf
+ last=GameConfig.kright
+ cur:+1
+ If cur=a.length
+ cur=0
+ EndIf
+ EndIf
+ press=True
+ Else
+ press=False
+ last=0
+ del=0
+ EndIf
+
+ If KeyHit(GameConfig.khyper)
+ Local c:String=a[cur..cur+1]
+
+ If c="{"
+ If nm.length>1
+ nm=nm[0..nm.length-1]
+ ElseIf nm.length=1
+ nm=""
+ EndIf
+ Else If c="}"
+ done=True
+ Else
+ nm:+c
+ If nm.length=3
+ done=True
+ EndIf
+ EndIf
+ EndIf
+
+ Flip
+ Wend
+
+ score[NUM-1]=THiscoreEnt.Create(nm.ToUpper(),sc)
+ score.Sort()
+ Save()
+ End Method
+End Type
+
+Type THiscoreEnt
+ Field score:Int
+ Field name:String
+
+ Function Create:THiscoreEnt(name:String, score:Int)
+ Local o:THiscoreEnt=New THiscoreEnt
+ o.score=score
+ o.name=name
+ Return o
+ End Function
+
+ Method Compare(o:Object)
+ Local os:THiscoreEnt=THiscoreEnt(o)
+
+ If os
+ Return os.score-score
+ Else
+ Return 0
+ EndIf
+ End Method
+End Type
diff --git a/sounds.bmx b/sounds.bmx
index c0bdf5d..1c7ffe0 100644
--- a/sounds.bmx
+++ b/sounds.bmx
@@ -1,118 +1,139 @@
-' Vectoroids
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-
-Incbin "SFX/explode1.wav"
-Incbin "SFX/explode2.wav"
-Incbin "SFX/explode3.wav"
-Incbin "SFX/fire.wav"
-Incbin "SFX/life.wav"
-Incbin "SFX/lsaucer.wav"
-Incbin "SFX/sfire.wav"
-Incbin "SFX/ssaucer.wav"
-Incbin "SFX/thrust.wav"
-Incbin "SFX/thumphi.wav"
-Incbin "SFX/thumplo.wav"
-
-
-Type Sounds
- Global explode:TSound[]
- Global fire:TSound
- Global life:TSound
- Global lsaucer:TSound
- Global sfire:TSound
- Global ssaucer:TSound
- Global thrust:TSound
- Global thumphi:TSound
- Global thumplo:TSound
-
- Global thrust_channel:TChannel
- Global ssaucer_channel:TChannel
- Global lsaucer_channel:TChannel
-
- Global frame:Int
- Global hi:Int
-
- Function Init()
- explode=New TSound[3]
- explode[2]=LoadSound("incbin::SFX/explode1.wav")
- explode[1]=LoadSound("incbin::SFX/explode2.wav")
- explode[0]=LoadSound("incbin::SFX/explode3.wav")
- fire=LoadSound("incbin::SFX/fire.wav")
- life=LoadSound("incbin::SFX/life.wav")
- lsaucer=LoadSound("incbin::SFX/lsaucer.wav",True)
- sfire=LoadSound("incbin::SFX/sfire.wav")
- ssaucer=LoadSound("incbin::SFX/ssaucer.wav",True)
- thrust=LoadSound("incbin::SFX/thrust.wav",True)
- thumplo=LoadSound("incbin::SFX/thumplo.wav")
- thumphi=LoadSound("incbin::SFX/thumphi.wav")
-
- frame=0
- hi=True
-
- thrust_channel=thrust.Cue()
- ssaucer_channel=ssaucer.Cue()
- lsaucer_channel=lsaucer.Cue()
- End Function
-
- Function Update(freq:Int)
- If frame>freq
- frame=0
-
- If hi
- thumphi.Play()
- Else
- thumplo.Play()
- EndIf
-
- hi=Not hi
- EndIf
- frame:+1
- End Function
-
- Function AsteroidExplosion(size:Int)
- explode[size].Play()
- End Function
-
- Function ShipExplosion()
- explode[0].Play()
- End Function
-
- Function PlayerFire()
- fire.Play()
- End Function
-
- Function SaucerFire()
- sfire.Play()
- End Function
-
- Function ExtraLife()
- life.Play()
- End Function
-
- Function PlayerThrust(on:Int)
- thrust_channel.SetPaused(Not on)
- End Function
-
- Function SmallSaucer()
- ssaucer_channel.SetPaused(False)
- End Function
-
- Function LargeSaucer()
- lsaucer_channel.SetPaused(False)
- End Function
-
- Function NoSaucer()
- lsaucer_channel.SetPaused(True)
- ssaucer_channel.SetPaused(True)
- End Function
-
- Function Clear()
- PlayerThrust(False)
- NoSaucer()
- End Function
-End Type
+' Vectoroids
+'
+' Copyright 2005 Ian Cowburn
+'
+' $Id$
+'
+Strict
+
+Incbin "SFX/explode1.wav"
+Incbin "SFX/explode2.wav"
+Incbin "SFX/explode3.wav"
+Incbin "SFX/fire.wav"
+Incbin "SFX/life.wav"
+Incbin "SFX/lsaucer.wav"
+Incbin "SFX/sfire.wav"
+Incbin "SFX/ssaucer.wav"
+Incbin "SFX/thrust.wav"
+Incbin "SFX/thumphi.wav"
+Incbin "SFX/thumplo.wav"
+
+
+Type Sounds
+ Global explode:TSound[]
+ Global fire:TSound
+ Global life:TSound
+ Global lsaucer:TSound
+ Global sfire:TSound
+ Global ssaucer:TSound
+ Global thrust:TSound
+ Global thumphi:TSound
+ Global thumplo:TSound
+
+ Global thrust_channel:TChannel
+ Global ssaucer_channel:TChannel
+ Global lsaucer_channel:TChannel
+
+ Global frame:Int
+ Global hi:Int
+
+ Global thrust_on:Int
+ Global small_on:Int
+ Global large_on:Int
+
+ Function Init()
+ explode=New TSound[3]
+ explode[2]=LoadSound("incbin::SFX/explode1.wav")
+ explode[1]=LoadSound("incbin::SFX/explode2.wav")
+ explode[0]=LoadSound("incbin::SFX/explode3.wav")
+ fire=LoadSound("incbin::SFX/fire.wav")
+ life=LoadSound("incbin::SFX/life.wav")
+ lsaucer=LoadSound("incbin::SFX/lsaucer.wav",True)
+ sfire=LoadSound("incbin::SFX/sfire.wav")
+ ssaucer=LoadSound("incbin::SFX/ssaucer.wav",True)
+ thrust=LoadSound("incbin::SFX/thrust.wav",True)
+ thumplo=LoadSound("incbin::SFX/thumplo.wav")
+ thumphi=LoadSound("incbin::SFX/thumphi.wav")
+
+ frame=0
+ hi=True
+
+ thrust_channel=thrust.Cue()
+ ssaucer_channel=ssaucer.Cue()
+ lsaucer_channel=lsaucer.Cue()
+ End Function
+
+ Function Update(freq:Int)
+ If frame>freq
+ frame=0
+
+ If hi
+ thumphi.Play()
+ Else
+ thumplo.Play()
+ EndIf
+
+ hi=Not hi
+ EndIf
+ frame:+1
+ End Function
+
+ Function AsteroidExplosion(size:Int)
+ explode[size].Play()
+ End Function
+
+ Function ShipExplosion()
+ explode[0].Play()
+ End Function
+
+ Function PlayerFire()
+ fire.Play()
+ End Function
+
+ Function SaucerFire()
+ sfire.Play()
+ End Function
+
+ Function ExtraLife()
+ life.Play()
+ End Function
+
+ Function PlayerThrust(on:Int)
+ thrust_channel.SetPaused(Not on)
+ thrust_on=on
+ End Function
+
+ Function SmallSaucer()
+ ssaucer_channel.SetPaused(False)
+ small_on=True
+ End Function
+
+ Function LargeSaucer()
+ lsaucer_channel.SetPaused(False)
+ large_on=True
+ End Function
+
+ Function NoSaucer()
+ lsaucer_channel.SetPaused(True)
+ ssaucer_channel.SetPaused(True)
+ small_on=False
+ large_on=False
+ End Function
+
+ Function Clear()
+ PlayerThrust(False)
+ NoSaucer()
+ End Function
+
+ Function Pause()
+ thrust_channel.SetPaused(True)
+ ssaucer_channel.SetPaused(True)
+ lsaucer_channel.SetPaused(True)
+ End Function
+
+ Function EndPause()
+ thrust_channel.SetPaused(Not thrust_on)
+ ssaucer_channel.SetPaused(Not small_on)
+ lsaucer_channel.SetPaused(Not large_on)
+ End Function
+End Type
diff --git a/vectoroids.bmx b/vectoroids.bmx
index 69563f9..b4018bc 100644
--- a/vectoroids.bmx
+++ b/vectoroids.bmx
@@ -1,206 +1,205 @@
-' Vectoroids
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-
-Import noddybox.vector
-Import noddybox.bitmapfont
-Import noddybox.keysyms
-
-Import "types.bmx"
-Import "game.bmx"
-Import "sounds.bmx"
-Import "hiscore.bmx"
-
-
-' Initialise
-'
-SeedRnd(MilliSecs())
-
-?Win32
-If Switch("--directx")
- SetGraphicsDriver D3D7Max2DDriver()
-Else
- SetGraphicsDriver GLMax2DDriver()
-EndIf
-?
-
-Graphics 800,600,32,60
-HideMouse
-
-SetBlend(ALPHABLEND)
-SetAlpha(1.0)
-
-' Globals
-'
-Lookup.Init()
-GameGFX.Init()
-TParticleMachine.Init()
-GameConfig.Load()
-Sounds.Init()
-
-Global quit:Int=False
-Global hiscore:THiscore=THiscore.Load()
-
-' Main code
-'
-Menu()
-
-While Not quit
- Local game:TGame=New TGame
- While game.Play()
- Wend
- Sounds.Clear()
- TParticleMachine.Clear()
- hiscore.Check(game.score)
- Menu()
-Wend
-
-EndGraphics
-End
-
-
-' ===================================
-' Argument Routines
-' ===================================
-'
-Function Switch:Int(s:String)
- For Local a:String=EachIn AppArgs
- If a=s
- Return True
- EndIf
- Next
-
- Return False
-End Function
-
-' ===================================
-' Menu Routines
-' ===================================
-'
-Function Menu()
- FlushKeys()
-
- Local done:Int=False
-
- Local defkey:Int=0
- Local obj:TVectorGfxObject
-
- Select Rand(1,2)
- Case 1
- obj=GameGFX.large.Clone()
- Case 2
- obj=GameGFX.ship.Clone()
- End Select
-
- obj.scale=5
- obj.x=GraphicsWidth()/2
- obj.y=GraphicsHeight()/2
-
- While Not done
- If KeyHit(KEY_ESCAPE)
- done=True
- quit=True
- EndIf
-
- Cls
-
- obj.ang=(obj.ang+1) Mod 3600
-
- If defkey=0
- SetAlpha(0.5)
- Else
- SetAlpha(0.2)
- EndIf
- SetColor(255,255,255)
- obj.Draw()
- SetAlpha(1)
-
- If defkey>0
-
- If defkey=7
- GameGFX.font.Centre("PRESS A KEY TO GO BACK TO THE MENU",120)
- Else
- GameGFX.font.Centre("DEFINE KEYS",120)
- EndIf
-
- GameGFX.font.DrawColoured("left",250,150,255,255*(defkey=1),0)
- GameGFX.font.DrawColoured("right",250,170,255,255*(defkey=2),0)
- GameGFX.font.DrawColoured("thrust",250,190,255,255*(defkey=3),0)
- GameGFX.font.DrawColoured("fire",250,210,255,255*(defkey=4),0)
- GameGFX.font.DrawColoured("hyperspace",250,230,255,255*(defkey=5),0)
- GameGFX.font.DrawColoured("pause",250,250,255,255*(defkey=6),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.kleft).ToLower(),500,150,255,255*(defkey=1),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.kright).ToLower(),500,170,255,255*(defkey=2),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.kthrust).ToLower(),500,190,255,255*(defkey=3),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.kfire).ToLower(),500,210,255,255*(defkey=4),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.khyper).ToLower(),500,230,255,255*(defkey=5),0)
- GameGFX.font.DrawColoured(KeySym(GameConfig.kpause).ToLower(),500,250,255,255*(defkey=6),0)
-
- Local k:Int=0
-
- For Local f:Int=1 To 255
- If KeyHit(f)
- k=f
- Continue
- EndIf
- Next
-
- If k<>0
- Select defkey
- Case 1
- GameConfig.kleft=k
- Case 2
- GameConfig.kright=k
- Case 3
- GameConfig.kthrust=k
- Case 4
- GameConfig.kfire=k
- Case 5
- GameConfig.khyper=k
- Case 6
- GameConfig.kpause=k
- End Select
-
- defkey:+1
-
- If defkey=8
- GameConfig.Save()
- defkey=0
- EndIf
- EndIf
- Else
- GameGFX.font.CentreColoured("vectoroids",0,255,255,0)
- GameGFX.font.CentreColoured("COPYRIGHT | 2005 IAN C",20,255,0,0)
-
- GameGFX.font.Centre("press space to play",150)
- GameGFX.font.Centre("press r to redefine keys",190)
- GameGFX.font.Centre("EXTRA LIFE AT 10000 PTS THEN EVERY 50000 PTS",520)
- GameGFX.font.Centre("ESCAPE TO QUIT",560)
- GameGFX.font.CentreColoured("BASED ON ASTEROIDS | 1979 ~~ ATARI INC.",580,255,0,0)
-
- hiscore.Display(400)
-
- If KeyHit(KEY_ESCAPE)
- done=True
- quit=True
- EndIf
-
- If KeyHit(KEY_R)
- FlushKeys()
- defkey=1
- EndIf
-
- If KeyHit(KEY_SPACE)
- FlushKeys()
- done=True
- EndIf
- EndIf
-
- Flip
- FlushMem
- Wend
-End Function
+' Vectoroids
+'
+' Copyright 2005 Ian Cowburn
+'
+' $Id$
+'
+Strict
+
+Import noddybox.vector
+Import noddybox.bitmapfont
+Import noddybox.keysyms
+
+Import "types.bmx"
+Import "game.bmx"
+Import "sounds.bmx"
+Import "hiscore.bmx"
+
+
+' Initialise
+'
+SeedRnd(MilliSecs())
+
+?Win32
+If Switch("--directx")
+ SetGraphicsDriver D3D7Max2DDriver()
+Else
+ SetGraphicsDriver GLMax2DDriver()
+EndIf
+?
+
+Graphics 800,600,32,60
+HideMouse
+
+SetBlend(ALPHABLEND)
+SetAlpha(1.0)
+
+' Globals
+'
+Lookup.Init()
+GameGFX.Init()
+TParticleMachine.Init()
+GameConfig.Load()
+Sounds.Init()
+
+Global quit:Int=False
+Global hiscore:THiscore=THiscore.Load()
+
+' Main code
+'
+Menu()
+
+While Not quit
+ Local game:TGame=New TGame
+ While game.Play()
+ Wend
+ Sounds.Clear()
+ TParticleMachine.Clear()
+ hiscore.Check(game.score)
+ Menu()
+Wend
+
+EndGraphics
+End
+
+
+' ===================================
+' Argument Routines
+' ===================================
+'
+Function Switch:Int(s:String)
+ For Local a:String=EachIn AppArgs
+ If a=s
+ Return True
+ EndIf
+ Next
+
+ Return False
+End Function
+
+' ===================================
+' Menu Routines
+' ===================================
+'
+Function Menu()
+ FlushKeys()
+
+ Local done:Int=False
+
+ Local defkey:Int=0
+ Local obj:TVectorGfxObject
+
+ Select Rand(1,2)
+ Case 1
+ obj=GameGFX.large.Clone()
+ Case 2
+ obj=GameGFX.ship.Clone()
+ End Select
+
+ obj.scale=5
+ obj.x=GraphicsWidth()/2
+ obj.y=GraphicsHeight()/2
+
+ While Not done
+ If KeyHit(KEY_ESCAPE)
+ done=True
+ quit=True
+ EndIf
+
+ Cls
+
+ obj.ang=(obj.ang+1) Mod 3600
+
+ If defkey=0
+ SetAlpha(0.5)
+ Else
+ SetAlpha(0.2)
+ EndIf
+ SetColor(255,255,255)
+ obj.Draw()
+ SetAlpha(1)
+
+ If defkey>0
+
+ If defkey=7
+ GameGFX.font.Centre("PRESS A KEY TO GO BACK TO THE MENU",120)
+ Else
+ GameGFX.font.Centre("DEFINE KEYS",120)
+ EndIf
+
+ GameGFX.font.DrawColoured("left",250,150,255,255*(defkey=1),0)
+ GameGFX.font.DrawColoured("right",250,170,255,255*(defkey=2),0)
+ GameGFX.font.DrawColoured("thrust",250,190,255,255*(defkey=3),0)
+ GameGFX.font.DrawColoured("fire",250,210,255,255*(defkey=4),0)
+ GameGFX.font.DrawColoured("hyperspace",250,230,255,255*(defkey=5),0)
+ GameGFX.font.DrawColoured("pause",250,250,255,255*(defkey=6),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.kleft).ToLower(),500,150,255,255*(defkey=1),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.kright).ToLower(),500,170,255,255*(defkey=2),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.kthrust).ToLower(),500,190,255,255*(defkey=3),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.kfire).ToLower(),500,210,255,255*(defkey=4),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.khyper).ToLower(),500,230,255,255*(defkey=5),0)
+ GameGFX.font.DrawColoured(KeySym(GameConfig.kpause).ToLower(),500,250,255,255*(defkey=6),0)
+
+ Local k:Int=0
+
+ For Local f:Int=1 To 255
+ If KeyHit(f)
+ k=f
+ Continue
+ EndIf
+ Next
+
+ If k<>0
+ Select defkey
+ Case 1
+ GameConfig.kleft=k
+ Case 2
+ GameConfig.kright=k
+ Case 3
+ GameConfig.kthrust=k
+ Case 4
+ GameConfig.kfire=k
+ Case 5
+ GameConfig.khyper=k
+ Case 6
+ GameConfig.kpause=k
+ End Select
+
+ defkey:+1
+
+ If defkey=8
+ GameConfig.Save()
+ defkey=0
+ EndIf
+ EndIf
+ Else
+ GameGFX.font.CentreColoured("vectoroids",0,255,255,0)
+ GameGFX.font.CentreColoured("COPYRIGHT | 2005 IAN C",20,255,0,0)
+
+ GameGFX.font.Centre("press space to play",150)
+ GameGFX.font.Centre("press r to redefine keys",190)
+ GameGFX.font.Centre("EXTRA LIFE AT 10000 PTS THEN EVERY 50000 PTS",520)
+ GameGFX.font.Centre("ESCAPE TO QUIT",560)
+ GameGFX.font.CentreColoured("BASED ON ASTEROIDS | 1979 ~~ ATARI INC.",580,255,0,0)
+
+ hiscore.Display(400)
+
+ If KeyHit(KEY_ESCAPE)
+ done=True
+ quit=True
+ EndIf
+
+ If KeyHit(KEY_R)
+ FlushKeys()
+ defkey=1
+ EndIf
+
+ If KeyHit(KEY_SPACE)
+ FlushKeys()
+ done=True
+ EndIf
+ EndIf
+
+ Flip
+ Wend
+End Function