summaryrefslogtreecommitdiff
path: root/gametypes.bmx
blob: 004e69e6a6823a6fa156e137ddc15463351e6cca (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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
' Hardwire
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import "types.bmx"
Import "particle.bmx"
Import "sounds.bmx"

Type Pit
	Const WIDTH=10
	Const HEIGHT=13
	
	Function X:Int(p:Int)
		Return 230+p*32
	End Function
	
	Function Y:Int(p:Int)
		Return 120+p*32
	End Function
End Type

Type TWire
	Const CROSS:Int=0
	Const LEFT_RIGHT:Int=1
	Const TOP_BOTTOM:Int=2
	Const TOP_LEFT:Int=3
	Const TOP_RIGHT:Int=4
	Const BOTTOM_LEFT:Int=5
	Const BOTTOM_RIGHT:Int=6
	Const SPECIAL_BOMB:Int=7
	Const SPECIAL_TWISTER:Int=8
	
	Const DIR_NONE:Int=0
	Const DIR_UP:Int=1
	Const DIR_RIGHT:Int=2
	Const DIR_DOWN:Int=3
	Const DIR_LEFT:Int=4

	Global rotright:Int[]
	Global rotleft:Int[]
	Global img:TImage[]
	Global dir:Int[][]
	Global dx:Int[]
	Global dy:Int[]
	
	Global dirname:String[]
	Global typename:String[]

	Field t:Int
	
	Function Init()
		rotright=[0,2,1,4,6,3,5,7,8]
		rotleft=[0,2,1,5,3,6,4,7,8]
		
		img=[GameGFX.cross,GameGFX.left_right,GameGFX.top_bottom,GameGFX.top_left,GameGFX.top_right,GameGFX.bottom_left,GameGFX.bottom_right,GameGFX.special_bomb,GameGFX.special_twister]
	
		'	 CROSS							   LEFT_RIGHT							  TOP_BOTTOM						  TOP_LEFT					   TOP_RIGHT				      BOTTOM_LEFT				    BOTTOM_RIGHT				   SPECIAL_BOMB				SPECIAL_TWISTER
		dir=[[DIR_UP,DIR_RIGHT,DIR_DOWN,DIR_LEFT], [DIR_NONE,DIR_RIGHT,DIR_NONE,DIR_LEFT], [DIR_UP,DIR_NONE,DIR_DOWN,DIR_NONE], [DIR_NONE,DIR_UP,DIR_LEFT,DIR_NONE], [DIR_NONE,DIR_NONE,DIR_RIGHT,DIR_UP], [DIR_LEFT,DIR_DOWN,DIR_NONE,DIR_NONE], [DIR_RIGHT,DIR_NONE,DIR_NONE,DIR_DOWN], [DIR_NONE,DIR_NONE,DIR_NONE,DIR_NONE], [DIR_NONE,DIR_NONE,DIR_NONE,DIR_NONE]]
		
		dx=[0,0,1,0,-1]
		dy=[0,-1,0,1,0]
		
		dirname=["NONE","UP","RIGHT","DOWN","LEFT"]
		typename=["CROSS","LEFT_RIGHT","TOP_BOTTOM","TOP_LEFT","TOP_RIGHT","BOTTOM_LEFT","BOTTOM_RIGHT","SPECIAL BOMB","SPECIAL TWISTER"]
	End Function
	
	Method New()
		t=Rand(0,6)
	End Method
	
	Function Create:TWire(t:Int[])
		Local o:TWire=New TWire
		o.t=t[Rand(0,t.length-1)]
		Return o
	End Function
	
	Method Image:TImage()
		Return img[t]
	End Method
	
	Method RotateLeft()
		t=rotleft[t]
	End Method
	
	Method RotateRight()
		t=rotright[t]
	End Method
	
	Method Traverse:Int(d:Int)
		If d=DIR_NONE
			Return DIR_NONE
		EndIf
		
		Return dir[t][d-1]
	End Method
	
	Function DirX:Int(d:Int)
		Return dx[d]
	End Function

	Function DirY:Int(d:Int)
		Return dy[d]
	End Function
End Type

Type TPiece Abstract
	Field x:Int
	Field y:Int
	Field ox:Int
	Field oy:Int
	Field map:TWire[4,4]
	Field rot:Int
	Field offx:Int[4]
	Field offy:Int[4]
	Field special:Int
	Field special_pulse:Int
	Field col:Int
	Field coli:Int
	Field frame:Int
	Field framed:Int
	
	Function Create:TPiece(special:Int)
		Local o:TPiece
		
		If special
			Select Rand(0,5)
				Case 0
					o=TPiece(New TPiece_SpecialBomb)
				Case 1
					o=TPiece(New TPiece_SpecialTwister)
			End Select
		Else
			Select Rand(0,5)
				Case 0
					o=TPiece(New TPiece_S_Left)
				Case 1
					o=TPiece(New TPiece_S_Right)
				Case 2
					o=TPiece(New TPiece_L_Left)
				Case 3
					o=TPiece(New TPiece_L_Right)
				Case 4
					o=TPiece(New TPiece_Square)
				Case 5
					o=TPiece(New TPiece_Bar)
			End Select
		EndIf
		
		o.BaseInit(special)
		
		Return o
	End Function
	
	Method Init() Abstract
	
	Method BaseInit(special:Int)
		special_pulse=False
		Init()
		rot=0
		ox=offx[rot]
		oy=offy[rot]
		self.special=special
		col=255
		coli=-1
		frame=0
		framed=0
	End Method
	
	Method Draw()
		If special
			col:+coli
			If col=255 Or col=128
				coli=-coli
			EndIf
			
			framed:+1
			If framed=5
				framed=0
				frame=(frame+1) Mod 4
			EndIf

			For Local px:Int=0 Until 4
				For Local py:Int=0 Until 4
					If map[px,py]
						Local gx:Int=Pit.X(x-ox+px)
						Local gy:Int=Pit.Y(y-oy+py)
						SetColor(255,255,255)
						DrawImage(GameGFX.tile,gx,gy)
						If special_pulse
							SetColor(col,col/2,255-col)
						EndIf
						DrawImage(map[px,py].Image(),gx,gy,frame)
					EndIf
				Next
			Next
		Else
			For Local px:Int=0 Until 4
				For Local py:Int=0 Until 4
					If map[px,py]
						Local gx:Int=Pit.X(x-ox+px)
						Local gy:Int=Pit.Y(y-oy+py)
						SetColor(255,255,255)
						DrawImage(GameGFX.tile,gx,gy)
						SetColor(128,128,128)
						DrawImage(map[px,py].Image(),gx,gy)
					EndIf
				Next
			Next
		EndIf
	End Method
	
	Method RotateLeft()
		If special Then Return
		
		If rot=0
			rot=3
		Else
			rot:-1
		EndIf

		ox=offx[rot]
		oy=offy[rot]
		
		Local m:TWire[4,4]
		
		For Local px:Int=0 Until 4
			For Local py:Int=0 Until 4
				If map[px,py]
					map[px,py].RotateLeft()
				EndIf
				m[py,3-px]=map[px,py]
			Next
		Next
		
		map=m
	End Method

	Method RotateRight()
		If special Then Return

		rot=(rot+1) Mod 4

		ox=offx[rot]
		oy=offy[rot]
		
		Local m:TWire[4,4]
		
		For Local px:Int=0 Until 4
			For Local py:Int=0 Until 4
				If map[px,py]
					map[px,py].RotateRight()
				EndIf
				m[3-py,px]=map[px,py]
			Next
		Next
		
		map=m
	End Method
	
	Method Collides:Int(gm:TGameMap)
		For Local px:Int=0 Until 4
			For Local py:Int=0 Until 4
				If map[px,py]
					Local gx:Int=x-ox+px
					Local gy:Int=y-oy+py
					
					If gx<0 Or gx>=Pit.WIDTH Or gy>=Pit.HEIGHT
						Return True
					EndIf
					
					If gy>=0 And gm.map[gx,gy]
						Return True
					EndIf
				EndIf
			Next
		Next
		
		Return False
	End Method

	Method AddToMap(gm:TGameMap)
		If special
			gm.SetSpecial(TSpecial(Self))
		Else
			For Local px:Int=0 Until 4
				For Local py:Int=0 Until 4
					If map[px,py]
						Local gx:Int=x-ox+px
						Local gy:Int=y-oy+py
						
						If gy<0
							gm.overflow=True
						Else
							gm.map[gx,gy]=map[px,py]
							
							If gy=Pit.HEIGHT-1 Or gm.map[gx,gy+1]
								Particles.AddDust(Pit.X(gx)+16,Pit.Y(gy)+32)
							EndIf
						EndIf
					EndIf
				Next
			Next
	
			Sound.Click()
			
			If Not gm.overflow
				If Not gm.CheckWires()
					gm.Flatten()
					gm.CheckWires()
				EndIf
			EndIf
		EndIf
	End Method
End Type

Type TSpecial Extends TPiece Abstract
	Method DoSpecial:Int(gm:TGameMap) Abstract
End Type

Type TPiece_S_Right Extends TPiece
	Method Init()
		map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_RIGHT])
		map[2,0]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT])
		map[0,1]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT])
		map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT])
		offx=[1,2,2,0]
		offy=[1,1,2,2]
	End Method
