summaryrefslogtreecommitdiff
path: root/types.bmx
blob: c5ca14f59da6326d85c363fa68ad4ce1a9f8e6bb (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
' Hardwire
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import noddybox.bitmapfont
Import noddybox.gfxmenu


' Included binaries
'
Incbin "GFX/font.bmf"
Incbin "GFX/small.bmf"
Incbin "GFX/large.bmf"
Incbin "GFX/pointer.png"
Incbin "GFX/play_button.png"
Incbin "GFX/quit_button.png"
Incbin "GFX/scores_button.png"
Incbin "GFX/keys_button.png"
Incbin "GFX/left_button.png"
Incbin "GFX/right_button.png"
Incbin "GFX/copper.png"
Incbin "GFX/copperslice.png"
Incbin "GFX/dust.png"
Incbin "GFX/title.png"
Incbin "GFX/gameover.png"

Incbin "TILES/tile.png"
Incbin "TILES/pit_top.png"
Incbin "TILES/pit_bottomleft.png"
Incbin "TILES/pit_bottomright.png"
Incbin "TILES/pit_bottom.png"
Incbin "TILES/pit_side.png"
Incbin "TILES/trode_left.png"
Incbin "TILES/trode_right.png"
Incbin "TILES/trode_bottom.png"
Incbin "TILES/top_bottom.png"
Incbin "TILES/left_right.png"
Incbin "TILES/cross.png"
Incbin "TILES/top_left.png"
Incbin "TILES/top_right.png"
Incbin "TILES/bottom_left.png"
Incbin "TILES/bottom_right.png"

Incbin "TILES/special_bomb.png"
Incbin "TILES/special_twister.png"

Const HERTZ:Int=60

Type Lookup
	Global si:Double[]
	Global co:Double[]
	
	Function Init()
		si=New Double[360]
		co=New Double[360]
		
		For Local a:Int=0 To 359
			si[a]=Sin(a)
			co[a]=Cos(a)
		Next
	End Function
End Type


Type GameGFX
	Global font:TBitmapFont
	Global small:TBitmapFont
	Global large:TBitmapFont

	Global title:TImage
	Global gameover:TImage

	Global pointer:TImage
	Global copper:TImage
	Global copperslice:TImage
	Global dust:TImage

	Global play_button:TImage
	Global quit_button:TImage
	Global left_button:TImage
	Global right_button:TImage
	Global scores_button:TImage
	Global keys_button:TImage
	
	Global tile:TImage
	
	Global pit_top:TImage
	Global pit_bottomleft:TImage
	Global pit_bottomright:TImage
	Global pit_bottom:TImage
	Global pit_side:TImage
	
	Global trode_left:TImage
	Global trode_right:TImage
	Global trode_bottom:TImage
	
	Global top_bottom:Timage
	Global left_right:Timage
	Global cross:Timage
	Global top_left:Timage
	Global top_right:Timage
	Global bottom_left:Timage
	Global bottom_right:Timage
	
	Global special_bomb:TImage
	Global special_twister: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)
		small=TBitmapFont.Load("incbin::GFX/small.bmf",0)
		large=TBitmapFont.Load("incbin::GFX/large.bmf",0)
		
		Assert font,"Failed to load incbin::GFX/font.bmf"
		Assert small,"Failed to load incbin::GFX/small.bmf"
		Assert large,"Failed to load incbin::GFX/large.bmf"

		title=SafeLoadImage("incbin::GFX/title.png",0)
		gameover=SafeLoadImage("incbin::GFX/gameover.png",0)
		MidHandleImage(gameover)

		pointer=SafeLoadImage("incbin::GFX/pointer.png",0)

		copper=SafeLoadImage("incbin::GFX/copper.png",0)
		copperslice=SafeLoadImage("incbin::GFX/copperslice.png",0)

		dust=SafeLoadImage("incbin::GFX/dust.png",FILTEREDIMAGE)
		MidHandleImage(dust)

		play_button=SafeLoadImage("incbin::GFX/play_button.png",0)
		quit_button=SafeLoadImage("incbin::GFX/quit_button.png",0)
		scores_button=SafeLoadImage("incbin::GFX/scores_button.png",0)
		keys_button=SafeLoadImage("incbin::GFX/keys_button.png",0)
		left_button=SafeLoadImage("incbin::GFX/left_button.png",0)
		right_button=SafeLoadImage("incbin::GFX/right_button.png",0)

		tile=SafeLoadImage("incbin::TILES/tile.png",0)

		pit_top=SafeLoadImage("incbin::TILES/pit_top.png",0)
		pit_bottom=SafeLoadImage("incbin::TILES/pit_bottom.png",0)
		pit_bottomleft=SafeLoadImage("incbin::TILES/pit_bottomleft.png",0)
		pit_bottomright=SafeLoadImage("incbin::TILES/pit_bottomright.png",0)
		pit_side=SafeLoadImage("incbin::TILES/pit_side.png",0)
		
		trode_left=SafeLoadImage("incbin::TILES/trode_left.png",0)
		trode_right=SafeLoadImage("incbin::TILES/trode_right.png",0)
		trode_bottom=SafeLoadImage("incbin::TILES/trode_bottom.png",0)

		top_bottom=SafeLoadImage("incbin::TILES/top_bottom.png",0)
		left_right=SafeLoadImage("incbin::TILES/left_right.png",0)
		cross=SafeLoadImage("incbin::TILES/cross.png",0)
		top_left=SafeLoadImage("incbin::TILES/top_left.png",0)
		top_right=SafeLoadImage("incbin::TILES/top_right.png",0)
		bottom_left=SafeLoadImage("incbin::TILES/bottom_left.png",0)
		bottom_right=SafeLoadImage("incbin::TILES/bottom_right.png",0)
		
		special_bomb=SafeLoadAnimImage("incbin::TILES/special_bomb.png",32,32,0,4,0)
		special_twister=SafeLoadAnimImage("incbin::TILES/special_twister.png",32,32,0,4,0)
	End Function
