summaryrefslogtreecommitdiff
path: root/missile_lock.bmx
blob: 95184529c7ff198c8c25ec2f37d500a5f0abde85 (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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
' 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
Framework brl.basic
Import brl.max2d
Import brl.glmax2d
?Win32
Import brl.d3d7max2d
?

Import noddybox.bitmapfont
Import noddybox.keysyms
Import noddybox.showlicense

Import "global.bmx"
Import "gametypes.bmx"
'Import "game.bmx"
Import "particle.bmx"
'Import "help.bmx"
Import "sound.bmx"

Incbin "short_license.txt"
Incbin "license.txt"

' ===================================
' Initialise
' ===================================
'
SeedRnd(MilliSecs())

?Win32
If Switch("--directx")
	SetGraphicsDriver D3D7Max2DDriver()
Else
	SetGraphicsDriver GLMax2DDriver()
EndIf
?

Graphics 800,600,32,HERTZ
HideMouse

SetBlend(ALPHABLEND)
SetAlpha(1.0)


' ===================================
' Globals
' ===================================
'
GFX.Init()	' MUST be first
SFX.Init()

GameConfig.Load()

If Not GameConfig.accepted
	If Not ShowLicense("MISSILE LOCK -- LICENSE","incbin::short_license.txt","incbin::license.txt")
		EndGraphics()
		End
	EndIf
	GameConfig.accepted=True
	GameConfig.Save()
EndIf

Scroller.Init()
Thanks.Init()
Particles.Init()
Backdrop.Init()
Trail.Init()
MissileSet.Init()
AsteroidSet.Init()

Global quit:Int=False


' ===================================
' Main
' ===================================
'
Menu()

FlushKeys()

While Not quit
	GameState.Reset()
	'GameState.SetLevel(10)
	MissileSet.StartLevel()
	AsteroidSet.StartLevel()
	
	While Not GameState.game_over
	
		Local alert_timer:Int=200
		
		SFX.Alert()
	
		While Not GameState.game_over And Not MissileSet.AllDestroyed()
			Cls()
			
			If alert_timer
				alert_timer:-1
				If alert_timer Mod 60 < 30
					GFX.font.Centre("RED ALERT!",300,255,0,0)
				EndIf
			EndIf
			
			ResetCollisions()
			
			Backdrop.Draw()
			Particles.Draw()
			Trail.Draw()
			
			GameState.Control()
			GameState.Move()
	
			SetRotation(GameState.ang)
	
			If GameState.shield
				SetColor(Rand(0,255),Rand(0,255),Rand(0,255))
			Else
				SetColor(255,255,255)
			EndIf
				
			DrawImage(GFX.ship,GameState.x,GameState.y)
			SetRotation(0)
			
			MissileSet.Update()
			AsteroidSet.Update()
			
			Local col:Object[]=CollideImage(GFX.ship,GameState.x,GameState.y,0,ALL_LAYERS,0)
			
			If Not GameState.shield Then
				If col
					GameState.ShieldDown()
					Particles.AddExplosion(GameState.x,GameState.y)
					For Local m:Missile=EachIn col
						If m
							MissileSet.RemoveMissile(m)
							GameState.AddScore(1*GameState.level)
							Exit
						EndIf
					Next
				EndIf
			EndIf
			
			If GameState.pause
				GFX.font.Centre("PAUSED!",300,255,255,0)
			EndIf
			
			GameState.Display()
			Flip(1)

			If GameState.pause
				GameState.pause=False
				While Not KeyHit(GameConfig.kpause) And Not KeyHit(KEY_ESCAPE)
				Wend
			EndIf
		Wend
		
		If Not GameState.game_over
			AsteroidSet.Nuke()

			Local bonus=100*GameState.level
			Local added:Int=0
			Local timer:Int=Max(HERTZ*5,bonus/10+HERTZ*3)
			Local bt:Int=0
			
			If GameState.gonads
				GameState.AddScore(9999+(GameState.level-1)*10000)
			EndIf
			
			If Not GameState.hit
				GameState.AddScore(500*GameState.level)
			EndIf
			
			If GameState.bonus_timer
				bonus:+GameState.bonus_timer
				bt=GameState.bonus_timer
			EndIf
			
			GameState.bonus_timer=0
			
			While timer And Not KeyHit(KEY_ESCAPE)
				Cls()
				ResetCollisions()
				
				GameState.ShieldShip()
				
				Backdrop.Draw()
				Particles.Draw()
				Trail.Draw()
				
				GameState.Control()
				GameState.Move()
		
				SetRotation(GameState.ang)
		
				If GameState.shield
					SetColor(Rand(0,255),Rand(0,255),Rand(0,255))
				Else
					SetColor(255,255,255)
				EndIf
					
				DrawImage(GFX.ship,GameState.x,GameState.y)
				SetRotation(0)
				
				GFX.font.Centre("LEVEL " + GameState.level + " COMPLETED!",200,255,255,0)

				GFX.font.Centre("BONUS " + Number.Format(added) + "!!!",400,255,255,0)
				
				If bt
					GFX.font.Centre("TIMER BONUS " + bt + "!!!",420,255,255,0)
				EndIf
				
				Local y:Int=440
				
				If Not GameState.hit
					GFX.font.Centre("PERFECT BONUS " + (500*GameState.level) + "!!!",y,255,255,0)
					y:+20
				EndIf
				
				If GameState.gonads
					GFX.font.Centre("SECRET GONADS OF STEEL BONUS " + (9999+(GameState.level-1)*10000) + "!!!",y,255,255,0)
					y:+20
				EndIf
				
				If added<bonus
					GameState.AddScore(10)
					added:+10
				EndIf
				
				If timer<HERTZ*2
					GFX.font.Centre("GET READY!",300)
				EndIf
				
				If GameState.pause
					GFX.font.Centre("PAUSED!",300,255,255,0)
				EndIf
				
				GameState.Display()
				Flip(1)
	
				If GameState.pause
					GameState.pause=False
					While Not KeyHit(GameConfig.kpause) And Not KeyHit(KEY_ESCAPE)
					Wend
				EndIf
				
				timer:-1
			Wend
			
			GameState.AddScore(bonus-added)
			
			GameState.LevelUp()
			MissileSet.StartLevel()
			AsteroidSet.StartLevel()
		EndIf
	Wend
	
	GameConfig.Save()
	
	MissileSet.Nuke()
	AsteroidSet.Nuke()
	Particles.AddBigExplosion(GameState.x,GameState.y)
	
	FlushKeys()
	Local timer:Int=0
	
	While Not KeyHit(KEY_SPACE) And Not KeyHit(KEY_ESCAPE) And timer<HERTZ*5
		Cls()
		
		Backdrop.Draw()
		Particles.Draw()
		Trail.Draw()
		
		GameState.Display()
		
		SetScale(3,3)
		GFX.font.Centre("GAME OVER!",280)
		SetScale(1,1)
		Flip(1)
		
		timer:+1
	Wend
	
	TFadeScreen.DoFadeOut()
	
	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()
	Local fade:TFadeScreen=TFadeScreen.FadeIn()
	Local done:Int=False
	Local defkey:Int=0
	
	Particles.Clear()
	
	While Not done
		Cls
		
		If Rand(100)>80
			Local x:Int=Rand(0,800)
			Local y:Int=Rand(0,600)
			Particles.AddScaledImage(GFX.fireball,x,y,0.1)
		End If
		
		Backdrop.Draw()
		Particles.Draw()
		Scroller.Draw(560)
			
		SetColor(255,255,255)
		DrawImage(GFX.title,0,0)
		
		If defkey>0
		
			If defkey=5
				GFX.font.Centre("PRESS A KEY TO GO BACK TO THE MENU",380)
			Else
				GFX.font.Centre("DEFINE KEYS",350)
				GFX.font.Centre("PRESS ESCAPE TO CANCEL",380)
			EndIf
			
			Local c1:Int=128+128*(defkey=1)
			Local c2:Int=128+128*(defkey=2)
			Local c3:Int=128+128*(defkey=3)
			Local c4:Int=128+128*(defkey=4)

			GFX.font.Draw("LEFT",250,200,c1,c1,c1)
			GFX.font.Draw("RIGHT",250,220,c2,c2,c2)
			GFX.font.Draw("THRUST",250,240,c3,c3,c3)
			GFX.font.Draw("PAUSE",250,260,c4,c4,c4)
			GFX.font.Draw(KeySym(GameConfig.kleft),500,200,c1,c1,0)
			GFX.font.Draw(KeySym(GameConfig.kright),500,220,c2,c2,0)
			GFX.font.Draw(KeySym(GameConfig.kthrust),500,240,c3,c3,0)
			GFX.font.Draw(KeySym(GameConfig.kpause),500,260,c4,c4,0)

			Local k:Int=-1
			
			For Local f:Int=0 To 255
				If KeyHit(f)
					k=f
					Continue
				EndIf
			Next
			
			If k=KEY_ESCAPE
				GameConfig.Load()
				defkey=0
				FlushKeys()
			ElseIf k<>-1
				Select defkey
					Case 1
						GameConfig.kleft=k
					Case 2
						GameConfig.kright=k
					Case 3
						GameConfig.kthrust=k
					Case 4
						GameConfig.kpause=k
				End Select
				
				defkey:+1
				
				If defkey=6
					GameConfig.Save()
					defkey=0
					FlushKeys()
				EndIf
			EndIf
		Else
			If KeyHit(KEY_ESCAPE)
				done=True
				quit=True
			EndIf
			
			If KeyHit(GameConfig.kthrust)
				done=True
			EndIf
			
			If KeyHit(KEY_R)
				defkey=1
				FlushKeys()
			EndIf
			
			GFX.font.Centre("COPYRIGHT (C) NODDYBOX 2006",200)
			GFX.font.Centre("HTTP://WWW.NODDYBOX.CO.UK/",226)

			GFX.font.Centre("THANKS TO",300)
			Thanks.Draw(326)
			
			GFX.font.Centre("PRESS " + KeySym(GameConfig.kthrust).ToUpper() + " TO PLAY",400)

			GFX.font.Centre("PRESS R TO REDEFINE KEYS",480)
			GFX.font.Centre("PRESS ESCAPE TO QUIT",500)
		EndIf

		If fade
			If fade.Fade()
				fade.Draw()
			Else
				fade=Null
			EndIf
		EndIf
		
		GameState.Display()
		Flip(1)
	Wend
	
	Particles.Clear()
	TFadeScreen.DoFadeOut()
End Function