summaryrefslogtreecommitdiff
path: root/hiscore.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'hiscore.bmx')
-rw-r--r--hiscore.bmx391
1 files changed, 195 insertions, 196 deletions
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