summaryrefslogtreecommitdiff
path: root/main.bmx
blob: e44f5964b244da50507fc18bc8cc8d27ca2a1014 (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
' Particle Pinch
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict

Import noddybox.vector
Import noddybox.bitmapfont
Import noddybox.simplegui
Import noddybox.keysyms

Import "types.bmx"
Import "level.bmx"
Import "game.bmx"
Import "designer.bmx"
Import "menu.bmx"

' Included binaries
'
Incbin "GFX/font.bmf"
Incbin "GFX/small.bmf"
Incbin "GFX/STAR.png"
Incbin "GFX/SHIP.png"
Incbin "GFX/POINT.png"
Incbin "GFX/PARTICLE.png"
Incbin "GFX/POINTER.png"
Incbin "GFX/COLLECTOR.png"
Incbin "GFX/SHOCK.png"
Incbin "GFX/play_button.png"
Incbin "GFX/edit_button.png"
Incbin "GFX/load_button.png"
Incbin "GFX/toy_button.png"
Incbin "GFX/quit_button.png"
Incbin "GFX/left_button.png"
Incbin "GFX/right_button.png"
Incbin "GFX/scores_button.png"
Incbin "GFX/keys_button.png"


' Initialise
'
SeedRnd(MilliSecs())

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

Graphics 800,600,32,60
HideMouse

SetBlend(ALPHABLEND)
SetAlpha(1.0)

' Globals
'
GameGFX.font=TBitmapFont.Load("incbin::GFX/font.bmf",0)
GameGFX.smallfont=TBitmapFont.Load("incbin::GFX/small.bmf",0)
GameGFX.star=LoadAnimImage("incbin::GFX/STAR.png",8,8,0,2)
GameGFX.ship=LoadImage("incbin::GFX/SHIP.png",FILTEREDIMAGE)
GameGFX.collector=LoadAnimImage("incbin::GFX/COLLECTOR.png",8,8,0,2)
GameGFX.point=LoadImage("incbin::GFX/POINT.png",FILTEREDIMAGE)
GameGFX.particle=LoadImage("incbin::GFX/PARTICLE.png",0)
GameGFX.pointer=LoadImage("incbin::GFX/POINTER.png",0)
GameGFX.shock=LoadImage("incbin::GFX/SHOCK.png",0)
GameGFX.play_button=LoadImage("incbin::GFX/play_button.png",0)
GameGFX.edit_button=LoadImage("incbin::GFX/edit_button.png",0)
GameGFX.load_button=LoadImage("incbin::GFX/load_button.png",0)
GameGFX.toy_button=LoadImage("incbin::GFX/toy_button.png",0)
GameGFX.quit_button=LoadImage("incbin::GFX/quit_button.png",0)
GameGFX.left_button=LoadImage("incbin::GFX/left_button.png",0)
GameGFX.right_button=LoadImage("incbin::GFX/right_button.png",0)
GameGFX.scores_button=LoadImage("incbin::GFX/scores_button.png",0)
GameGFX.keys_button=LoadImage("incbin::GFX/keys_button.png",0)

SetImageHandle(GameGFX.star,3,3)
SetImageHandle(GameGFX.ship,7,7)
SetImageHandle(GameGFX.collector,3,3)
SetImageHandle(GameGFX.point,3,3)
SetImageHandle(GameGFX.particle,3,3)
SetImageHandle(GameGFX.pointer,0,0)
SetImageHandle(GameGFX.shock,3,3)

TPoint.img=GameGFX.point
TParticle.img=GameGFX.particle

TGUIFont.font=GameGFX.font

Lookup.Init()
TParticleMachine.Init()
GameConfig.Load()

Global quit:Int=False
Global levelfile:String="Default.ppinch"
Global levelset:TLevelSet=Null
Global selected_level:Int=0

' Check designer mode
'
If Switch("--design")
	LevelDesigner()
	EndGraphics
	End
EndIf

' Initialisation
'
Try
	levelset=TLevelSet.Load(levelfile)
Catch e:TLevelException
	Error(e.message,True)
EndTry

If levelset.level.Count()<1
	Error("Default levelset has no levels!",True)
EndIf


' Main code
'
Menu()

While Not quit
	Menu()
Wend

EndGraphics
End

' ===================================
' Error Routines
' ===================================
'
Function Error(s:String, fatal:Int=False)
	Local f:Int=0
	Local t:Int=0
	FlushKeys()
	
	SetScale(2,2)
	
	While Not KeyHit(KEY_ESCAPE)
		Cls
		
		GameGFX.font.CentreColoured(s,GraphicsHeight()/4,255,255*f,255*f)
		
		If fatal
			GameGFX.font.CentreColoured("FATAL ERROR",0,255,255,255)
			GameGFX.font.CentreColoured("Press ESCAPE to exit",GraphicsHeight()/4*3,255,255,255)
		Else
			GameGFX.font.CentreColoured("Press ESCAPE",GraphicsHeight()/4*3,255,255,255)
		EndIf
		
		t:+1
		
		If t=30
			t=0
			f=1-f
		EndIf
		
		Flip
	Wend
	
	If fatal
		EndGraphics
		End
	EndIf
	
	SetScale(1,1)
End Function

' ===================================
' 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()
	Const MENU_PLAY:Int=1
	Const MENU_EDIT:Int=2
	Const MENU_LOAD:Int=3
	Const MENU_TOY:Int=4
	Const MENU_QUIT:Int=5
	Const MENU_LEFT:Int=6
	Const MENU_RIGHT:Int=7
	Const MENU_SCORES:Int=8
	Const MENU_KEYS:Int=9
	
	Local done:Int=False
	Local menu:TMenu=TMenu.Create()
	Local sel:Int
	
	Local x1:Int=(GraphicsWidth()/2-ImageWidth(GameGFX.play_button))/2
	Local x2:Int=x1+GraphicsWidth()/2
	
	Local defkey:Int=0
	
	menu.Add(x1,100,GameGFX.play_button,MENU_PLAY)
	menu.Add(x2,100,GameGFX.scores_button,MENU_SCORES)
	menu.Add(x1,200,GameGFX.load_button,MENU_LOAD)
	menu.Add(x2,200,GameGFX.edit_button,MENU_EDIT)
	menu.Add(x1,300,GameGFX.toy_button,MENU_TOY)
	menu.Add(x2,300,GameGFX.keys_button,MENU_KEYS)
	menu.Add(-1,400,GameGFX.quit_button,MENU_QUIT)

	menu.Add(64,530,GameGFX.left_button,MENU_LEFT)
	menu.Add(GraphicsWidth()-96,530,GameGFX.right_button,MENU_RIGHT)
	
	While Not done
		If KeyHit(KEY_ESCAPE)
			done=True
			quit=True
		EndIf
		
		Cls
		
		If defkey>0
		
			SetScale(2,2)
			
			If defkey=6
				GameGFX.font.Centre("PRESS A KEY TO GO BACK TO THE MENU",50)
			Else
				GameGFX.font.Centre("DEFINE KEYS",50)
			EndIf
			
			GameGFX.font.DrawColoured("Left",250,100,255,255*(defkey=1),0)
			GameGFX.font.DrawColoured("Right",250,120,255,255*(defkey=2),0)
			GameGFX.font.DrawColoured("Thrust",250,140,255,255*(defkey=3),0)
			GameGFX.font.DrawColoured("Reverse",250,160,255,255*(defkey=4),0)
			GameGFX.font.DrawColoured("Gravity Wave",250,180,255,255*(defkey=5),0)
			GameGFX.font.DrawColoured(KeySym(GameConfig.kleft),500,100,255,255*(defkey=1),0)
			GameGFX.font.DrawColoured(KeySym(GameConfig.kright),500,120,255,255*(defkey=2),0)
			GameGFX.font.DrawColoured(KeySym(GameConfig.kthrust),500,140,255,255*(defkey=3),0)
			GameGFX.font.DrawColoured(KeySym(GameConfig.kreverse),500,160,255,255*(defkey=4),0)
			GameGFX.font.DrawColoured(KeySym(GameConfig.kblast),500,180,255,255*(defkey=5),0)
			
			Local k:Int=0
			
			For Local f:Int=1 To 255
				If KeyHit(f)
					k=f
					Continue
				EndIf
			Next
			
			If k<>0
				Select defkey
					Case 1
						GameConfig.kleft=k
					Case 2
						GameConfig.kright=k
					Case 3
						GameConfig.kthrust=k
					Case 4
						GameConfig.kreverse=k
					Case 5
						GameConfig.kblast=k
				End Select
				
				defkey:+1
				
				If defkey=7
					GameConfig.Save()
					defkey=0
				EndIf
			EndIf
			
			SetScale(1,1)
		EndIf

		sel=menu.Render(defkey>0)
		
		Select sel
			Case MENU_PLAY
				done=True
				FlushKeys()
			Case MENU_SCORES
				FlushKeys()
			Case MENU_LOAD
				FlushKeys()
			Case MENU_EDIT
				LevelDesigner()
				FlushKeys()
			Case MENU_TOY
				done=True
				FlushKeys()
			Case MENU_KEYS
				FlushKeys()
				defkey=1
			Case MENU_QUIT
				done=True
				quit=True
			Case MENU_LEFT
				selected_level:-1
				
				If selected_level<0
					selected_level=levelset.level.Count()-1
				EndIf
			Case MENU_RIGHT
				selected_level=(selected_level+1) Mod levelset.level.Count()
		End Select
	
		SetScale(2,2)
		GameGFX.font.CentreColoured("PARTICLE PINCH",0,255,255,0)
		
		If defkey=0
			GameGFX.font.CentreColoured("Start Level",528,0,255,255)
			GameGFX.font.Centre(levelset.Get(selected_level).name,547)
		EndIf

		SetScale(1,1)
		GameGFX.font.CentreColoured("Copyright (c) 2005 Ian Cowburn",20,255,0,0)
		
		SetColor(255,255,255)
		DrawImage(GameGFX.pointer,MouseX(),MouseY())
		
		Flip
		FlushMem
	Wend
End Function