-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
1958 lines (1924 loc) · 60.8 KB
/
main.lua
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Generated by Haxe 4.0.0-rc.1+1fc84df26
local _hx_array_mt = {
__newindex = function(t,k,v)
local len = t.length
t.length = k >= len and (k + 1) or len
rawset(t,k,v)
end
}
local function _hx_tab_array(tab,length)
tab.length = length
return setmetatable(tab, _hx_array_mt)
end
local function _hx_anon_newindex(t,k,v) t.__fields__[k] = true; rawset(t,k,v); end
local _hx_anon_mt = {__newindex=_hx_anon_newindex}
local function _hx_a(...)
local __fields__ = {};
local ret = {__fields__ = __fields__};
local max = select('#',...);
local tab = {...};
local cur = 1;
while cur < max do
local v = tab[cur];
__fields__[v] = true;
ret[v] = tab[cur+1];
cur = cur + 2
end
return setmetatable(ret, _hx_anon_mt)
end
local function _hx_e()
return setmetatable({__fields__ = {}}, _hx_anon_mt)
end
local function _hx_o(obj)
return setmetatable(obj, _hx_anon_mt)
end
local function _hx_new(prototype)
return setmetatable({__fields__ = {}}, {__newindex=_hx_anon_newindex, __index=prototype})
end
local _hxClasses = {}
local Int = _hx_e();
local Dynamic = _hx_e();
local Float = _hx_e();
local Bool = _hx_e();
local Class = _hx_e();
local Enum = _hx_e();
local Array = _hx_e()
__defold_support_Script = _hx_e()
local Block = _hx_e()
local Board = _hx_e()
local Connector = _hx_e()
local MagicFx = _hx_e()
local Main = _hx_e()
local Math = _hx_e()
local Messages = _hx_e()
local String = _hx_e()
local Std = _hx_e()
__defold_CollectionproxyMessages = _hx_e()
__defold_GoMessages = _hx_e()
__defold_SpriteMessages = _hx_e()
__defold_support_GuiScript = _hx_e()
__gui_NoDropRoom = _hx_e()
__gui_MainMenu = _hx_e()
__gui_Restart = _hx_e()
__gui_PresentLevel = _hx_e()
__gui_Board = _hx_e()
__gui_LevelComplete = _hx_e()
__defold_support_Init = _hx_e()
__lua_Boot = _hx_e()
local _hx_bind, _hx_bit, _hx_staticToInstance, _hx_funcToField, _hx_maxn, _hx_print, _hx_apply_self, _hx_box_mr, _hx_bit_clamp, _hx_table, _hx_bit_raw
local _hx_pcall_default = {};
local _hx_pcall_break = {};
Array.new = function()
local self = _hx_new(Array.prototype)
Array.super(self)
return self
end
Array.super = function(self)
_hx_tab_array(self, 0);
end
Array.prototype = _hx_a();
Array.prototype.concat = function(self,a)
local _g = _hx_tab_array({}, 0);
local _g1 = 0;
local _g2 = self;
while (_g1 < _g2.length) do
local i = _g2[_g1];
_g1 = _g1 + 1;
_g:push(i);
end;
local _g3 = 0;
while (_g3 < a.length) do
local i1 = a[_g3];
_g3 = _g3 + 1;
_g:push(i1);
end;
do return _g end
end
Array.prototype.join = function(self,sep)
local tbl = ({});
local _gthis = self;
local cur_length = 0;
local i = _hx_o({__fields__={hasNext=true,next=true},hasNext=function(self)
do return cur_length < _gthis.length end;
end,next=function(self)
cur_length = cur_length + 1;
do return _gthis[cur_length - 1] end;
end});
while (i:hasNext()) do
_G.table.insert(tbl, Std.string(i:next()));
end;
do return _G.table.concat(tbl, sep) end
end
Array.prototype.pop = function(self)
if (self.length == 0) then
do return nil end;
end;
local ret = self[self.length - 1];
self[self.length - 1] = nil;
self.length = self.length - 1;
do return ret end
end
Array.prototype.push = function(self,x)
self[self.length] = x;
do return self.length end
end
Array.prototype.reverse = function(self)
local tmp;
local i = 0;
while (i < Std.int(self.length / 2)) do
tmp = self[i];
self[i] = self[(self.length - i) - 1];
self[(self.length - i) - 1] = tmp;
i = i + 1;
end;
end
Array.prototype.shift = function(self)
if (self.length == 0) then
do return nil end;
end;
local ret = self[0];
if (self.length == 1) then
self[0] = nil;
else
if (self.length > 1) then
self[0] = self[1];
_G.table.remove(self, 1);
end;
end;
local tmp = self;
tmp.length = tmp.length - 1;
do return ret end
end
Array.prototype.slice = function(self,pos,_end)
if ((_end == nil) or (_end > self.length)) then
_end = self.length;
else
if (_end < 0) then
_end = _G.math.fmod((self.length - (_G.math.fmod(-_end, self.length))), self.length);
end;
end;
if (pos < 0) then
pos = _G.math.fmod((self.length - (_G.math.fmod(-pos, self.length))), self.length);
end;
if ((pos > _end) or (pos > self.length)) then
do return _hx_tab_array({}, 0) end;
end;
local ret = _hx_tab_array({}, 0);
local _g = pos;
local _g1 = _end;
while (_g < _g1) do
_g = _g + 1;
ret:push(self[_g - 1]);
end;
do return ret end
end
Array.prototype.sort = function(self,f)
local i = 0;
local l = self.length;
while (i < l) do
local swap = false;
local j = 0;
local max = (l - i) - 1;
while (j < max) do
if (f(self[j], self[j + 1]) > 0) then
local tmp = self[j + 1];
self[j + 1] = self[j];
self[j] = tmp;
swap = true;
end;
j = j + 1;
end;
if (not swap) then
break;
end;
i = i + 1;
end;
end
Array.prototype.splice = function(self,pos,len)
if ((len < 0) or (pos > self.length)) then
do return _hx_tab_array({}, 0) end;
else
if (pos < 0) then
pos = self.length - (_G.math.fmod(-pos, self.length));
end;
end;
len = Math.min(len, self.length - pos);
local ret = _hx_tab_array({}, 0);
local _g = pos;
local _g1 = pos + len;
while (_g < _g1) do
_g = _g + 1;
local i = _g - 1;
ret:push(self[i]);
self[i] = self[i + len];
end;
local _g2 = pos + len;
local _g3 = self.length;
while (_g2 < _g3) do
_g2 = _g2 + 1;
local i1 = _g2 - 1;
self[i1] = self[i1 + len];
end;
local tmp = self;
tmp.length = tmp.length - len;
do return ret end
end
Array.prototype.toString = function(self)
local tbl = ({});
_G.table.insert(tbl, "[");
_G.table.insert(tbl, self:join(","));
_G.table.insert(tbl, "]");
do return _G.table.concat(tbl, "") end
end
Array.prototype.unshift = function(self,x)
local len = self.length;
local _g = 0;
while (_g < len) do
_g = _g + 1;
local i = _g - 1;
self[len - i] = self[(len - i) - 1];
end;
self[0] = x;
end
Array.prototype.insert = function(self,pos,x)
if (pos > self.length) then
pos = self.length;
end;
if (pos < 0) then
pos = self.length + pos;
if (pos < 0) then
pos = 0;
end;
end;
local cur_len = self.length;
while (cur_len > pos) do
self[cur_len] = self[cur_len - 1];
cur_len = cur_len - 1;
end;
self[pos] = x;
end
Array.prototype.remove = function(self,x)
local _g = 0;
local _g1 = self.length;
while (_g < _g1) do
_g = _g + 1;
local i = _g - 1;
if (self[i] == x) then
local _g2 = i;
local _g11 = self.length - 1;
while (_g2 < _g11) do
_g2 = _g2 + 1;
local j = _g2 - 1;
self[j] = self[j + 1];
end;
self[self.length - 1] = nil;
self.length = self.length - 1;
do return true end;
end;
end;
do return false end
end
Array.prototype.indexOf = function(self,x,fromIndex)
local _end = self.length;
if (fromIndex == nil) then
fromIndex = 0;
else
if (fromIndex < 0) then
fromIndex = self.length + fromIndex;
if (fromIndex < 0) then
fromIndex = 0;
end;
end;
end;
local _g = fromIndex;
while (_g < _end) do
_g = _g + 1;
local i = _g - 1;
if (x == self[i]) then
do return i end;
end;
end;
do return -1 end
end
Array.prototype.lastIndexOf = function(self,x,fromIndex)
if ((fromIndex == nil) or (fromIndex >= self.length)) then
fromIndex = self.length - 1;
else
if (fromIndex < 0) then
fromIndex = self.length + fromIndex;
if (fromIndex < 0) then
do return -1 end;
end;
end;
end;
local i = fromIndex;
while (i >= 0) do
if (self[i] == x) then
do return i end;
else
i = i - 1;
end;
end;
do return -1 end
end
Array.prototype.copy = function(self)
local _g = _hx_tab_array({}, 0);
local _g1 = 0;
local _g2 = self;
while (_g1 < _g2.length) do
local i = _g2[_g1];
_g1 = _g1 + 1;
_g:push(i);
end;
do return _g end
end
Array.prototype.map = function(self,f)
local _g = _hx_tab_array({}, 0);
local _g1 = 0;
local _g2 = self;
while (_g1 < _g2.length) do
local i = _g2[_g1];
_g1 = _g1 + 1;
_g:push(f(i));
end;
do return _g end
end
Array.prototype.filter = function(self,f)
local _g = _hx_tab_array({}, 0);
local _g1 = 0;
local _g2 = self;
while (_g1 < _g2.length) do
local i = _g2[_g1];
_g1 = _g1 + 1;
if (f(i)) then
_g:push(i);
end;
end;
do return _g end
end
Array.prototype.iterator = function(self)
local _gthis = self;
local cur_length = 0;
do return _hx_o({__fields__={hasNext=true,next=true},hasNext=function(self)
do return cur_length < _gthis.length end;
end,next=function(self)
cur_length = cur_length + 1;
do return _gthis[cur_length - 1] end;
end}) end
end
Array.prototype.resize = function(self,len)
if (self.length < len) then
self.length = len;
else
if (self.length > len) then
local _g = len;
local _g1 = self.length;
while (_g < _g1) do
_g = _g + 1;
self[_g - 1] = nil;
end;
self.length = len;
end;
end;
end
__defold_support_Script.new = function()
local self = _hx_new()
__defold_support_Script.super(self)
return self
end
__defold_support_Script.super = function(self)
end
Block.new = function()
local self = _hx_new(Block.prototype)
Block.super(self)
return self
end
Block.super = function(self)
__defold_support_Script.super(self);
end
Block.prototype = _hx_a();
Block.prototype.init = function(self,_self)
_G.go.set_scale(0.18);
_self.fx1 = nil;
_self.fx2 = nil;
_G.msg.post("#cover", __defold_GoMessages.disable);
if (_self.color ~= nil) then
_G.msg.post("#sprite", __defold_SpriteMessages.play_animation, _hx_o({__fields__={id=true},id=_self.color}));
else
_G.msg.post("#sprite", __defold_GoMessages.disable);
end;
end
Block.prototype.final_ = function(self,_self)
if (_self.fx1 ~= nil) then
_G.go.delete(_self.fx1);
end;
if (_self.fx2 ~= nil) then
_G.go.delete(_self.fx2);
end;
if (_self.cover ~= nil) then
_G.go.delete(_self.cover);
end;
end
Block.prototype.on_message = function(self,_self,message_id,message,_)
local message_id1 = message_id;
if (message_id1) == Messages.lights_off or (message_id1) == Messages.lights_on then
_G.msg.post(_self.fx1, message_id);
_G.msg.post(_self.fx2, message_id);
elseif (message_id1) == Messages.make_magic then
_self.color = _G.hash("magic");
_G.msg.post("#cover", __defold_GoMessages.enable);
_G.msg.post("#sprite", __defold_GoMessages.enable);
_G.msg.post("#sprite", __defold_SpriteMessages.play_animation, _hx_o({__fields__={id=true},id=_G.hash("magic-sphere_layer1")}));
local hleft = _G.hash("left");
local hright = _G.hash("right");
_self.fx1 = _G.factory.create("#fxfactory", _G.vmath.vector3(0, 0, 0), nil, ({direction = hleft}));
_self.fx2 = _G.factory.create("#fxfactory", _G.vmath.vector3(0, 0, 0), nil, ({direction = hright}));
_G.msg.post(_self.fx1, __defold_GoMessages.set_parent, _hx_o({__fields__={parent_id=true,keep_world_transform=true},parent_id=_G.go.get_id(),keep_world_transform=0}));
_G.msg.post(_self.fx2, __defold_GoMessages.set_parent, _hx_o({__fields__={parent_id=true,keep_world_transform=true},parent_id=_G.go.get_id(),keep_world_transform=0}));
_G.go.set(_self.fx1, "position.z", 0.01);
_G.go.set(_self.fx1, "scale", 1);
_G.go.set(_self.fx2, "position.z", 0.02);
_G.go.set(_self.fx2, "scale", 1); end;
end
Block.__super__ = __defold_support_Script
setmetatable(Block.prototype,{__index=__defold_support_Script.prototype})
Board.new = function()
local self = _hx_new(Board.prototype)
Board.super(self)
return self
end
Board.super = function(self)
__defold_support_Script.super(self);
end
Board.build_blocklist = function(_self)
_self.blocks = _hx_tab_array({}, 0);
local _g = 0;
local _g1 = _self.board.length;
while (_g < _g1) do
_g = _g + 1;
local col = _self.board[_g - 1];
local _g2 = 0;
local _g11 = col.length;
while (_g2 < _g11) do
_g2 = _g2 + 1;
local b = col[_g2 - 1];
if (b ~= nil) then
_self.blocks:push(_hx_o({__fields__={id=true,color=true,x=true,y=true},id=b.id,color=b.color,x=b.x,y=b.y}));
end;
end;
end;
end
Board.magic_blocks = function(_self)
local magic = _hx_tab_array({}, 0);
local block = _self.board[0][0];
if ((block ~= nil) and (block.color == _G.hash("magic"))) then
magic:push(block);
end;
local block1 = _self.board[0][1];
if ((block1 ~= nil) and (block1.color == _G.hash("magic"))) then
magic:push(block1);
end;
local block2 = _self.board[0][2];
if ((block2 ~= nil) and (block2.color == _G.hash("magic"))) then
magic:push(block2);
end;
local block3 = _self.board[0][3];
if ((block3 ~= nil) and (block3.color == _G.hash("magic"))) then
magic:push(block3);
end;
local block4 = _self.board[0][4];
if ((block4 ~= nil) and (block4.color == _G.hash("magic"))) then
magic:push(block4);
end;
local block5 = _self.board[0][5];
if ((block5 ~= nil) and (block5.color == _G.hash("magic"))) then
magic:push(block5);
end;
local block6 = _self.board[0][6];
if ((block6 ~= nil) and (block6.color == _G.hash("magic"))) then
magic:push(block6);
end;
local block7 = _self.board[0][7];
if ((block7 ~= nil) and (block7.color == _G.hash("magic"))) then
magic:push(block7);
end;
local block8 = _self.board[0][8];
if ((block8 ~= nil) and (block8.color == _G.hash("magic"))) then
magic:push(block8);
end;
local block9 = _self.board[1][0];
if ((block9 ~= nil) and (block9.color == _G.hash("magic"))) then
magic:push(block9);
end;
local block10 = _self.board[1][1];
if ((block10 ~= nil) and (block10.color == _G.hash("magic"))) then
magic:push(block10);
end;
local block11 = _self.board[1][2];
if ((block11 ~= nil) and (block11.color == _G.hash("magic"))) then
magic:push(block11);
end;
local block12 = _self.board[1][3];
if ((block12 ~= nil) and (block12.color == _G.hash("magic"))) then
magic:push(block12);
end;
local block13 = _self.board[1][4];
if ((block13 ~= nil) and (block13.color == _G.hash("magic"))) then
magic:push(block13);
end;
local block14 = _self.board[1][5];
if ((block14 ~= nil) and (block14.color == _G.hash("magic"))) then
magic:push(block14);
end;
local block15 = _self.board[1][6];
if ((block15 ~= nil) and (block15.color == _G.hash("magic"))) then
magic:push(block15);
end;
local block16 = _self.board[1][7];
if ((block16 ~= nil) and (block16.color == _G.hash("magic"))) then
magic:push(block16);
end;
local block17 = _self.board[1][8];
if ((block17 ~= nil) and (block17.color == _G.hash("magic"))) then
magic:push(block17);
end;
local block18 = _self.board[2][0];
if ((block18 ~= nil) and (block18.color == _G.hash("magic"))) then
magic:push(block18);
end;
local block19 = _self.board[2][1];
if ((block19 ~= nil) and (block19.color == _G.hash("magic"))) then
magic:push(block19);
end;
local block20 = _self.board[2][2];
if ((block20 ~= nil) and (block20.color == _G.hash("magic"))) then
magic:push(block20);
end;
local block21 = _self.board[2][3];
if ((block21 ~= nil) and (block21.color == _G.hash("magic"))) then
magic:push(block21);
end;
local block22 = _self.board[2][4];
if ((block22 ~= nil) and (block22.color == _G.hash("magic"))) then
magic:push(block22);
end;
local block23 = _self.board[2][5];
if ((block23 ~= nil) and (block23.color == _G.hash("magic"))) then
magic:push(block23);
end;
local block24 = _self.board[2][6];
if ((block24 ~= nil) and (block24.color == _G.hash("magic"))) then
magic:push(block24);
end;
local block25 = _self.board[2][7];
if ((block25 ~= nil) and (block25.color == _G.hash("magic"))) then
magic:push(block25);
end;
local block26 = _self.board[2][8];
if ((block26 ~= nil) and (block26.color == _G.hash("magic"))) then
magic:push(block26);
end;
local block27 = _self.board[3][0];
if ((block27 ~= nil) and (block27.color == _G.hash("magic"))) then
magic:push(block27);
end;
local block28 = _self.board[3][1];
if ((block28 ~= nil) and (block28.color == _G.hash("magic"))) then
magic:push(block28);
end;
local block29 = _self.board[3][2];
if ((block29 ~= nil) and (block29.color == _G.hash("magic"))) then
magic:push(block29);
end;
local block30 = _self.board[3][3];
if ((block30 ~= nil) and (block30.color == _G.hash("magic"))) then
magic:push(block30);
end;
local block31 = _self.board[3][4];
if ((block31 ~= nil) and (block31.color == _G.hash("magic"))) then
magic:push(block31);
end;
local block32 = _self.board[3][5];
if ((block32 ~= nil) and (block32.color == _G.hash("magic"))) then
magic:push(block32);
end;
local block33 = _self.board[3][6];
if ((block33 ~= nil) and (block33.color == _G.hash("magic"))) then
magic:push(block33);
end;
local block34 = _self.board[3][7];
if ((block34 ~= nil) and (block34.color == _G.hash("magic"))) then
magic:push(block34);
end;
local block35 = _self.board[3][8];
if ((block35 ~= nil) and (block35.color == _G.hash("magic"))) then
magic:push(block35);
end;
local block36 = _self.board[4][0];
if ((block36 ~= nil) and (block36.color == _G.hash("magic"))) then
magic:push(block36);
end;
local block37 = _self.board[4][1];
if ((block37 ~= nil) and (block37.color == _G.hash("magic"))) then
magic:push(block37);
end;
local block38 = _self.board[4][2];
if ((block38 ~= nil) and (block38.color == _G.hash("magic"))) then
magic:push(block38);
end;
local block39 = _self.board[4][3];
if ((block39 ~= nil) and (block39.color == _G.hash("magic"))) then
magic:push(block39);
end;
local block40 = _self.board[4][4];
if ((block40 ~= nil) and (block40.color == _G.hash("magic"))) then
magic:push(block40);
end;
local block41 = _self.board[4][5];
if ((block41 ~= nil) and (block41.color == _G.hash("magic"))) then
magic:push(block41);
end;
local block42 = _self.board[4][6];
if ((block42 ~= nil) and (block42.color == _G.hash("magic"))) then
magic:push(block42);
end;
local block43 = _self.board[4][7];
if ((block43 ~= nil) and (block43.color == _G.hash("magic"))) then
magic:push(block43);
end;
local block44 = _self.board[4][8];
if ((block44 ~= nil) and (block44.color == _G.hash("magic"))) then
magic:push(block44);
end;
local block45 = _self.board[5][0];
if ((block45 ~= nil) and (block45.color == _G.hash("magic"))) then
magic:push(block45);
end;
local block46 = _self.board[5][1];
if ((block46 ~= nil) and (block46.color == _G.hash("magic"))) then
magic:push(block46);
end;
local block47 = _self.board[5][2];
if ((block47 ~= nil) and (block47.color == _G.hash("magic"))) then
magic:push(block47);
end;
local block48 = _self.board[5][3];
if ((block48 ~= nil) and (block48.color == _G.hash("magic"))) then
magic:push(block48);
end;
local block49 = _self.board[5][4];
if ((block49 ~= nil) and (block49.color == _G.hash("magic"))) then
magic:push(block49);
end;
local block50 = _self.board[5][5];
if ((block50 ~= nil) and (block50.color == _G.hash("magic"))) then
magic:push(block50);
end;
local block51 = _self.board[5][6];
if ((block51 ~= nil) and (block51.color == _G.hash("magic"))) then
magic:push(block51);
end;
local block52 = _self.board[5][7];
if ((block52 ~= nil) and (block52.color == _G.hash("magic"))) then
magic:push(block52);
end;
local block53 = _self.board[5][8];
if ((block53 ~= nil) and (block53.color == _G.hash("magic"))) then
magic:push(block53);
end;
local block54 = _self.board[6][0];
if ((block54 ~= nil) and (block54.color == _G.hash("magic"))) then
magic:push(block54);
end;
local block55 = _self.board[6][1];
if ((block55 ~= nil) and (block55.color == _G.hash("magic"))) then
magic:push(block55);
end;
local block56 = _self.board[6][2];
if ((block56 ~= nil) and (block56.color == _G.hash("magic"))) then
magic:push(block56);
end;
local block57 = _self.board[6][3];
if ((block57 ~= nil) and (block57.color == _G.hash("magic"))) then
magic:push(block57);
end;
local block58 = _self.board[6][4];
if ((block58 ~= nil) and (block58.color == _G.hash("magic"))) then
magic:push(block58);
end;
local block59 = _self.board[6][5];
if ((block59 ~= nil) and (block59.color == _G.hash("magic"))) then
magic:push(block59);
end;
local block60 = _self.board[6][6];
if ((block60 ~= nil) and (block60.color == _G.hash("magic"))) then
magic:push(block60);
end;
local block61 = _self.board[6][7];
if ((block61 ~= nil) and (block61.color == _G.hash("magic"))) then
magic:push(block61);
end;
local block62 = _self.board[6][8];
if ((block62 ~= nil) and (block62.color == _G.hash("magic"))) then
magic:push(block62);
end;
do return magic end;
end
Board.count_magic_regions = function(blocks)
local maxr = 0;
local _g = 0;
while (_g < blocks.length) do
local m = blocks[_g];
_g = _g + 1;
if (m.region > maxr) then
maxr = m.region;
end;
end;
do return maxr end;
end
Board.adjacent_magic_blocks = function(blocks,block)
do return blocks:filter(function(e)
if (not ((block.x == e.x) and (_G.math.abs(block.y - e.y) == 1))) then
if (block.y == e.y) then
do return _G.math.abs(block.x - e.x) == 1 end;
else
do return false end;
end;
else
do return true end;
end;
end) end;
end
Board.mark_neighbors = function(blocks,block,region)
local neighbors = Board.adjacent_magic_blocks(blocks, block);
local _g = 0;
while (_g < neighbors.length) do
local m = neighbors[_g];
_g = _g + 1;
if (m.region == nil) then
m.region = region;
Board.mark_neighbors(blocks, m, region);
end;
end;
end
Board.mark_magic_regions = function(_self)
local m_blocks = Board.magic_blocks(_self);
local _g = 0;
while (_g < m_blocks.length) do
local m = m_blocks[_g];
_g = _g + 1;
m.region = nil;
m.neighbors = Board.adjacent_magic_blocks(m_blocks, m).length;
end;
local region = 1;
local _g1 = 0;
while (_g1 < m_blocks.length) do
local m1 = m_blocks[_g1];
_g1 = _g1 + 1;
if (m1.region == nil) then
m1.region = region;
Board.mark_neighbors(m_blocks, m1, region);
region = region + 1;
end;
end;
do return m_blocks end;
end
Board.highlight_magic = function(blocks)
local _g = 0;
while (_g < blocks.length) do
local m = blocks[_g];
_g = _g + 1;
if (m.neighbors > 0) then
_G.msg.post(m.id, Messages.lights_on);
else
_G.msg.post(m.id, Messages.lights_off);
end;
end;
end
Board.clear_board = function(_self)
local _g = 0;
local _g1 = _self.board;
while (_g < _g1.length) do
local col = _g1[_g];
_g = _g + 1;
local _g2 = 0;
local _g11 = col.length;
while (_g2 < _g11) do
_g2 = _g2 + 1;
local i = _g2 - 1;
if (col[i] ~= nil) then
_G.go.delete(col[i].id);
col[i] = nil;
end;
end;
end;
end
Board.same_color_neighbors = function(_self,x,y)
do return _self.blocks:filter(function(v)
if (((v.id ~= _self.board[x][y].id) and (((v.x == x) or (v.x == (x - 1))) or (v.x == (x + 1)))) and (((v.y == y) or (v.y == (y - 1))) or (v.y == (y + 1)))) then
do return v.color == _self.board[x][y].color end;
else
do return false end;
end;
end) end;
end
Board.remove_chain = function(_self)
local _g = 0;
local _g1 = _self.chain;
while (_g < _g1.length) do
local c = _g1[_g];
_g = _g + 1;
_self.board[c.x][c.y] = Board.REMOVING_BLOCK;
_G.go.delete(c.id);
end;
_self.chain = _hx_tab_array({}, 0);
end
Board.nilremoved = function(_self)
local _g = 0;
local _g1 = _self.board;
while (_g < _g1.length) do
local col = _g1[_g];
_g = _g + 1;
local _g2 = 0;
local _g11 = col.length;
while (_g2 < _g11) do
_g2 = _g2 + 1;
local i = _g2 - 1;
if (col[i] == Board.REMOVING_BLOCK) then
col[i] = nil;
end;
end;
end;
end
Board.in_blocklist = function(blocks,block)
local _g = 0;
while (_g < blocks.length) do
local b = blocks[_g];
_g = _g + 1;
if (b.id == block) then
do return true end;
end;
end;
do return false end;
end
Board.dropspots = function(_self)
local spots = _hx_tab_array({}, 0);
local _g = 0;
while (_g < 7) do
_g = _g + 1;
local x = _g - 1;
local _g1 = 0;
while (_g1 < 9) do
_g1 = _g1 + 1;
local y = _g1 - 1;
if (_self.board[x][y] == nil) then
spots:push(_hx_o({__fields__={x=true,y=true},x=x,y=y}));
break;
end;
end;
end;
local _g11 = 1;
local _g2 = spots.length - 3;
while (_g11 < _g2) do
_g11 = _g11 + 1;
spots:splice(Std.random(spots.length), 1);
end;
do return spots end;
end
Board.drop = function(_self,spots)
local _g = 0;
while (_g < spots.length) do
local s = spots[_g];
_g = _g + 1;
local pos = _G.vmath.vector3();
pos.x = 80. + (80 * s.x);
pos.y = 1000;
local c = Board.colors[Std.random(Board.colors.length)];
local id = _G.factory.create("#blockfactory", pos, nil, ({color = c}));
_G.go.animate(id, "position.y", _G.go.PLAYBACK_ONCE_FORWARD, 90. + (80 * s.y), _G.go.EASING_OUTBOUNCE, 0.5);
_G.go.set(id, "position.z", (s.x * -0.1) + (s.y * 0.01));
_self.board[s.x][s.y] = _hx_o({__fields__={id=true,color=true,x=true,y=true},id=id,color=c,x=s.x,y=s.y});
end;
Board.build_blocklist(_self);
end
Board.slide_board = function(_self)
local _g = 0;
while (_g < 7) do
_g = _g + 1;
local x = _g - 1;
local dy = 0;
local _g1 = 0;
while (_g1 < 9) do
_g1 = _g1 + 1;
local y = _g1 - 1;
if (_self.board[x][y] ~= nil) then
if (dy > 0) then
_self.board[x][y - dy] = _self.board[x][y];
_self.board[x][y] = nil;
_self.board[x][y - dy].y = _self.board[x][y - dy].y - dy;
_G.go.animate(_self.board[x][y - dy].id, "position.y", _G.go.PLAYBACK_ONCE_FORWARD, 90. + (80 * (y - dy)), _G.go.EASING_OUTBOUNCE, 0.3);
_G.go.set(_self.board[x][y - dy].id, "position.z", (x * -0.1) + ((y - dy) * 0.01));
end;
else
dy = dy + 1;
end;
end;
end;
Board.build_blocklist(_self);
end
Board.build_board = function(_self)
_G.math.randomseed(_G.os.time());
local pos = _G.vmath.vector3();
local _g = 0;
while (_g < 7) do
_g = _g + 1;
local x = _g - 1;
pos.x = 80. + (80 * x);
_self.board[x] = _hx_tab_array({}, 0);
local _g1 = 0;
while (_g1 < 9) do
_g1 = _g1 + 1;
local y = _g1 - 1;
pos.y = 90. + (80 * y);
pos.z = (x * -0.1) + (y * 0.01);
local c = Board.colors[Std.random(Board.colors.length)];
local id = _G.factory.create("#blockfactory", pos, nil, ({color = c}));
_self.board[x][y] = _hx_o({__fields__={id=true,color=true,x=true,y=true},id=id,color=c,x=x,y=y});
end;
end;
local y1 = 0;
local step = Std.int(9 / _self.num_magic);
while (y1 < 9) do
local set = false;
while (not set) do
local rand_y = Std.int(_G.math.random(_G.math.floor(y1), Math.min(8, _G.math.floor(y1 + (9 / _self.num_magic)))));
local rand_x = Std.int(_G.math.random(0, 6));
if (_self.board[rand_x][rand_y].color ~= _G.hash("magic")) then
_G.msg.post(_self.board[rand_x][rand_y].id, Messages.make_magic);
_self.board[rand_x][rand_y].color = _G.hash("magic");
set = true;
end;
end;
y1 = y1 + step;
end;
Board.build_blocklist(_self);
local magic_blocks = Board.mark_magic_regions(_self);
if (Board.count_magic_regions(magic_blocks) == 1) then
Board.clear_board(_self);
Board.build_board(_self);
end;
Board.highlight_magic(magic_blocks);
end
Board.slide_magic_blocks = function(_self)
local _g = 0;
while (_g < 9) do
_g = _g + 1;
local y = _g - 1;
local row_m = _hx_tab_array({}, 0);
local _g1 = 0;
while (_g1 < 7) do
_g1 = _g1 + 1;
local x = _g1 - 1;
if (((_self.board[x][y] ~= nil) and (_self.board[x][y] ~= Board.REMOVING_BLOCK)) and (_self.board[x][y].color == _G.hash("magic"))) then
row_m:push(_self.board[x][y]);
end;
end;
local mc = row_m.length + 1;
while (row_m.length < mc) do
mc = row_m.length;