End Type

Type GameConfig
	Global kleft:Int
	Global kright:Int
	Global krotright:Int
	Global krotleft:Int
	Global kdrop:Int
	Global kpause:Int
	Global start_level:Int
	
	Function Load()
		Local s:TStream=ReadStream("hardwire.config")
		
		If s=Null
			kleft=KEY_LEFT
			kright=KEY_RIGHT
			krotright=KEY_UP
			krotleft=KEY_DOWN
			kdrop=KEY_SPACE
			kpause=KEY_P
			start_level=1
			Return
		EndIf
		
		s=LittleEndianStream(s)
		
		kleft=s.ReadInt()
		kright=s.ReadInt()
		krotright=s.ReadInt()
		krotleft=s.ReadInt()
		kdrop=s.ReadInt()
		kpause=s.ReadInt()
		start_level=s.ReadInt()
		
		s.Close()
	End Function
	
	Function Save()
		Local s:TStream=WriteStream("hardwire.config")
		
		If s=Null
			Return
		EndIf
		
		s=LittleEndianStream(s)
		
		s.WriteInt(kleft)
		s.WriteInt(kright)
		s.WriteInt(krotright)
		s.WriteInt(krotleft)
		s.WriteInt(kdrop)
		s.WriteInt(kpause)
		s.WriteInt(start_level)
		
		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 TMenuBdrop Extends TGfxMenuBackdrop
	Const NUM:Int=2
	Const SIZE:Double=50.0
	Const OFFSET:Double=500.0
	Field a:Int[NUM]
	Field msg:String
	Field msgp:Int
	Field msgx:Int
	Field msgy:Int
	
	Method New()
		For Local f:Int=0 Until NUM
			a[f]=360/NUM*f
		Next

		msg="                                          "
		msg:+"Welcome to Hardwire.  The object of the game is to connect the electrodes around the side of the pit using "
		msg:+"the wires embedded in the blocks.  Once a circuit is completed those blocks are removed.  Once in a while new blocks will fall from the sky.  "
		msg:+"If you let the pit overflow the game is over.  That's all there is to it...          "
		msg:+"Hardwire was written using BlitzMax -- http://www.blitzbasic.com/ -- and a variety of tools available at "
		msg:+"http://www.noddybox.demon.co.uk/          Please feel free to forward this game on to whoever you despise enough "
		msg:+"to inflict this monstrosity upon.  Enjoy."

		msgx=0
		msgp=0
		msgy=OFFSET
	End Method
	
	Method Create:TGfxMenuBackdrop()
		Return Self
	End Method
	
	Method Update()
		For Local f:Int=0 Until NUM
			a[f]=(a[f]+2) Mod 360
			
			If a[f]<=180
				Local c:Int=128-Abs(64*Lookup.si[a[f]])
				SetColor(c,c,c)
				DrawImage(GameGFX.copper,0,OFFSET+SIZE*Lookup.co[a[f]])
			EndIf
		Next
		
		GameGFX.large.Draw(msg[..80],msgx,msgy)
		msgx:-2
		If msgx<-GameGFX.large.TextWidth(msg[0..1])
			msgx:+GameGFX.large.TextWidth(msg[0..1])
			msg=msg[1..]+msg[0..1]
		EndIf
		
		For Local f:Int=0 Until NUM
			If a[f]>180
				Local c:Int=128+Abs(64*Lookup.si[a[f]])
				SetColor(c,c,c)
				DrawImage(GameGFX.copper,0,OFFSET+SIZE*Lookup.co[a[f]])
			EndIf
		Next
		SetColor(255,255,255)
	End Method
End Type