1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
' 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.ReadString(3)
o.score[f]=THiscoreEnt.Create(n,sc)
Next
s.Close()
EndIf
Return o
End Function
Method Save()
Return
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.WriteString(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 CheckScore(sc:Int)
If sc<score[NUM-1].score
Return
EndIf
Local done:Int=False
Local a:String="abcdefghijklmnopqrstuvwxyz{}"
Local curs:Int=0
Local nm:String=""
Local last:Int=0
Local del:Int=0
While Not done
Cls
If del
del:-1
EndIf
If KeyHit(GameConfig.kleft) And (last<>GameConfig.kleft Or del=0)
del=40
last=GameConfig.kleft
cur:-1
If cur<0
cur:+Len(a)
EndIf
EndIf
If KeyHit(GameConfig.kright) And (last<>GameConfig.kright Or del=0)
del=40
last=GameConfig.kright
cur:+1
If cur=Len(a)
cur=0
EndIf
EndIf
If KeyDown(GameConfig.khyper) And (last<>GameConfig.kright Or del=0)
del=40
last=GameConfig.kright
cur:+1
If cur=Len(a)
cur=0
EndIf
EndIf
GameGFX.font.Centre("enter your name for",0)
GameGFX.font.Centre("the hall of fame",20)
Flip
FlushMem
Wend
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 score-os.score
Else
Return 0
EndIf
End Method
End Type
|