End Type


Type TPiece_S_Left Extends TPiece
	Method Init()
		map[0,0]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT])
		map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT])
		map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT])
		map[2,1]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT])
		offx=[1,2,2,0]
		offy=[1,1,2,2]
	End Method
End Type


Type TPiece_L_Right Extends TPiece
	Method Init()
		map[0,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_RIGHT])
		map[1,0]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT])
		map[0,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM])
		map[0,2]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM])
		offx=[0,2,3,1]
		offy=[1,0,2,3]
	End Method
End Type


Type TPiece_L_Left Extends TPiece
	Method Init()
		map[0,0]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT])
		map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT])
		map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM])
		map[1,2]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM])
		offx=[1,2,2,1]
		offy=[1,1,2,2]
	End Method
End Type


Type TPiece_Square Extends TPiece
	Method Init()
		map[0,0]=TWire.Create([TWire.CROSS])
		map[1,0]=TWire.Create([TWire.CROSS])
		map[0,1]=TWire.Create([TWire.CROSS])
		map[1,1]=TWire.Create([TWire.CROSS])
		offx=[0,2,2,0]
		offy=[1,1,3,3]
	End Method
End Type


Type TPiece_Bar Extends TPiece
	Method Init()
		map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT,TWire.BOTTOM_RIGHT,TWire.TOP_BOTTOM])
		map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM])
		map[1,2]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM])
		map[1,3]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM])
		offx=[1,1,2,1]
		offy=[1,1,1,2]
	End Method
