summaryrefslogtreecommitdiff
path: root/global.bmx
blob: b120af78392519c94476cf691f7afbc693877601 (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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
' Missile Lock
'
' Copyright (C) 2006  Ian Cowburn (ianc@noddybox.co.uk)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
' -------------------------------------------------------------------------
'
' $Id$
'
Strict
Import brl.pngloader

Import noddybox.bitmapfont
Import noddybox.gfxmenu


' Included binaries
'
Incbin "GFX/font.bmf"

Incbin "GFX/title.png"
Incbin "GFX/ship.png"
Incbin "GFX/missile.png"
Incbin "GFX/exhaust.png"
Incbin "GFX/flame.png"
Incbin "GFX/star.png"
Incbin "GFX/asteroid.png"
Incbin "GFX/fireball.png"

Const HERTZ:Int=70

Const MISSILE_LAYER:Int=1
Const ASTEROID_LAYER:Int=2
Const ALL_LAYERS:Int=3

Type GFX
	Global font:TBitmapFont

	Global title:TImage
	
	Global ship:TImage
	Global missile:TImage
	Global exhaust:TImage
	Global flame:TImage
	Global star:TImage
	Global asteroid:TImage
	Global fireball:TImage

	Function SafeLoadImage:TImage(p:String, mode:Int)
		Local i:TImage=LoadImage(p,mode)
		Assert i,"Failed to load " + p
		Return i
	End Function
	
	Function SafeLoadAnimImage:TImage(p:String, w:Int, h:Int, f:Int, c:Int, mode:Int)
		Local i:TImage=LoadAnimImage(p,w,h,f,c,mode)
		Assert i,"Failed to load " + p
		Return i
	End Function
	
	Function Init()
		font=TBitmapFont.Load("incbin::GFX/font.bmf",0)
		
		Assert font,"Failed to load incbin::GFX/font.bmf"

		title=SafeLoadImage("incbin::GFX/title.png",0)
		
		ship=SafeLoadImage("incbin::GFX/ship.png",FILTEREDIMAGE)
		flame=SafeLoadImage("incbin::GFX/flame.png",FILTEREDIMAGE)
		MidHandleImage(ship)
		MidHandleImage(flame)

		missile=SafeLoadImage("incbin::GFX/missile.png",FILTEREDIMAGE)
		exhaust=SafeLoadImage("incbin::GFX/exhaust.png",FILTEREDIMAGE)
		SetImageHandle(missile,3,7)
		SetImageHandle(exhaust,3,3)

		star=SafeLoadImage("incbin::GFX/star.png",0)
		SetImageHandle(star,1,1)
		
		asteroid=SafeLoadImage("incbin::GFX/asteroid.png",FILTEREDIMAGE)
		MidHandleImage(asteroid)

		fireball=SafeLoadImage("incbin::GFX/fireball.png",FILTEREDIMAGE)
		SetImageHandle(fireball,7,7)
	End Function
End Type

Type GameConfig
	Global kleft:Int
	Global kright:Int
	Global kpause:Int
	Global kthrust:Int
	Global hiscore:Int
	
	Function Load()
		Local s:TStream=ReadStream("mlock.config")
		
		If s=Null
			kleft=KEY_LEFT
			kright=KEY_RIGHT
			kthrust=KEY_SPACE
			kpause=KEY_P
			hiscore=0
			Return
		EndIf
		
		s=LittleEndianStream(s)
		
		kleft=s.ReadInt()
		kright=s.ReadInt()
		kthrust=s.ReadInt()
		kpause=s.ReadInt()
		hiscore=s.ReadInt()
		
		s.Close()
	End Function
	
	Function Save()
		Local s:TStream=WriteStream("mlock.config")
		
		If s=Null
			Return
		EndIf
		
		s=LittleEndianStream(s)
		
		s.WriteInt(kleft)
		s.WriteInt(kright)
		s.WriteInt(kthrust)
		s.WriteInt(kpause)
		s.WriteInt(hiscore)
		
		s.Close()
	End Function
EndType

Type TEasyLink
	Field l:TLink
	
	Function Create:TEasyLink(l:TList)
		Local o:TEasyLink=New TEasyLink
		o.l=l.FirstLink()
		Return o
	End Function
	
	Method Value:Object()
		If l
			Return l.Value()
		Else
			Return Null
		EndIf
	End Method
	
	Method MoveNext()
		If l
			l=l.NextLink()
		EndIf
	End Method
	
	Method Remove()
		Local ol:TLink=l
		MoveNext()
		ol.Remove()
	End Method
End Type


Type Scroller
	Global msg:String
	Global msgp:Int
	Global msgx:Int
	
	Function Init()
		Rem
		msg="                                          "
		msg:+"DURING A TEST-FLIGHT OF THE STAR-FIGHTER OGL-X YOU ARE AMBUSHED IN THE ASTEROID FIELD OUTSIDE OF MARS...   "
		msg:+"THE EVIL EMPIRE CANNOT BE ALLOWED TO DESTROY THE PROTOTYPE SO YOU MUST PILOT THE WEAPONLESS CRAFT, "
		msg:+"AVOIDING THE DEADLY MISSILES UNTIL HELP ARRIVES...   "
		msg:+"SHOW HEART YOUNG PILOT, STAR-FLEET IS DEPENDING UPON YOU!"
		EndRem
		
		msg="                                                         "
		msg:+"IT IS A TIME OF WAR.  IN A LAST DITCH ATTEMPT TO WIN A LOSING WAR THAT HAS RAGED THROUGH THE GALAXY AGAINST THE EVIL EMPIRE "
		msg:+"A NEW SHIP, THE DX-9, HAS BEEN DEVELOPED.  ON A ROUTINE TEST FLIGHT THE SHIP HAS BEEN AMBUSHED IN AN ASTEROID FIELD.  "
		msg:+"WEAPONLESS, YOU MUST PILOT THE DX-9 AND AVOID THE EMPIRE'S MISSILE SALVOS AMONGST THE ASTEROIDS...  HELP WILL ARRIVE EVENTUALLY, "
		msg:+"BUT UNTIL THEN YOU ARE OUR LAST HOPE.  IF THE DX-9 IS LOST THEN SO IS THE EARTH.  EARTH IS DEPENDING ON YOU!!!"
		
		msgx=0
		msgp=0
	End Function 
	
	Function Draw(y:Int)
		GFX.font.Draw(msg[..70],msgx,y)

		msgx:-2
		If msgx<-GFX.font.TextWidth(msg[0..1])
			msgx:+GFX.font.TextWidth(msg[0..1])
			msg=msg[1..]+msg[0..1]
		EndIf
	End Function
End Type

Type VText
	Field t:String
	Field y:Int
	
	Function Create:VText(t:String, y:Int)
		Local o:VText=New VText
		o.t=t
		o.y=y
		Return o
	End Function
End Type

Type VerticalScroller
	Global msg:TList
	Global maxy:Int
	
	Method New()
		msg=CreateList()
		maxy=0
	End Method
	
	Method Add(s:String)
		SetScale(2,2)
		msg.AddLast(VText.Create(s,maxy+800))
		maxy:+GFX.font.TextHeight(s)
		SetScale(1,1)
	End Method
	
	Method Draw()
		SetScale(2,2)
		For Local o:VText=EachIn msg
			o.y:-1
			If o.y<-GFX.font.TextHeight(o.t)
				o.y:+maxy
			EndIf
			If o.y<799
				GFX.font.Centre(o.t,o.y)
			EndIf
		Next
		SetScale(1,1)
	End Method
End Type

Type Thanks
	Global item:String[]
	Global i:Int
	Global wait:Int
	Global a:Double
	Global ai:Double
	
	Function Init()
		item=["HTTP://WWW.SLAYRADIO.ORG/", ..
			  "HTTP://WWW.BLITZBASIC.COM/"]
		i=0
		a=0
		ai=0.05
	End Function
	
	Function Draw(y:Int)
		SetAlpha(a)
		GFX.font.Centre(item[i],y)
		SetAlpha(1)
		
		If wait
			wait:-1
		Else
			a:+ai
			
			If a>1
				wait=HERTZ*5
				ai=-0.05
				a=1
			ElseIf a<0
				i=(i+1) Mod item.length
				ai=0.05
				a=0
			EndIf
		EndIf
	End Function 
End Type

Type TFadeScreen
	Field a:Double
	Field ai:Double
	
	Function Create:TFadeScreen(a:Double, ai:Double)
		Local o:TFadeScreen=New TFadeScreen
		o.a=a
		o.ai=ai
		Return o
	End Function
	
	Function FadeOut:TFadeScreen()
		Return Create(0,0.05)
	End Function

	Function FadeIn:TFadeScreen()
		Return Create(1,-0.05)
	End Function
	
	Function DoFadeIn()
		Local fade:TFadeScreen=TFadeScreen.FadeIn()
		Local pm:TPixmap=GrabPixmap(0,0,GraphicsWidth(),GraphicsHeight())
		
		While fade.Fade()
			Cls
			DrawPixmap(pm,0,0)
			fade.Draw()
			Flip
		Wend
	End Function
	
	Function DoFadeOut()
		Local fade:TFadeScreen=TFadeScreen.FadeOut()
		Local pm:TPixmap=GrabPixmap(0,0,GraphicsWidth(),GraphicsHeight())
		
		While fade.Fade()
			Cls
			DrawPixmap(pm,0,0)
			fade.Draw()
			Flip
		Wend
	End Function
	
	Method Fade:Int()
		a:+ai
		Return a>0 And a<1
	End Method

	Method Draw()
		Local r:Int,g:Int,b:Int
		Local x:Float,y:Float
		Local oa:Double=GetAlpha()
		GetColor(r,g,b)
		GetOrigin(x,y)
		SetAlpha(a)
		SetColor(0,0,0)
		DrawRect(-x,-y,GraphicsWidth(),GraphicsHeight())
		SetColor(r,g,b)
		SetAlpha(oa)
	End Method
End Type


Type Number
	Function Format:String(num:Int)
		Local c:Int=0
		Local ret:String=""
		Local a:String=String.FromInt(num)
		
		For Local f:Int=a.length-1 To 0 Step -1
			If ret.length And (c Mod 3)=0
				ret=","+ret
			EndIf
			ret=a[f..f+1]+ret
			c:+1
		Next
		Return ret
	End Function
End Type