summaryrefslogtreecommitdiff
path: root/hardwire.bmx
blob: d0cea7a601b652b0eb3084e738433bc483d8dad5 (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
' Hardwire
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict

Import noddybox.bitmapfont
Import noddybox.keysyms
Import noddybox.gfxmenu

Import "types.bmx"
Import "gametypes.bmx"
Import "game.bmx"
Import "particle.bmx"
Import "help.bmx"

Rem
TWire.Init()
For Local t:Int=TWire.CROSS To TWire.BOTTOM_RIGHT

	Local w:TWire=TWire.Create(t)
	
	For Local d:Int=TWire.DIR_NONE To TWire.DIR_LEFT
		Print TWire.typename[t] + ": " + TWire.dirname[d] + " -> " + TWire.dirname[w.Traverse(d)]
	Next
Next
End
EndRem

' ===================================
' 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
' ===================================
'
GameGFX.Init()	' MUST be first

Lookup.Init()
GameConfig.Load()
TWire.Init()
Particles.Init()
TextParticles.Init()
ExplosionParticles.Init()
Sound.Init()

Global bdrop:TMenuBdrop=New TMenuBdrop
Global quit:Int=False
Global last_score:Int=0


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

While Not quit
	Local game:TGame=New TGame
	game.SetInitLevel(GameConfig.start_level)
	
	While game.Play()
	Wend
	
	GameConfig.Save()
	last_score=game.score
	
	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()
	Const MENU_PLAY:Int=1
	Const MENU_QUIT:Int=2
	Const MENU_RULES:Int=3
	Const MENU_KEYS:Int=4
	Const MENU_LEFT:Int=5
	Const MENU_RIGHT:Int=6
	
	Local fade:TFadeScreen=TFadeScreen.FadeIn()
	Local done:Int=False
	Local menu:TGfxMenu=TGfxMenu.Create(255,0,0,255,255,255,25,bdrop,1)
	Local sel:Int
	
	Local defkey:Int=0
	
	Local x1:Int=GraphicsWidth()/3-ImageWidth(GameGFX.play_button)/2
	Local x2:Int=GraphicsWidth()/3*2-ImageWidth(GameGFX.play_button)/2

	menu.Add(x1,150,GameGFX.play_button,MENU_PLAY)
	menu.Add(x2,150,GameGFX.rules_button,MENU_RULES)
	menu.Add(x1,250,GameGFX.keys_button,MENU_KEYS)
	menu.Add(x2,250,GameGFX.quit_button,MENU_QUIT)
	menu.Add(x1,350,GameGFX.left_button,MENU_LEFT)
	menu.Add(x2+ImageWidth(GameGFX.play_button)-ImageWidth(GameGFX.right_button),350,GameGFX.right_button,MENU_RIGHT)
	
	Local tx1:Int=(GraphicsWidth()-GameGFX.large.TextWidth("START LEVEL 1"))/2
	Local tx2:Int=tx1+GameGFX.large.TextWidth("START LEVEL ")
	
	Local col:Int=128
	Local coli=1
	
	While Not done
		Cls
		SetColor(col,col,255)
		DrawImage(GameGFX.title,0,0)
		SetColor(255,255,255)
		
		col:+coli
		
		If col=128 Or col=255
			coli=-coli
		EndIf
		
		sel=menu.Render(defkey>0)
		
		If defkey>0
		
			If defkey=7
				GameGFX.large.Centre("PRESS A KEY TO GO BACK TO THE MENU",150)
			Else
				GameGFX.large.Centre("DEFINE KEYS",150)
				GameGFX.large.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)
			Local c5:Int=128+128*(defkey=5)
			Local c6:Int=128+128*(defkey=6)

			GameGFX.large.Draw("Left",250,180,c1,c1,0)
			GameGFX.large.Draw("Right",250,210,c2,c2,0)
			GameGFX.large.Draw("Rotate Right",250,240,c3,c3,0)
			GameGFX.large.Draw("Rotate Left",250,270,c4,c4,0)
			GameGFX.large.Draw("Drop",250,300,c5,c5,0)
			GameGFX.large.Draw("Pause",250,330,c6,c6,0)
			GameGFX.large.Draw(KeySym(GameConfig.kleft),500,180,c1,c1,0)
			GameGFX.large.Draw(KeySym(GameConfig.kright),500,210,c2,c2,0)
			GameGFX.large.Draw(KeySym(GameConfig.krotright),500,240,c3,c3,0)
			GameGFX.large.Draw(KeySym(GameConfig.krotleft),500,270,c4,c4,0)
			GameGFX.large.Draw(KeySym(GameConfig.kdrop),500,300,c5,c5,0)
			GameGFX.large.Draw(KeySym(GameConfig.kpause),500,330,c6,c6,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.krotright=k
					Case 4
						GameConfig.krotleft=k
					Case 5
						GameConfig.kdrop=k
					Case 6
						GameConfig.kpause=k
				End Select
				
				defkey:+1
				
				If defkey=7
					GameConfig.Save()
					defkey=0
					FlushKeys()
				EndIf
			EndIf
		Else
			If KeyHit(KEY_ESCAPE)
				done=True
				quit=True
			EndIf
			
			GameGFX.large.Draw("START LEVEL ",tx1,356)
			GameGFX.large.Draw(GameConfig.start_level,tx2,356,255,255,0)
			
			GameGFX.large.CentreOn("LAST SCORE",200,500)
			GameGFX.large.CentreOn("HIGH SCORE",600,500)
			GameGFX.large.CentreOn(last_score,200,520,255,255,0)
			GameGFX.large.CentreOn(GameConfig.hiscore,600,520,255,255,0)
		EndIf

		Select sel
			Case MENU_PLAY
				done=True
				FlushKeys()
			Case MENU_RULES
				FlushKeys()
				Local help:THelp=New THelp
				help.Show()
			Case MENU_KEYS
				FlushKeys()
				defkey=1
			Case MENU_QUIT
				done=True
				quit=True
			Case MENU_LEFT
				GameConfig.start_level=Max(1,GameConfig.start_level-1)
				GameConfig.Save()
			Case MENU_RIGHT
				GameConfig.start_level=Min(10,GameConfig.start_level+1)
				GameConfig.Save()
		End Select
	
		Rem
		SetScale(2,2)
		GameGFX.font.Centre("HARDWIRE",0,255,255,0)
		
		SetScale(1,1)
		GameGFX.font.Centre("Copyright (c) 2005 Ian C",20,255,0,0)
		EndRem
		
		SetColor(255,255,255)
		DrawImage(GameGFX.pointer,MouseX(),MouseY())
		
		If fade
			If fade.Fade()
				fade.Draw()
			Else
				fade=Null
			EndIf
		EndIf
		
		Flip
	Wend
	
	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