-
Notifications
You must be signed in to change notification settings - Fork 0
/
level1.lua
executable file
·890 lines (454 loc) · 14.2 KB
/
level1.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
module(..., package.seeall)
new = function ( params )
local localGroup = display.newGroup()
local physics = require("physics")
local calcScore = require("calcScore")
local popUpEnd = require("popUpEnd")
local insertScore = require("insertScore")
local PP_params = {world = 1, level = 1}
local timeValue = 0
tmr = nil
local ui = require("ui")
--print(display.contentWidth)
--print(display.contentHeight)
physics.start()
--physics.setDrawMode( "hybrid" )
if background == nil then
print("ok")
end
if music == nil then
bgMusic = audio.loadStream("song.mp3")
bgMusicChannel = audio.play( bgMusic, { loops=-1})
audio.fade({ channel=1, time=0, volume=0.2 } )
audio.fade({ channel=1, time=3000, volume=0.5 } )
--local availableChannel = audio.findFreeChannel()
--audio.play( backgroundMusic, { channel=availableChannel, lopps = -1 } )
music = 1
end
local background = display.newImage("bg.png")
background:setReferencePoint(display.TopLeftReferencePoint)
background.x = 0
background.y = 0
background.xScale = display.contentWidth / background.contentWidth
background.yScale = display.contentHeight / background.contentHeight
--localGroup:insert(background)
--background.xScale = 1.78
--background.yScale = 1.78
local dietro = display.newGroup()
local oggetti = display.newGroup()
local palla = display.newGroup()
local btns = display.newGroup()
dietro:insert(background)
local accNumber = 0
local points = display.newText( accNumber, 35, 12, native.systemFont, 35 )
points:setReferencePoint(display.TopLeftReferencePoint)
points.x = 0
points.y = 0
points:setTextColor(255, 32 ,25)
--localGroup:insert(points)
dietro:insert(points)
local muro_sx = display.newRect(0, 0, 1, display.contentHeight)
--localGroup:insert(muro_sx)
local muro_dx = display.newRect(display.contentWidth, 0, 1, display.contentHeight)
--localGroup:insert(muro_dx)
muro_dx:setReferencePoint(display.TopLeftReferencePoint)
physics.addBody(muro_sx, "static",{bounce = 0.3, friction = 0.5})
physics.addBody(muro_dx, "static",{bounce = 0.3, friction = 0.5})
dietro:insert(muro_sx)
dietro:insert(muro_dx)
local physicsData = (require "universal").physicsData()
local pinguino = display.newImage("pinguino.png")
pinguino:setReferencePoint(display.CenterReferencePoint)
pinguino.x = 105
pinguino.y = 88
pinguino.rotation = 105
--localGroup:insert(pinguino)
palla:insert(pinguino)
physics.addBody(pinguino, physicsData:get("pinguino"))
local p_1 = display.newImage("p_1.png")
p_1:setReferencePoint(display.CenterReferencePoint)
p_1.x = 125
p_1.y = 188
p_1.rotation = 23
p_1.type = "p_1"
--localGroup:insert(p_1)
oggetti:insert(p_1)
physics.addBody(p_1, "static", physicsData:get("p_1"))
local p_2 = display.newImage("p_3.png")
p_2.x = 285
p_2.y = 205
p_2.type = "p_2"
--localGroup:insert(p_2)
oggetti:insert(p_2)
physics.addBody(p_2, "static", physicsData:get("p_3"))
local p_3 = display.newImage("p_2.png")
p_3.x = 437
p_3.y = 90
p_3.rotation = 190
p_3.type = "p_3"
--localGroup:insert(p_3)
oggetti:insert(p_3)
physics.addBody(p_3, "static", physicsData:get("p_2"))
local p_4 = display.newImage("p_4.png")
p_4.x = 558
p_4.y = 218
p_4.rotation = -105
p_4.type = "p_4"
--localGroup:insert(p_4)
physics.addBody(p_4, "static", physicsData:get("p_4"))
oggetti:insert(p_4)
local p_5 = display.newImage("p_4.png")
p_5.x = 585
p_5.y = 363
p_5.rotation = -95
p_5.type = "p_5"
--localGroup:insert(p_5)
physics.addBody(p_5, "static", physicsData:get("p_4"))
oggetti:insert(p_5)
local p_6 = display.newImage("p_4.png")
p_6.x = 590
p_6.y = 512
p_6.rotation = -88
p_6.type = "p_6"
--localGroup:insert(p_6)
physics.addBody(p_6, "static", physicsData:get("p_4"))
oggetti:insert(p_6)
local p_7 = display.newImage("p_4.png")
p_7.x = 578
p_7.y = 660
p_7.rotation = -83
p_7.type = "p_7"
--localGroup:insert(p_7)
physics.addBody(p_7, "static", physicsData:get("p_4"))
oggetti:insert(p_7)
local p_8 = display.newImage("p_2.png")
p_8.x = 487
p_8.y = 810
p_8.rotation = -25
p_8.type = "p_8"
--localGroup:insert(p_8)
physics.addBody(p_8, "static", physicsData:get("p_2"))
oggetti:insert(p_8)
local p_9 = display.newImage("p_10.png")
p_9.x = 320
p_9.y = 805
p_9.rotation = 20
p_9.type = "p_9"
--localGroup:insert(p_9)
physics.addBody(p_9, "static", physicsData:get("p_10"))
oggetti:insert(p_9)
local p_10 = display.newImage("p_5r.png")
p_10.x = 180
p_10.y = 718
p_10.rotation = 20
p_10.type = "p_10"
--localGroup:insert(p_10)
physics.addBody(p_10, "static", physicsData:get("p_5r"))
oggetti:insert(p_10)
local meta = display.newImage("meta.png")
meta.x = 190
meta.y = 504
meta.type = "meta"
--localGroup:insert(meta)
physics.addBody(meta, "static")
oggetti:insert(meta)
local acc = display.newImage("acc.png")
acc.x = 55
acc.y = 909
--localGroup:insert(acc)
btns:insert(acc)
local pause = display.newImage("pause.png")
pause:setReferencePoint(display.TopRightReferencePoint)
pause.x = display.contentWidth - 10
pause.y = 10
btns:insert(pause)
local i = 0
local num = 0
local bo = 0
local incr = 0
--[[function rotazione(event)
local pinguino_rot = math.ceil(pinguino.rotation)
--print(pinguino.rotation)
--print(pinguino_rot)
if (bo == 0) then
--print(pinguino_rot)
--print(i)
if ((pinguino_rot <=360) and (pinguino_rot >=0)) then
num = pinguino_rot
bo = 1
else
i = i + 360
if (i>pinguino_rot) then
--print ("ciao1")
i = i -360
num = pinguino_rot - i
bo = 1
end
end
else
--print ("ciao")
--print (num)
--print (incr)
if (incr >= num) then
Runtime:removeEventListener("enterFrame", rotazione)
else
pinguino.rotation = pinguino.rotation - 1
incr = incr + 1
end
end
end
]]--
--local number = 0
--local i = 0
local zone = "z0"
function collisioni2(event)
if (event.phase == "began") then
--print(i%3)
local type = event.other.type
if(type == "p_1") then
zone = "z1"
elseif(type == "p_2") then
zone = "z2"
elseif(type == "p_3") then
zone = "z3"
elseif(type == "p_4") then
zone = "z4"
elseif(type == "p_5") then
zone = "z5"
elseif(type == "p_6") then
zone = "z6"
elseif(type == "p_7") then
zone = "z7"
elseif(type == "p_8") then
zone = "z8"
elseif(type == "p_9") then
zone = "z9"
elseif(type == "p_10") then
zone = "z10"
elseif(type == "p_11") then
zone = "z11"
elseif(type == "meta") then
local score_value
meta.isBodyActive = false
pinguino.isBodyActive = false
transition.to( pinguino, { time=1000, x=meta.x, y=meta.y} )
--Runtime:addEventListener("enterFrame", rotazione)
score_value = calcScore:exec(score_value, accNumber)
print(score_value)
popUpEnd:init(PP_params, score_value, localGroup)
timer.cancel(tmr)
tmr = nil
acc:removeEventListener("touch", aumento)
pause:removeEventListener("touch", touchPopUp)
insertScore:go(PP_params, score_value)
--pinguino:setLinearVelocity(0, 0 )
--Runtime:removeEventListener("enterFrame", rotazione)
print("fatto")
end
end
end
function aumento(event)
if (event.phase == "ended") then
accNumber = accNumber + 1
points.text = accNumber
if (zone == "z0") then
pinguino:setLinearVelocity(700, 400)
elseif(zone == "z1") then
pinguino:setLinearVelocity(700, 300)
elseif(zone == "z2") then
pinguino:setLinearVelocity(600, -50)
elseif(zone == "z3") then
pinguino:setLinearVelocity(600, -100)
elseif(zone == "z4") then
pinguino:setLinearVelocity(100, 500)
elseif(zone == "z5") then
pinguino:setLinearVelocity(100, 500)
elseif(zone == "z6") then
pinguino:setLinearVelocity(100, 500)
elseif(zone == "z7") then
pinguino:setLinearVelocity(50, 500)
elseif(zone == "z8") then
pinguino:setLinearVelocity(-600, 300)
elseif(zone == "z9") then
pinguino:setLinearVelocity(-600, -50)
elseif(zone == "z10") then
pinguino:setLinearVelocity(-700, -250)
end
end
end
local count = 0
function popClosed()
physics.start()
count = 0
end
function popUp()
local popUpGroup = display.newGroup()
physics.pause()
--Runtime:removeEventListener("enterFrame", rotazione)
acc:removeEventListener("touch", aumento)
pause:removeEventListener("touch", touchPopUp)
local darkening = display.newImage("darkening.png")
darkening:setReferencePoint(display.TopLeftReferencePoint)
darkening.x = 0
darkening.y = 0
darkening.isVisible = true
darkening.alpha = 0.7
local popUp_bg = display.newImage( "popUp-bg.png" )
popUp_bg:setReferencePoint(display.BottomCenterReferencePoint)
popUp_bg.x = display.contentWidth / 2
popUp_bg.y = 0
popUp_bg.xScale = 1.5
popUp_bg.yScale = 1.5
popUp_bg.isVisible = true
popUp_bg.alpha = 0.9
transition.to(popUp_bg, { time=500, y=popUp_bg.contentHeight, transition=easing.outQuad})
local replay = display.newImage("replay.png")
replay:setReferencePoint(display.BottomLeftReferencePoint)
replay.x = 40
replay.y = -10
replay.xScale = 2
replay.yScale = 2
replay.isVisible = true
local select = display.newImage("select.png")
select:setReferencePoint(display.BottomLeftReferencePoint)
select.x = replay.contentWidth + 80
select.y = -10
select.xScale = 2
select.yScale = 2
select.isVisible = true
local ritorna = display.newImage("ritorna.png")
ritorna:setReferencePoint(display.BottomLeftReferencePoint)
ritorna.x = (replay.contentWidth * 2) + 120
ritorna.y = -10
ritorna.xScale = 2
ritorna.yScale = 2
ritorna.isVisible = true
local soundOn = display.newImage("sound-on.png")
soundOn:setReferencePoint(display.BottomLeftReferencePoint)
soundOn.x = display.contentWidth - soundOn.contentWidth - 40
soundOn.y = -10
soundOn.isVisible = false
soundOn.status = "on"
local soundOff = display.newImage("sound-off.png")
soundOff:setReferencePoint(display.BottomLeftReferencePoint)
soundOff.x = display.contentWidth - soundOff.contentWidth - 40
soundOff.y = -10
soundOff.status = "off"
function sound(event)
if (event.phase == "ended") then
if (event.target.status == "off") then
soundOn.isVisible = true
soundOff.isVisible = false
audio.stop(bgMusicChannel)
audio.rewind(bgMusic)
elseif (event.target.status == "on") then
soundOff.isVisible = true
soundOn.isVisible = false
audio.play(bgMusic, {loops = -1})
end
end
return true
end
transition.to(replay, { time=500, y=popUp_bg.contentHeight -35, transition=easing.outQuad})
transition.to(select, { time=500, y=popUp_bg.contentHeight -35, transition=easing.outQuad})
transition.to(ritorna, { time=500, y=popUp_bg.contentHeight -35, transition=easing.outQuad})
transition.to(soundOn, { time=500, y=popUp_bg.contentHeight -35, transition=easing.outQuad})
transition.to(soundOff, { time=500, y=popUp_bg.contentHeight -35, transition=easing.outQuad})
local touched = function ( event )
if event.phase == "ended" then
--Runtime:addEventListener("enterFrame", rotazione)
popUp_bg.isVisible = false
darkening.isVisible = false
replay.isVisible = false
select.isVisible = false
ritorna.isVisible = false
soundOn.isVisible = false
soundOff.isVisible = false
count = 0
physics.start()
tmr = timer.performWithDelay(1000, gt, -1)
acc:addEventListener("touch", aumento)
pause:addEventListener("touch", touchPopUp)
end
return true
end
function red(event)
if (event.phase == "ended") then
audio.stop(bgMusicChannel)
bgMusicChannel = nil
director:changeScene("red", "fade", "black")
end
end
function reload(event)
if (event.phase == "ended") then
count = 0
director:changeScene("level", "fade", "black")
end
return true
end
localGroup:insert( darkening )
localGroup:insert( popUp_bg )
localGroup:insert( replay )
localGroup:insert( select )
localGroup:insert( ritorna )
localGroup:insert( soundOn )
localGroup:insert( soundOff )
timer.cancel(tmr)
tmr = nil
ritorna:addEventListener( "touch" , touched )
--darkening:addEventListener( "touch" , touched )
replay:addEventListener("touch", reload)
soundOn:addEventListener("touch", sound)
soundOff:addEventListener("touch", sound)
select:addEventListener("touch", red)
count = 1
end
function resumePopUp()
if(count == 0) then
popUp()
count = 1
end
end
function touchPopUp(event)
print("not ended")
print(count)
if (event.phase == "ended" and count == 0) then
print("touched")
popUp()
count = 1
print(count)
end
end
function sospensione(event)
--if(event.type == "applicationSuspend" and count == 0) then
--physics.pause()
--director:openPopUp("popup", popClosed)
--count = 1
--end
if(event.type == "applicationResume" and count == 0) then
resumePopUp()
print("ciao")
end
--if(event.type == "applicationExit" and count == 0) then
-- physics.pause()
-- director:openPopUp("popup", popClosed)
-- count = 1
--end
end
function gt()
calcScore:get()
end
localGroup:insert(dietro)
localGroup:insert(oggetti)
localGroup:insert(palla)
localGroup:insert(btns)
Runtime:addEventListener("system", sospensione)
pinguino:addEventListener("collision", collisioni2)
acc:addEventListener("touch", aumento)
pause:addEventListener("touch", touchPopUp)
------------------------------------------
--Creare il timer per la durata del gioco
------------------------------------------
tmr = timer.performWithDelay(1000, gt, -1)
return localGroup
end