-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
1228 lines (1073 loc) · 43.1 KB
/
game.lua
File metadata and controls
1228 lines (1073 loc) · 43.1 KB
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
local composer = require( "composer" )
local physics = require("physics")
local json = require "json"
local scene = composer.newScene()
local loadSave = require("loadsave")
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
local clickFinger
local mirrorGroup
local gameGroup
local beamGroup
local maxBeams=100
local obs
local bg
local back
local mirror
local destructible = {}
local emitter = {}
local maxCharge = 180
local mapW = 16
local mapH = 9
local blockW = _W/mapW
local blockH = _H/mapH
local gameState
local endMsg
local targetsInLvl
local targetsDestroyed
local isLost = false
local explosion
--mirror collision filter
local catMirror = 1
local catFloor = 2
local catOther = 4
local mirrorCollisionFilter = { categoryBits = catMirror, maskBits = catMirror + catFloor }
local floorCollisionFilter = { categoryBits = catFloor, maskBits = catMirror + catOther }
local otherCollisionFilter = { categoryBits = catOther, maskBits = catFloor + catOther}
local endMsgSh
local lvlData = {
--level 1
{
winMsg = "hopefully not too difficult",
loseMsg = "how? I don't think that's even possible",
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,11, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{13, 0,13, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0,13,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
}
},
--level 2
{
winMsg = "TNT bad",
loseMsg = "Don't blow up the TNT",
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 9, 3, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 9, 3, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 9, 3, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0,},
{13, 0,11, 0, 0, 0, 9, 2, 3, 2, 0, 0, 0, 0, 0,13,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
}
},
-- level 3
{
winMsg = "floaty castle",
loseMsg = "unlucky",
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,11, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{13, 0,13, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0,13,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
}
},
-- level 4
{
winMsg = "everything is floating, and there are holes",
loseMsg = "Falls = lose",
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0,13, 0, 7, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 2, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{13, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 11, 0, 0, 9,13,},
{13,13, 0, 0, 0,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level 5
{
winMsg = "did you like my distraction???",
loseMsg = "Have to be quick" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
{ 0, 0, 2, 0, 2, 0, 2, 0, 7, 0, 2, 0, 2, 0, 2, 0,},
{11, 0, 6, 0, 6, 0, 6, 0, 0, 0, 6, 0, 6, 0, 6, 0,},
{13,13, 0,13, 0,13, 0,13,13,13, 0,13, 0,13, 0,13,},
},
},
-- -- level NEW 6
-- {
-- winMsg = "did you like my distraction???",
-- loseMsg = "well done" ,
-- ---[[
-- -- objects = {
-- -- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- -- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- -- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- -- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- -- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
-- --},
-- --]]
-- map = {
-- { 0, 0, 0, 0, 0, 0, 0, 0,12, 0, 9, 9, 0, 0, 0, 0,},
-- { 0, 0, 0, 7, 7, 7, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
-- { 0, 0, 0, 8, 6, 8, 0, 0,13, 0, 6, 0, 0, 0, 0, 0,},
-- { 0, 0, 0, 7, 8, 7, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
-- { 0, 0, 0, 0, 0, 0, 0, 0,13,13,13,13,13, 8, 7,13,},
-- { 0, 0, 0, 0, 0, 0, 0, 0,13, 6, 0, 0, 0, 0, 0, 0,},
-- { 0, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0, 0,},
-- {11, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0,12,},
-- {13, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0,13,},
-- },
-- },
-- level 6
{
winMsg = "completed",
loseMsg = "i dont think you can lose this one" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0,10,10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 2,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 8, 8, 8, 8, 8, 8, 8,13, 8, 8, 8, 8, 8, 8, 8, 8,},
{ 0, 0, 0, 0, 0, 0, 0, 0,13,13,13,13, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 2,10, 2, 2, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level 7
{
winMsg = "MAXIMUM MAX",
loseMsg = "u lost" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 9, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0,11, 0, 0, 0,13, 0, 6, 6, 6, 0,10, 0, 0, 0,10,},
{ 0,13,13, 0,13,13, 0,13, 0,13, 0, 0, 8, 0,10, 0,},
{ 0, 6, 0, 6, 0, 6, 0, 6, 6, 6, 0, 0, 0,10, 0, 0,},
{ 0,13, 0, 0, 0,13, 0,13, 0,13, 0, 0,10, 0,10, 0,},
{ 0, 6, 0,10, 0, 6, 0, 6, 0, 6, 0,10, 0, 0, 0,10,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
},
},
-- level 8
{
winMsg = "bolted mirrors are helpful",
loseMsg = "yeah... the floor is tnt" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 6, 0, 0,10, 0, 0, 0, 0, 0, 0, 0,10,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 6, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11, 0, 0, 0, 0,},
{ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,},
},
},
-- level NEW 9
{
winMsg = "u r won",
loseMsg = "u r losed" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0,12, 0, 9, 9, 0, 0, 0, 0,},
{ 0, 0, 0, 3, 7, 7, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 6, 6, 6, 0, 0, 4, 0, 6, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 7, 8, 7, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0,13,13,13,13,13, 8, 8,13,},
{ 0, 0, 0, 0, 0, 0, 0, 0,13, 6, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0, 0,},
{11, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0,12,},
{13, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 7, 0, 0,13,},
},
},
-- level 10
{
winMsg = "tricky?",
loseMsg = "can u move that emitter???!??!?!?!?!?!?!?!?!??!!11/!?1/?!!?1/?!1/!" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 9, 9,10, 0, 0, 0,},
{11, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 8, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 6, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0,13, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0,10, 0, 6,10, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 8, 0,13, 0, 2, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level 11
{
winMsg = "bolted mirrors for days",
loseMsg = "too many bolted mirrors?" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0,},
{ 0,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 2, 0,10,13,13,13,13,13,13,13,13,13,13,13, 6,},
{ 0, 2, 0, 0, 6,10, 0, 0, 0, 0, 0,10, 0, 0, 0, 0,},
{ 0, 2, 0, 0, 0, 0,10,13, 0,13, 0,13,13,13,13, 0,},
{ 0, 2, 0, 0, 0, 0, 0, 0, 0,10, 6, 0, 0, 0, 0, 0,},
{ 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10,},
{ 0,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level 12
{
winMsg = "2 emitters",
loseMsg = "REEEE" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{11, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 9, 0, 0,},
{ 4, 0, 0, 0, 0, 0,13, 0,13, 0, 0, 0, 0, 0, 0, 0,},
{ 4, 0, 0, 0,13, 0, 6, 0, 6, 0, 0, 0, 0, 0, 0,10,},
{ 4, 0,13, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,10,13,13,13,13,13,13, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0,},
{13, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level NEW 13
{
winMsg = "isn't that cool",
loseMsg = "ran out of time?" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 6, 0, 0,},
{ 0, 0, 0,13,13,13,13, 0, 0,13,13,13,13, 0, 0, 0,},
{ 0, 0,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,12, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0,11, 0, 0, 8, 8, 7, 7, 7, 7, 8, 8, 0, 0,12, 0,},
{ 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 0,13, 0,},
},
},
-- level NEW 14
{
winMsg = "Hope it wasn't too easy",
loseMsg = "Maybe an emitter is causing more harm than good???" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{11, 0, 0, 0, 0, 0,10, 0,13, 0, 9, 9, 0, 0, 0, 0,},
{13, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 6, 0,},
{ 6, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
{13,13,13,13,13, 8,13,13,13,13,13,13,13,13, 8,13,},
{ 0, 0, 0, 0, 0, 8, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
{ 6, 7, 0, 0, 0, 8, 0, 0,13, 0, 0, 0, 0, 0, 6, 0,},
{ 6, 7, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0,12, 0, 0,},
{ 7, 7, 0, 0, 0, 7, 0, 0,13, 0, 0, 0, 0, 8, 0, 0,},
},
},
-- level 15
{
winMsg = "yay u won.",
loseMsg = "wall'o'tnt" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0,13, 0, 3, 0, 0, 0, 0, 0, 9, 0, 0,},
{ 0, 0, 0, 0, 0,13, 6, 3, 0, 0, 0, 0, 0, 0, 0, 0,},
{11, 0, 0, 0, 0, 4, 0, 3, 6, 0, 0, 0, 0, 0, 0, 0,},
{ 8, 0, 0, 0, 0, 4, 6, 3, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0,13,10, 3, 6, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0,13, 6, 3, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0,13, 0, 7, 8, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 4, 6, 4, 0, 0, 0, 0, 0,10, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
},
},
-- level 16
{
winMsg = "underground digging",
loseMsg = "darn it" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10, 9,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 2, 0, 0, 7, 0, 0, 0, 0, 0, 0, 2, 0, 0,},
{ 0, 0, 6, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0,10,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0,10, 0, 7, 6, 7,11, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 8, 8,13, 8, 8, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0,10, 8, 8,10, 8,13, 0, 0,13, 0,},
},
},
-- level 17
{
winMsg = "Claw ",
loseMsg = "NOOOO!" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 9, 9, 0,},
{ 0, 0, 0,10, 0,10,10, 0,10, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 6, 0, 8, 0, 8, 0, 8, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 7, 6, 8, 6, 8, 6, 7, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 7, 7, 7, 8, 7, 7, 7, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0,10, 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0,11, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,10,},
},
},
-- level NEW 18
{
winMsg = "another win",
loseMsg = "Zigs zags" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{13, 0, 0, 0, 0, 0, 0, 6, 8, 6, 9, 9, 0, 0, 0, 0,},
{ 0,13, 0, 0, 6, 0, 0,13, 0,13, 0, 0, 6, 0, 0,13,},
{ 0, 0,13, 0, 0, 0,13, 0, 0, 0,13, 0, 0, 0,13, 0,},
{ 0, 0, 0,13, 0,13, 0, 7, 7, 7, 0,13, 0,13, 0, 0,},
{11, 0, 0, 0, 0,10, 0, 6,10, 6, 0,10, 0, 0, 0,12,},
{13, 6, 0,13, 0,13, 0, 7, 6, 7, 0,13, 0,13, 6,13,},
{ 0, 0,13, 0, 0, 0,13, 7, 0, 7,13, 0, 0, 0,13, 0,},
{ 0,13, 0, 0, 0, 0, 0, 8, 0,13, 0, 0, 0, 0, 0,13,},
{13, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0, 0,},
},
},
-- level NEW 19
{
winMsg = "Split",
loseMsg = "u lost" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 0, 0,},
{ 0, 0,11, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,},
{ 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0,},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
{ 0, 0, 7, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0,12, 0,},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13, 6,},
},
},
-- level 20
{
winMsg = "whaaaaa?????",
loseMsg = "what is this. someone help me pls" ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 8, 8, 0, 0, 0, 7, 0, 0,10, 0, 8, 9, 8,10,},
{ 0, 8, 0, 0,10, 0, 8, 8, 8, 0, 8, 0,10, 7, 0, 0,},
{10, 8, 8, 0, 0, 8, 8, 8, 8, 0, 8, 0, 0, 0,10, 6,},
{ 0,11, 0,10, 0, 8, 0, 7, 7, 8, 8, 8, 8, 8, 8, 8,},
{ 0, 8, 8, 0, 0, 0, 0, 7, 7, 8, 8, 8, 8, 8, 8, 8,},
{ 0, 0, 8, 8, 0, 0, 8, 8, 8, 8, 8, 8, 8, 0,10, 7,},
{ 0, 8, 8, 0, 0, 0,10, 8, 8, 8, 8, 8, 0, 0, 0, 6,},
{ 0, 0, 8, 0,10, 0,10, 8, 8, 8, 8, 0,10, 0, 0, 7,},
{ 6, 8,10, 0, 0, 0, 0, 8, 8, 8, 8,10, 0, 8, 0, 0,},
},
},
-- level NEW 21
{
winMsg = "Last level! You won the game",
loseMsg = "get the order of destruction right the nu win." ,
---[[
-- objects = {
-- {type = 'emitter', x = 0.3*_W, y = 0.5*_H, rot = 90,},
-- --{type = 'noReflect', x = 0.3*_W, y = 0.3*_H, w = 0.05*_W, h = 0.05*_W, rot = 8,},
-- {type = 'mirror', x = _W, y = 0.5*_H , w = 0.1*_W, h = _H, rot = 67,},
-- {type = "receiver", x = 0.7*_W, y = 0.3*_H,},
-- {type = "receiver", x = 0.7*_W, y = 0.7*_H,},
--},
--]]
map = {
{ 0, 0, 7, 0, 0,13, 0, 0, 0, 9, 9,13, 0, 0, 0, 0,},
{ 0, 6, 7, 0, 0,13, 0, 0, 0, 0, 0,13, 0, 6, 0, 0,},
{ 0, 0, 7, 0, 0,13, 0, 0, 0, 0, 0,13, 0, 7, 0, 0,},
{13, 8, 7, 8, 8, 8, 0,12, 0,11, 0,13,13,13, 8,13,},
{13, 8, 7, 8,13,13, 0, 8, 0, 8, 0, 8, 8,13, 8,13,},
{ 0, 0, 0, 0, 6,13, 0, 0, 0,13, 0,13, 6, 7, 0, 0,},
{ 0,10, 0, 0, 0,13, 0, 0, 0, 0, 0,13, 7, 0, 0, 0,},
{ 0, 0, 0, 0, 0,13, 0, 0, 0, 0,10, 8, 0, 0,10, 0,},
{ 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0,13, 0, 0, 0, 0,},
},
},
}
local function backFunc (e)
if e.phase == "ended" then
composer.gotoScene("lvlSelect", {effect = "zoomInOut", time = 1000,})
end
end
-- print(lvlData[1].objects[].y)
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
local function gameOver ()
isLost = true
timer.performWithDelay( 1500, function() isLost = false end )
gameState = "end"
timer.performWithDelay(3000, function() backFunc({phase = 'ended'}) end )
endMsgSh = display.newText( {parent = scene.view, align = "center", text = lvlData[lvl].loseMsg, x = 0.52*_W, y = 0.52*_H, width = _W*0.95, fontSize = 200, font = "PermanentMarker-Regular.ttf"} )
endMsgSh:setFillColor(0,0,0,0.5)
endMsgSh.xScale = 0.5
endMsgSh.yScale = 0.5
endMsgSh.alpha = 0
endMsg = display.newText({parent = scene.view, align = "center", text = lvlData[lvl].loseMsg, x = 0.5*_W, y = 0.5*_H, width = _W*0.95, fontSize = 200, font = "PermanentMarker-Regular.ttf"})
endMsg.xScale = 0.5
endMsg.yScale = 0.5
endMsg.alpha = 0
transition.to( endMsgSh, {delay = 750, time = 1000, xScale = 1, yScale = 1, alpha = 1, transition = easing.inOutBounce} )
transition.to( endMsg, {delay = 750, time = 1000, xScale = 1, yScale = 1, alpha = 1, transition = easing.inOutBounce} )
physics.pause()
back:removeEventListener('touch', backFunc)
end
local function makeParticles(filename)
local filePath = system.pathForFile( filename )
local f = io.open( filePath, "r" )
local fileData = f:read( "*a" )
f:close()
-- Decode the string
local emitterParams = json.decode( fileData )
--emitterParams.absolutePosition = true
-- Create the emitter with the decoded parameters
local emitter1 = display.newEmitter( emitterParams )
return emitter1
end
-- -- Center the emitter within the content area
-- emitter1.x = display.contentCenterX
-- emitter1.y = display.contentCenterY
local function clearObject( object )
display.remove( object )
object = nil
end
local function drawBeam( startX, startY, endX, endY )
-- Draw a series of overlapping lines to represent the beam
local beam1 = display.newLine( beamGroup, startX, startY, endX, endY )
beam1.strokeWidth = 2 ; beam1:setStrokeColor( 1, 0.312, 0.157, 1 ) ; beam1.blendMode = "add" ; beam1:toBack()
local beam2 = display.newLine( beamGroup, startX, startY, endX, endY )
beam2.strokeWidth = 4 ; beam2:setStrokeColor( 1, 0.312, 0.157, 0.706 ) ; beam2.blendMode = "add" ; beam2:toBack()
local beam3 = display.newLine( beamGroup, startX, startY, endX, endY )
beam3.strokeWidth = 6 ; beam3:setStrokeColor( 1, 0.196, 0.157, 0.392 ) ; beam3.blendMode = "add" ; beam3:toBack()
end
-- local function resetGroup()
-- -- print(beamGroup.numChildren)
-- -- Clear all beams/bursts from display
-- for i = beamGroup.numChildren,1,-1 do
-- local child = beamGroup[i]
-- display.remove( child )
-- child = nil
-- end
--
-- -- Reset beam group alpha
-- beamGroup.alpha = 1
--
-- end
local function resetGroup(g)
-- print(g.numChildren)
-- Clear all from display
if g ~= nil then
for i = g.numChildren,1,-1 do
local child = g[i]
display.remove( child )
child = nil
end
g.alpha = 1
end
-- Reset group alpha
end
local function bang ()
print("bang")
audio.play(explosion)
end
local function castRay( startX, startY, endX, endY )
-- Perform ray cast
local hits = physics.rayCast( startX, startY, endX, endY, "closest" )
-- There is a hit; calculate the entire ray sequence (initial ray and reflections)
if ( hits and beamGroup.numChildren <= maxBeams ) then
-- Store first hit to variable (just the "closest" hit was requested, so use 'hits[1]')
local hitFirst = hits[1]
-- Store the hit X and Y position to local variables
local hitX, hitY = hitFirst.position.x, hitFirst.position.y
-- Place a visual "burst" at the hit point and animate it
local burst = display.newImageRect( beamGroup, "burst.png", 64, 64 )
burst.rotation = rnd(0,360)
burst.x, burst.y = hitX, hitY
burst.blendMode = "add"
transition.to( burst, { time=1, onComplete=clearObject } )
-- Draw the next beam
drawBeam( startX, startY, hitX, hitY )
if hitFirst.object.id == "noReflect" then
--transition.to( beamGroup, { time=800, delay=400, alpha=0, onComplete=resetGroup } )
elseif hitFirst.object.id == "canDest" then
if hitFirst.object.type == 'tnt' then
hitFirst.object.charge = hitFirst.object.charge + 0.8
else
hitFirst.object.charge = hitFirst.object.charge + 1
end
if hitFirst.object.charge >= maxCharge then
local emitter
if hitFirst.object.emitter ~= nil then
display.remove(hitFirst.object.emitter)
end
print("value correct")
physics.removeBody(hitFirst.object)
explosion = audio.loadSound( "firework_medium_distant_explosion.mp3" )
audio.play( explosion )
if hitFirst.object.type == "tnt" then
print("TNT")
timer.performWithDelay( 400, bang)
timer.performWithDelay( 700, bang)
timer.performWithDelay( 950, bang)
emitter = makeParticles("particle_texture.json")
gameOver()
elseif hitFirst.object.type == "target" then
print("target hit")
emitter = makeParticles("particle_texture.json")
targetsDestroyed = targetsDestroyed + 1
if targetsInLvl == targetsDestroyed then
gameState = "end"
endMsgSh = display.newText( {parent = scene.view, align = "center", text = lvlData[lvl].winMsg, x = 0.52*_W, y = 0.52*_H, width = 0.95*_W, fontSize = 200, font = "PermanentMarker-Regular.ttf"} )
endMsgSh:setFillColor(0,0,0,0.5)
endMsgSh.xScale = 0.5
endMsgSh.yScale = 0.5
endMsg = display.newText({parent = scene.view, align = "center", text = lvlData[lvl].winMsg, x = 0.5*_W, y = 0.5*_H, width = 0.95*_W, fontSize = 200, font = "PermanentMarker-Regular.ttf"})
endMsg.xScale = 0.5
endMsg.yScale = 0.5
endMsgSh.alpha = 0
endMsg.alpha = 0
transition.to( endMsgSh, {delay = 750, time = 1000, xScale = 1, yScale = 1, alpha = 1, transition = easing.inOutBounce} )
transition.to( endMsg, {delay = 750, time = 1000, xScale = 1, yScale = 1, alpha = 1, transition = easing.inOutBounce} )
local winSnd = audio.loadSound( "zapsplat_multimedia_game_star_win_gain_x1_12387.mp3")
audio.play( winSnd )
timer.performWithDelay( 5000, function() backFunc({phase = 'ended'}) end )
physics.pause()
back:removeEventListener('touch', backFunc)
if lvl < numLvls then
saveData.locked[lvl+1] = false
print(lvl+1 .. "unlocked")
loadSave.saveTable(saveData, "scores.json")
end
end
else
emitter = makeParticles("particle_texture.json")
end
emitter.x = hitFirst.object.x
emitter.y = hitFirst.object.y
end
else
-- Check for and calculate the reflected ray
local reflectX, reflectY = physics.reflectRay( startX, startY, hitFirst )
local reflectLen = 2600
local reflectEndX = ( hitX + ( reflectX * reflectLen ) )
local reflectEndY = ( hitY + ( reflectY * reflectLen ) )
-- If the ray is reflected, cast another ray
if ( reflectX and reflectY ) then
castRay( hitX, hitY, reflectEndX, reflectEndY )
end
end
-- Else, ray casting sequence is complete
else
-- Draw the final beam
drawBeam( startX, startY, endX, endY )
end
end
local function updateGame (e)
-- Delete the beams
resetGroup(beamGroup)
if gameState == "playing" then
for i = 1, #destructible do
if destructible[i].charge > 0 and destructible[i].charge < maxCharge then
destructible[i].charge = destructible[i].charge - 0.1
destructible[i].alpha = 1-destructible[i].charge/maxCharge
-- destructible[i]:setFillColor(destructible[i].charge/maxCharge,0,0)
end
--checking if target leaves screen
if destructible[i] and destructible[i].type == 'target' then
if destructible[i].x > _W or destructible[i].x < 0 or destructible[i].y > _H or destructible[i].y < 0 then
gameOver()
end
end
end
for i =1,#emitter do
local xDest = emitter[i].x - (math.cos(math.rad(emitter[i].rotation)) * 2600)
local yDest = emitter[i].y - (math.sin(math.rad(emitter[i].rotation)) * 2600)
castRay( emitter[i].x,emitter[i].y, xDest, yDest )
end
end
if isLost == true then
scene.view.x = math.random(-20,20)
end
-- Calculate ending x/y of beam
-- local xDest = turret.x - (math.cos(math.rad(turret.rotation+90)) * 2600)
-- local yDest = turret.y - (math.sin(math.rad(turret.rotation+90)) * 2600)
-- Cast the initial ray
-- castRay( turret.x, turret.y, xDest, yDest )
end
function moveObj (event)
event.target.x = event.x
event.target.y = event.y
if event.phase == "began" then
display.getCurrentStage():setFocus( event.target, event.id )
elseif event.phase == "ended" then
display.getCurrentStage():setFocus( event.target, nil)
end
return true
end
local function clickAnim ()
transition.to( clickFinger, {delay = 0, time = 1000, xScale = 0.8, yScale = 0.8, alpha = 0.7, transition = easing.continuousLoop} )
transition.to( clickFinger, {delay = 1000, time = 1000, xScale = 0.8, yScale = 0.8, alpha = 0.7, transition = easing.continuousLoop} )
transition.to( clickFinger, {delay = 2000, time = 1000, alpha = 0} )
end
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
-- bg:setFillColor(0.5,0.5,0.5)
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
if lvl <= 7 then
bg = display.newImageRect( sceneGroup, "blurBG.png", _W, _H )
bg.x = 0.5*_W
bg.y = 0.5*_H
elseif lvl <= 14 then
bg = display.newImageRect( sceneGroup, "blurBG2.png", _W*1.1, _H*1.1 )
bg.x = 0.5*_W
bg.y = 0.5*_H
elseif lvl > 14 then
bg = display.newImageRect( sceneGroup, "blurBG3.png", _W*1, _H*1 )
bg.x = 0.5*_W
bg.y = 0.5*_H
end
back = display.newImageRect(sceneGroup, "backButton.png",0.1*_W, 0.1*_W )
back.x = 0.1*_W
back.y = 0.1*_H
targetsInLvl = 0
targetsDestroyed = 0
gameState = "playing"
gameGroup = display.newGroup()
sceneGroup:insert(gameGroup)
beamGroup = display.newGroup()
sceneGroup:insert(beamGroup)
mirrorGroup = display.newGroup()
sceneGroup:insert(mirrorGroup)
physics.start()
--physics.setDrawMode( "hybrid" )
physics.setGravity( 0, 9.8 )
--[[
for i = 1, #lvlData[lvl].objects do
if lvlData[lvl].objects[i].type == "emitter" then
turret = display.newImageRect( gameGroup, "turret.png", 48, 48 )
turret.rotation = lvlData[lvl].objects[i].rot
physics.addBody( turret, "dynamic", { radius=18 } )
turret.x, turret.y = lvlData[lvl].objects[i].x, lvlData[lvl].objects[i].y
elseif lvlData[lvl].objects[i].type == "noReflect" then
obs = display.newRect(gameGroup, lvlData[lvl].objects[i].x,
lvlData[lvl].objects[i].y,
lvlData[lvl].objects[i].w,
lvlData[lvl].objects[i].h)
obs.rotation = lvlData[lvl].objects[i].rot
physics.addBody(obs, "dynamic")
obs.id = "noReflect"
elseif lvlData[lvl].objects[i].type == "mirror" then
mirror = display.newRect(gameGroup,
lvlData[lvl].objects[i].x,
lvlData[lvl].objects[i].y,
lvlData[lvl].objects[i].w,
lvlData[lvl].objects[i].h)
mirror.rotation = lvlData[lvl].objects[i].rot
physics.addBody( mirror, "static" )
mirror:addEventListener("touch", moveObj)
elseif lvlData[lvl].objects[i].type == "receiver" then
local slot = #destructible + 1
destructible[slot] = display.newRect(gameGroup, lvlData[lvl].objects[i].x, lvlData[lvl].objects[i].y, 0.05*_W, 0.05*_W)
destructible[slot]:setFillColor(0,0,0)
destructible[slot]:setStrokeColor(0,0,0)
destructible[slot].strokeWidth = 4
physics.addBody( destructible[slot], "static")
destructible[slot].id = "canDest"
destructible[slot].charge = 0
else
print("ERROR: invalid type: " .. lvlData[lvl].objects[i].type)
native.showAlert( "ERROR", "invalid type:".. lvlData[lvl].objects[i].type, { "what?", "OMG!!!" })
end
end
--]]
if lvl == 1 then
clickFinger = display.newImageRect(sceneGroup, "click.png",0.05*_W, 0.05*_W)
clickFinger.x = 0.53*_W
clickFinger.y = 0.3*_H
clickFinger.xScale = 1.5
clickFinger.yScale = 1.5
timer.performWithDelay( 2000, clickAnim )
end
for y = 1, mapH do
for x = 1, mapW do
-- print(x,y)