End Type

Type TPiece_SpecialBomb Extends TSpecial
	Method Init()
		map[0,0]=TWire.Create([TWire.SPECIAL_BOMB])
		offx=[0,0,0,0]
		offy=[0,0,0,0]
	End Method
	
	Method DoSpecial:Int(gm:TGameMap)
		Local l:TWireList=New TWireList

		If y<Pit.HEIGHT-1
			Local t:Int=map[x,y+1].t
			
			For Local px:Int=0 Until Pit.WIDTH
				For Local py:Int=0 Until Pit.HEIGHT
					If gm.map[px,py] And map[px,py].t=t
						l.Add(px,py,gm.map[px,py])
					EndIf
				Next
			Next
		EndIf
		
		If l.Count()=0
			TextParticles.Big("WHAT A WASTE!",255,0,0)
		Else
			TextParticles.Big("SPECIAL GOT " + (l.Count()-1) + " BLOCKS!",255,255,0)
		EndIf
		
		gm.path.AddLast(l)
		
		Return False
	End Method
End Type

Type TPiece_SpecialTwister Extends TSpecial
	Method Init()
		special_pulse=True
		map[0,0]=TWire.Create([TWire.SPECIAL_TWISTER])
		offx=[0,0,0,0]
		offy=[0,0,0,0]
	End Method
	
	Method DoSpecial:Int(gm:TGameMap)
	End Method
End Type


Type TWireListEnt
	Field w:TWire
	Field x:Int
	Field y:Int
	
	Function Create:TWireListEnt(x:Int, y:Int, w:TWire)
		Local o:TWireListEnt=New TWireListEnt
		o.x=x
		o.y=y
		o.w=w
		Return o
	End Function
