summaryrefslogtreecommitdiff
path: root/help.bmx
blob: ccf3aaadaa88c96c978eb2bde4946819fd9e9bbc (plain)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
' Hardwire
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import brl.pngloader

Import noddybox.bitmapfont
Import noddybox.gfxmenu

Import "types.bmx"


' Included binaries
'
Incbin "HELP/help.txt"
Incbin "HELP/pit.png"
Incbin "HELP/piece.png"
Incbin "HELP/wire1.png"
Incbin "HELP/wire2.png"
Incbin "HELP/wire3.png"
Incbin "HELP/loop1.png"
Incbin "HELP/bomb.png"
Incbin "HELP/twister.png"
Incbin "HELP/nuke.png"
Incbin "HELP/cross.png"

Type THelp
	Const TOP:Int=50
	Const BOTTOM:Int=550
	Field list:TList
	Field pos:Int
	Field item:TLink
	Field del:Int
	
	Method New()
		Local str:TStream=ReadStream("incbin::HELP/help.txt")
		
		Assert str,"Unable to open help file"
		
		list=CreateList()
		
		While Not str.Eof()
			Local line:String=str.ReadLine()
			
			If line.length
				Select line[0]
					Case Asc("#")
						list.AddLast(THelpImage.Create(line[1..]))
					Case Asc("$")
						list.AddLast(THelpAnimImage.Create(line[1..],False))
					Case Asc("~~")
						list.AddLast(THelpAnimImage.Create(line[1..],True))
					Default
						list.AddLast(THelpText.Create(line))
				End Select
			Else
				list.AddLast(THelpBlankLine.Create(line))
			EndIf
		Wend
		
		item=list.LastLink()
		pos=TOP-Current().Height()
	End Method
	
	Method Draw()
		Local y:Int=pos
		Local i:TLink=item
		
		While y<BOTTOM
			Local h:THelpItem=THelpItem(i.Value())
			h.Draw(y)
			y:+h.Height()
			i=i.NextLink()
			If Not i
				i=list.FirstLink()
			EndIf
		Wend

		SetColor(0,0,0)
		DrawRect(0,0,GraphicsWidth(),TOP)
		DrawRect(0,BOTTOM,GraphicsWidth(),GraphicsHeight()-BOTTOM)
		For Local f:Int=0 To 8
			SetAlpha(1.0-f*0.125)
			DrawLine(0,TOP+f,GraphicsWidth(),TOP+f)
			DrawLine(0,BOTTOM-f,GraphicsWidth(),BOTTOM-f)
		Next
		SetAlpha(1)
		SetColor(128,128,128)
		DrawLine(0,TOP-1,GraphicsWidth(),TOP-1)
		DrawLine(0,TOP+1,GraphicsWidth(),TOP+1)
		DrawLine(0,BOTTOM-1,GraphicsWidth(),BOTTOM-1)
		DrawLine(0,BOTTOM+1,GraphicsWidth(),BOTTOM+1)
		SetColor(255,255,255)
		DrawLine(0,TOP,GraphicsWidth(),TOP)
		DrawLine(0,BOTTOM,GraphicsWidth(),BOTTOM)
		
		GameGFX.large.Centre("HOW TO PLAY HARDWIRE",0,255,255,0)
		GameGFX.large.Centre("USE UP/DOWN CURSORS TO SCROLL",BOTTOM+10,255,255,0)
		GameGFX.large.Centre("ESCAPE TO EXIT",BOTTOM+30,255,255,0)
	End Method
	
	Method Current:THelpItem()
		Return THelpItem(item.Value())
	End Method
	
	Method Show()
		Local done:Int=False
		Local fade:TFadeScreen=TFadeScreen.FadeIn()
		
		While Not done
			Cls

			Draw()
			
			If KeyDown(KEY_DOWN)
				del=Min(del+1,200)
				pos:-del/4+1
				While pos<TOP-Current().Height()
					pos:+Current().Height()
					item=item.NextLink()
					If Not item
						item=list.FirstLink()
					EndIf
				Wend
			ElseIf KeyDown(KEY_UP)
				del=Min(del+1,200)
				pos:+del/4+1
				While pos>TOP
					item=item.PrevLink()
					If Not item
						item=list.LastLink()
					EndIf
					pos:-Current().Height()
				Wend
			ElseIf KeyHit(KEY_ESCAPE)
				FlushKeys()
				done=True
			Else
				del=0
			EndIf
			
			If fade
				If fade.Fade()
					fade.Draw()
				Else
					fade=Null
				EndIf
			EndIf
			
			Flip
		Wend
		
		SetColor(255,255,255)
	End Method
End Type

Type THelpItem Abstract
	Method Height:Int() Abstract
	Method Draw(y:Int) Abstract
End Type

Type THelpText Extends THelpItem
	Field txt:String
	Field r:Int
	Field g:Int
	Field b:Int
	Field sc:Int
	
	Function Create:THelpItem(txt:String)
		Local o:THelpText=New THelpText
		
		Select txt[0]
			Case Asc("@")
				o.sc=2
				o.r=255
				o.g=255
				o.b=0
				o.txt=txt[1..]
			Case Asc("!")
				o.sc=1
				o.r=255
				o.g=255
				o.b=0
				o.txt=txt[1..]
			Default
				o.sc=1
				o.r=255
				o.g=255
				o.b=255
				o.txt=txt
		End Select
		
		Return THelpItem(o)
	End Function
	
	Method Height:Int()
		Return GameGFX.large.MaxHeight()*sc
	End Method
	
	Method Draw(y:Int)
		SetScale(sc,sc)
		GameGFX.large.Centre(txt,y,r,g,b)
		SetScale(1,1)
	End Method
End Type


Type THelpBlankLine Extends THelpItem
	Function Create:THelpItem(txt:String)
		Local o:THelpBlankLine=New THelpBlankLine
		Return THelpItem(o)
	End Function
	
	Method Height:Int()
		Return GameGFX.large.MaxHeight()
	End Method
	
	Method Draw(y:Int)
	End Method
End Type


Type THelpImage Extends THelpItem
	Field img:TImage
	Field x:Int
	
	Function Create:THelpItem(url:String)
		Local o:THelpImage=New THelpImage
		o.img=LoadImage(url)
		Assert o.img,"Failed to load help image " + url
		o.x=(GraphicsWidth()-ImageWidth(o.img))/2
		Return THelpItem(o)
	End Function
	
	Method Height:Int()
		Return ImageHeight(img)
	End Method
	
	Method Draw(y:Int)
		SetColor(255,255,255)
		DrawImage(img,x,y)
	End Method
End Type


Type THelpAnimImage Extends THelpItem
	Field img:TImage
	Field x:Int
	Field frame:Int
	Field framei:Int
	Field framed:Int
	Field pong:Int
	
	Function Create:THelpItem(url:String,pong:Int)
		Local o:THelpAnimImage=New THelpAnimImage
		o.img=LoadAnimImage(url,32,32,0,4)
		Assert o.img,"Failed to load help anim image " + url
		o.x=(GraphicsWidth()-32)/2
		o.frame=0
		o.framed=5
		o.framei=1
		o.pong=pong
		Return THelpItem(o)
	End Function
	
	Method Height:Int()
		Return ImageHeight(img)
	End Method
	
	Method Draw(y:Int)
		SetColor(255,255,255)
		DrawImage(img,x,y,frame)
		framed:-1
		If framed=0
			framed=5
			If pong
				frame:+framei
				If frame=0 Or frame=3
					framei=-framei
				EndIf
			Else
				frame=(frame+1) Mod 4
			EndIf
		EndIf
	End Method
End Type