End Type


Type TWireList
	Field list:TList
	Field col:Int
	
	Method New()
		list=CreateList()
		col=128
	End Method
	
	Method Add(x:Int, y:Int, w:TWire)
		list.AddLast(TWireListEnt.Create(x,y,w))
	End Method
	
	Method Draw:Int()
		col=Min(255,col+5)
		SetColor(col,col,col)
		For Local e:TWireListEnt=EachIn list
			DrawImage(e.w.Image(),Pit.X(e.x),Pit.Y(e.y))
		Next
		
		If col<255
			Return True
		Else
			For Local e:TWireListEnt=EachIn list
				Particles.AddImage(e.w.Image(),Pit.X(e.x),Pit.Y(e.y))
			Next
			Return False
		EndIf
	End Method
	
	Method Count:Int()
		Return list.Count()
	End Method
End Type


Type TGameMap
	Field map:TWire[Pit.WIDTH,Pit.HEIGHT]
	Field trode_col:Int
	Field trode_coli:Int
	Field overflow:Int
	Field cx:Int
	Field cy:Int
	Field path:TList
	Field special:TSpecial
	
	Method New()
		trode_col=0
		trode_coli=1
		overflow=False
		path=CreateList()
		special=Null
	End Method
	
	Method BlockInteract:Int()
		Return overflow Or path.Count() Or special
	End Method
	
	Method FindPath:Int(l:TWireList, x:Int, y:Int, dir:Int)
		If y<0
			Return False
		EndIf
		
		If x<0 Or x=Pit.WIDTH Or y=Pit.HEIGHT
			Return True
		EndIf
		
		Local w:TWire=map[x,y]

		If Not w
			Return False
		EndIf
		
		dir=w.Traverse(dir)
		
		If dir=TWire.DIR_NONE
			Return False
		EndIf
		
		l.Add(x,y,w)
		
		Return FindPath(l,x+TWire.DirX(dir),y+TWire.DirY(dir),dir)
	End Method
	
	Method FindLoop:Int(l:TWireList, ox:Int, oy:Int, x:Int, y:Int, dir:Int)
		If y<0 Or x<0 Or x=Pit.WIDTH Or y=Pit.HEIGHT
			Return False
		EndIf
		
		Local w:TWire=map[x,y]

		If Not w
			Return False
		EndIf
		
		dir=w.Traverse(dir)
		
		If dir=TWire.DIR_NONE
			Return False
		EndIf
		
		l.Add(x,y,w)
		
		x:+TWire.DirX(dir)
		y:+TWire.DirY(dir)
		
		If x=ox And y=oy And dir=TWire.DIR_RIGHT
			Return True
		EndIf
		
		Return FindLoop(l,ox,oy,x,y,dir)
	End Method
	
	Method CheckWires:Int()
		Local loop:Int=False
		Local wire:Int=False
		
		For Local y:Int=0 Until Pit.HEIGHT
			Local l:TWireList=New TWireList
			
			If FindPath(l,0,y,TWire.DIR_RIGHT)
				path.AddLast(l)
			EndIf
			
			l=New TWireList

			If FindPath(l,Pit.WIDTH-1,y,TWire.DIR_LEFT)
				path.AddLast(l)
				wire=True
			EndIf
		Next

		For Local x:Int=0 Until Pit.WIDTH
			Local l:TWireList=New TWireList
			
			If FindPath(l,x,Pit.HEIGHT-1,TWire.DIR_UP)
				path.AddLast(l)
				wire=True
			EndIf
		Next
		
		For Local x:Int=0 Until Pit.WIDTH
			For Local y:Int=0 Until Pit.HEIGHT
				If map[x,y]
					Local l:TWireList=New TWireList
					Select map[x,y].t
						Case TWire.CROSS, TWire.LEFT_RIGHT, TWire.TOP_LEFT, TWire.BOTTOM_LEFT
							If FindLoop(l,x,y,x,y,TWire.DIR_RIGHT)
								path.AddLast(l)
								loop=True
							EndIf
					End Select
				EndIf
			Next
		Next
		
		If loop And wire
			TextParticles.Big("LOOP AND WIRE",255,0,255)
		ElseIf loop
			TextParticles.Big("LOOP",255,0,255)
		ElseIf wire
			TextParticles.Big("WIRE",255,0,255)
		EndIf
		
		Return loop Or wire
	End Method
	
	Method SetSpecial(s:TSpecial)
		special=s
	End Method
	
	Method FlattenColumn(x:Int, y:Int)
		Local diff:Int=0
		
		For Local cy:Int=y-1 To 0 Step -1
			If map[x,cy]
				diff=y-cy
				Exit
			EndIf
		Next
		
		If diff
			For Local cy:Int=y To diff Step -1
				map[x,cy]=map[x,cy-diff]
			Next
			For Local cy:Int=diff To 0 Step -1
				map[x,cy]=Null
			Next
		EndIf
		
		Return diff
	End Method
	
	Method Flatten()
		For Local x:Int=0 Until Pit.WIDTH
			For Local y:Int=Pit.HEIGHT-1 To 1 Step -1
				If Not map[x,y] And FlattenColumn(x,y)
					Particles.AddDust(Pit.X(x)+16,Pit.Y(y)+32)
					Sound.Click()
				EndIf
			Next
		Next
	End Method
	
	Method Draw:Int()
		Local score:Int=0
		
		SetColor(255,255,255)
		DrawImage(GameGFX.pit_bottomleft,Pit.X(-1),Pit.Y(Pit.HEIGHT))
		DrawImage(GameGFX.pit_bottomright,Pit.X(Pit.WIDTH),Pit.Y(Pit.HEIGHT))

		DrawImage(GameGFX.pit_top,Pit.X(-1),Pit.Y(0))
		DrawImage(GameGFX.pit_top,Pit.X(Pit.WIDTH),Pit.Y(0))
		SetColor(trode_col,trode_col,0)
		DrawImage(GameGFX.trode_left,Pit.X(-1),Pit.Y(0))
		DrawImage(GameGFX.trode_right,Pit.X(Pit.WIDTH),Pit.Y(0))

		For Local f:Int=0 Until Pit.WIDTH
			SetColor(255,255,255)
			DrawImage(GameGFX.pit_bottom,Pit.X(f),Pit.Y(Pit.HEIGHT))
			SetColor(trode_col,trode_col,0)
			DrawImage(GameGFX.trode_bottom,Pit.X(f),Pit.Y(Pit.HEIGHT))
		Next
		
		For Local f:Int=1 Until Pit.HEIGHT
			SetColor(255,255,255)
			DrawImage(GameGFX.pit_side,Pit.X(-1),Pit.Y(f))
			DrawImage(GameGFX.pit_side,Pit.X(Pit.WIDTH),Pit.Y(f))
			SetColor(trode_col,trode_col,0)
			DrawImage(GameGFX.trode_left,Pit.X(-1),Pit.Y(f))
			DrawImage(GameGFX.trode_right,Pit.X(Pit.WIDTH),Pit.Y(f))
		Next
		
		For Local x:Int=0 Until Pit.WIDTH
			For Local y:Int=0 Until Pit.HEIGHT
				If map[x,y]
					SetColor(255,255,255)
					DrawImage(GameGFX.tile,Pit.X(x),Pit.Y(y))
					SetColor(128,128,128)
					DrawImage(map[x,y].Image(),Pit.X(x),Pit.Y(y))
				EndIf
			Next
		Next
		
		Local l:TEasyLink=TEasyLink.Create(path)
		Local check:Int=False
		
		While l.Value()
			Local b:TWireList=TWireList(l.Value())
			
			If b.Draw()
				l.MoveNext()
			Else
				If Not overflow
					score:+b.list.Count()
					For Local e:TWireListEnt=EachIn b.list
						map[e.x,e.y]=Null
					Next
				EndIf
				l.Remove()
				check=True
			EndIf
		Wend
		
		If check
			Sound.Path()
			Flatten()
			CheckWires()
		EndIf
		
		trode_col:+trode_coli
		
		If (trode_col=255 And trode_coli>0) Or (trode_col=200 And trode_coli<0)
			trode_coli=-trode_coli
		EndIf
		
		Return score
	End Method
End Type