-
Notifications
You must be signed in to change notification settings - Fork 2
/
levels.lua
991 lines (797 loc) · 20.8 KB
/
levels.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
-- Mark H Carolan
--
-- Stroople project
-- © 2010 Mark H Carolan, Gregory S Hooper
module(..., package.seeall)
require "words"
require "wordsHoriz"
require "menu"
require "score"
require "letters"
require "languages"
require "db"
require "spiral"
require "carousel"
--
-- Constants
--
local textHeight = 40
local textSpacing = textHeight * 1.5
local textSpacingH = textHeight * 2
local startScrollSpeed = .5 -- 0.1
local sectionLength = 3000
local topBorder = 40
local baseBorder = globals.H
local guagePosX = 90 -- (96 for my orig panel)
local guagePosMaxAddX = 40
local guagePosY =6
local deadScore = 0 -- make lower for debugging
local startLevel = 1 -- change for debugging
local gameTime = 120000
local extraTime = 30000
local levelComplete = false
local outgoingLevel, incomingLevel
local transitionTime = 1000 -- between levels
local normalLevels = 4 -- before master level
local masterLevel = 80
local maxMisses = 2
--
-- Tracking variables; reset each level play
--
local scrollSpeed
local scrollFunction
--
-- Created and destroyed each run thru the game
--
--
local levelMenu, mainMenu
local words1, wordsL, wordsR, wordsU, wordsD
local wordsH1, wordsH2, wordsH3, wordsH4, wordsCarousel, wordsSpiral
local endLevelLogo
--
-- Only needs to be created once
--
local scoreboard
local speedController
local blacking -- black backing for health display guage
local background
--
-- Set from main via init() only once
--
local fontName
local returnFunction
--
-- filled by entry dialog for high score
--
local nameField, hsRank, hsTime, hsScore
local nameIX = 1 -- create name in sim
local clearLevel, setLevel
local variableGameTime
local isAndroid = "Android" == system.getInfo("platformName")
local inputFontSize = 24
if isAndroid then
inputFontSize = 18
end
local function getSpeedController(levels)
local speedController = {}
-- Delay times for increasing speed:
speedController.timeTable = {10000, 10000, 10000, 10000, 10000, 10000,
10000, 10000, 10000, 10000, 10000, 10000}
-- Activate this one for quick testing
-- speedController.timeTable = {2000, 2000, 2000, 2000, 2000, 2000, 2000,
-- 2000, 2000, 2000, 2000, 2000, 2000, 2000} -- test only
-- Speed notch settings:
speedController.speedTable = {0.10, 0.11, 0.12, 0.13, .14, .15,
.16, .17, .18, .19, .20, .21, .22}
-- Level switches
local addLevelTime = 20000
-- for i = 1, #speedController.timeTable do
-- addLevelTime = addLevelTime + speedController.timeTable[i]
-- end
speedController.levelTime = addLevelTime
speedController.masterLevelTime = 40000
speedController.levelCount = levels
speedController.stIndex = 1
speedController.ttIndex = 1
speedController.startTime = 0
speedController.levelStartTime = 0
speedController.speed = 0
speedController.totalTime = 0
function speedController:start(startT, curLevel)
self.startLevel = curLevel
if curLevel > self.levelCount then curLevel = self.levelCount end
if self.currentLevel == self.levelCount then
self.hitLevelLimit = true
else
self.hitLevelLimit = false
end
self.currentLevel = curLevel
self.stIndex, self.ttIndex = 1, 1
self.totalTime = 0
self.startTime = startT
self.hitSpeedLimit = false
self.speed = self.speedTable[self.stIndex]
self.levelStartTime = startT
setLevel(self.currentLevel)
end
function speedController:getSpeed(elapsed)
if not self.hitSpeedLimit then
local curTimeOut = self.timeTable[self.ttIndex]
local curSpeed = self.speedTable[self.stIndex]
-- Commented out for testing constant speed
-- if (elapsed - self.startTime) >= curTimeOut then
--
-- self.startTime = elapsed
-- self.ttIndex = self.ttIndex + 1
-- if self.ttIndex >= #self.timeTable then
-- self.hitSpeedLimit = true
-- self.speed = self.speedTable[#self.speedTable] -- last element
-- else
-- self.stIndex = self.stIndex + 1
-- if self.stIndex >= #self.speedTable then
-- self.hitSpeedLimit = true -- speed already set in previous iteration
-- else
-- self.speed = self.speedTable[self.stIndex]
-- end
-- end
-- end
end
if not self.hitLevelLimit then
if elapsed - self.levelStartTime >= self.levelTime then
self.levelStartTime = elapsed
-- This is only if we are resetting speed at each level step-up
-- self.startTime = elapsed
-- self.hitSpeedLimit = false
-- self.ttIndex = 1
-- self.stIndex = 1
clearLevel(self.currentLevel)
self.currentLevel = self.currentLevel + 1
-- level 4 is double time
if self.currentLevel == 4 then
self.levelTime = self.levelTime * 2
end
if self.currentLevel >= self.levelCount then
self.hitLevelLimit = true
self.currentLevel = self.levelCount
db.print("final level", self.currentLevel)
else
db.print("Next level", self.currentLevel)
end
-- self.speed = self.speedTable[self.stIndex]
if self.currentLevel == self.startLevel then
setLevel(self.currentLevel)
end
end
else -- must be master level
if elapsed - self.levelStartTime >= self.masterLevelTime then
db.print("calling clearLevel", self.currentLevel)
self.levelStartTime = elapsed
clearLevel(self.currentLevel)
end
end -- not hitLevelLimit
return self.speed, self.currentLevel
end
function speedController:endLevel()
clearLevel(self.currentLevel)
end
function speedController:startLevel()
setLevel(self.currentLevel)
end
return speedController
end
-- Not a pretty visual. For testing.
local function plainTextDisplay(c, f, h)
local rgb = c or {0, 0, 0}
local box = display.newText("0", 0, 0, f, h)
box:setTextColor(rgb[1], rgb[2], rgb[3])
return box
end
local function createScoreboard()
local sb = display.newGroup()
sb:setReferencePoint(display.TopLeftReferencePoint)
sb.y = 0 -- globals.H
local pole = display.newRect(0, 0, 50, 30)
pole:setReferencePoint(display.TopLeftReferencePoint)
pole:setFillColor(255, 0, 0)
pole.y = guagePosY
pole.x = guagePosX
sb:insert(pole, false) -- index 1
sb.guage = pole
-- Now using bitmap
--local scoreBacking = display.newRect(0, 0, globals.W, 40)
--scoreBacking:setFillColor(0, 0, 0)
local scoreBacking = display.newImage("scoring_bar_3.png")
scoreBacking:setReferencePoint(display.TopLeftReferencePoint)
sb:insert(scoreBacking) -- index 2
scoreBacking.x = 0
scoreBacking.y = 0
local scoreBox = plainTextDisplay({200, 200, 200}, native.systemFont, 24)
sb:insert(scoreBox) -- index 3
scoreBox.x = 90
scoreBox.y = 20
sb.scoreBoxIndex = 3
local timeBox = plainTextDisplay({200, 200, 200}, native.systemFont, 24)
sb:insert(timeBox) -- index 4
timeBox.x = 240
timeBox.y = 20
sb.timeBoxIndex = 4
local miss = display.newCircle(0, 0, 5)
miss:setFillColor(255, 0, 0)
miss.strokewidth = 2
miss:setStrokeColor(100, 100, 100)
sb:insert(miss) -- index 5
miss.x = 40
miss.y = 22
sb.missIndex = 5
local hit = display.newCircle(0, 0, 5)
hit:setFillColor(0, 255, 0)
hit.strokewidth = 2
hit:setStrokeColor(100, 100, 100)
sb:insert(hit) -- index 6
hit.x = globals.W - 40
hit.y = 22
sb.hitIndex = 6
function sb:score(n)
self[self.scoreBoxIndex].text = n
if n > guagePosMaxAddX then n = guagePosMaxAddX end
pole.x = guagePosX + n
end
function sb:time(n)
local s = string.format("%.1f", n / 1000)
self[self.timeBoxIndex].text = s
end
return sb
end
local function lightController(object, max)
local on = false
local counter = 0
object.isVisible = false
return function(trigger)
if trigger then
object.isVisible = true
on = true
elseif on then
counter = counter + 1
if counter >= max then
on = false
counter = 0
object.isVisible = false
end
end
end
end
local function createWords()
words1 = words.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacing,
colorNames = languages.colorNames,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
words1.x = globals.W2
end
local function createWordsLR()
wordsL = words.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacing,
colorNames = languages.colorNames,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
wordsL.x = globals.W4
wordsR = words.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacing,
colorNames = languages.colorNames,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
wordsR.x = 3 * globals.W4
end
local function createWordsUD()
wordsD = words.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacing,
colorNames = languages.colorNames,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
wordsD.x = globals.W4
wordsU = words.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacing,
colorNames = languages.colorNames,
topBorder = topBorder,
baseBorder = baseBorder,
direction = -1
}
wordsU.x = 3 * globals.W4
end
local function createWordsH()
local leftX = -globals.W
local rightX = globals.W*2
wordsH1 = wordsHoriz.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacingH,
colorNames = languages.colorNames,
xMin = leftX,
xMax = globals.W + globals.W4,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
wordsH1.x = -globals.W
wordsH1.y = textHeight + textHeight/2
wordsH2 = wordsHoriz.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacingH,
colorNames = languages.colorNames,
xMin = leftX,
xMax = globals.W + globals.W4,
topBorder = topBorder,
baseBorder = baseBorder,
direction = 1
}
wordsH2.x = 0
wordsH2.y = textHeight + textHeight/2
wordsH3 = wordsHoriz.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacingH,
colorNames = languages.colorNames,
xMin = -globals.W4,
xMax = rightX,
topBorder = topBorder,
baseBorder = baseBorder,
direction = -1
}
wordsH3.x = globals.W
wordsH3.y = textHeight + textHeight * 2
wordsH4 = wordsHoriz.createWords
{
fontName = fontName,
textHeight = textHeight,
textSpacing = textSpacingH,
colorNames = languages.colorNames,
xMin = -globals.W4,
xMax = rightX,
topBorder = topBorder,
baseBorder = baseBorder,
direction = -1
}
wordsH4.x = globals.W*2
wordsH4.y = textHeight + textHeight * 2
end
local function createWordsSpiral()
wordsSpiral = spiral.createWords
{
fontName = fontName,
textHeight = textHeight,
colorNames = languages.colorNames,
}
end
local function createWordsCarousel()
wordsCarousel = carousel.createWords
{
fontName = fontName,
textHeight = textHeight,
colorNames = languages.colorNames,
}
end
local function removeMenuButtons()
if levelMenu then levelMenu:cleanup(); levelMenu = nil end
if mainMenu then mainMenu:cleanup(); mainMenu = nil end
end
local function onMainMenu()
if endLevelLogo then
endLevelLogo:removeSelf()
endLevelLogo = nil
end
removeMenuButtons()
returnFunction()
end
local function showScores()
if endLevelLogo then
endLevelLogo:removeSelf()
endLevelLogo = nil
end
score.showScoreMenu(hsScore)
end
local function showLevelMenu()
if endLevelLogo then
endLevelLogo:removeSelf()
endLevelLogo = nil
end
background.parent:insert(background)
if not mainMenu then
mainMenu = menu.createMenu
{
items =
{
{
text = languages.menuText(), handler = onMainMenu,
foreColor = { 200, 200, 200 }, backColor = { 0, 0, 0 },
}
},
spacing = 80,
x = globals.W2,
y = 460,
itemHeight = 30,
textHeight = 25,
}
else
mainMenu.parent:insert(mainMenu)
end
end
local function textListener(event)
if event.phase == "submitted" then
if globals.getIsSimulator() then
highscores.submitName(hsScore, "person" .. nameIX)
nameIX = nameIX + 1
else
globals.setCurrentPlayer(nameField.text) -- may be blank
if nameField.text and string.len(nameField.text) > 0 then
local txt = nameField.text -- make sure no colons as they're delimiters
highscores.submitName(hsScore, nameField.text)
end
native.setKeyboardFocus(nil)
nameField:removeSelf()
nameField = nil
end
showScores()
elseif event.phase == "ended" then
native.setKeyboardFocus(nil)
nameField:removeSelf()
nameField = nil
showScores()
end
end
local function addPlayer()
if endLevelLogo then
endLevelLogo:removeSelf()
endLevelLogo = nil
end
if globals.getIsSimulator() then
textListener{phase = "submitted"}
else
nameField = native.newTextField( 20, 180, globals.W-40, 30, textListener )
nameField.font = native.newFont( native.systemFontBold, inputFontSize )
nameField.text = globals.getCurrentPlayer()
native.setKeyboardFocus(nameField)
end
end
local function endLevel()
hsScore = score.getScore()
db.print("score", hsScore)
local isTop, isIn, txt, rank, time = score.endLevel(hsScore)
db.print("isTop, isIn, txt, rank, time:", isTop, isIn, txt, rank, time)
score.setScore(0)
if words1 then words1:cleanup(); words1 = nil end
if wordsL then wordsL:cleanup(); wordsL = nil end
if wordsR then wordsR:cleanup(); wordsR = nil end
if wordsH1 then wordsH1:cleanup(); wordsH1 = nil end
if wordsH2 then wordsH2:cleanup(); wordsH2 = nil end
if wordsH3 then wordsH3:cleanup(); wordsH3 = nil end
if wordsH4 then wordsH4:cleanup() ; wordsH4 = nil end
if wordsCarousel then wordsCarousel:cleanup(); wordsCarousel = nil end
if wordsSpiral then wordsSpiral:cleanup(); wordsSpiral = nil end
if speedController then speedController = nil end
endLevelLogo = letters.newLetters()
if isTop then endLevelLogo:addText(txt or "New High Score!")
elseif isIn then endLevelLogo:addText(txt or "Made it to top 10!")
else endLevelLogo:addText(txt or "Bad luck") end
endLevelLogo:drop(globals.H, false, 300)
hsRank = rank
hsTime = time
if isIn then
endLevelLogo:addText("Achieved ranking of " .. rank, 110)
endLevelLogo:addText("Enter your name", 140)
timer.performWithDelay(3000, addPlayer)
else
timer.performWithDelay(3000, showScores)
end
end
local function scrollRow(displacement)
words1:scroll(displacement)
end
local function scrollRowLR(displacement)
wordsL:scroll(displacement)
wordsR:scroll(displacement)
end
local function scrollRowUD(displacement)
wordsU:scroll(displacement)
wordsD:scroll(displacement)
end
local function scrollRowH(displacement)
wordsH1:scroll(displacement)
wordsH2:scroll(displacement)
wordsH3:scroll(displacement)
wordsH4:scroll(displacement)
end
local function scrollRowCarousel(displacement)
wordsCarousel:scroll(displacement)
end
local function scrollRowSpiral(displacement)
wordsSpiral:scroll(displacement)
end
local scrollFunc = { scrollRow, scrollRowLR, scrollRowUD, scrollRowH, scrollRowCarousel, scrollRowSpiral, }
local function enterFrame(event)
local elapsed = score.elapsedSinceLastFrame()
local levelTime = score.getCurLevelTime()
scoreboard:time(levelTime)
scoreboard:score(score.getScore())
scrollSpeed, level = speedController:getSpeed(levelTime)
-- if levelTime >= variableGameTime then
-- db.print("levelTime >= variableGameTime")
-- if level == normalLevels and score.getScore() >= masterLevel then
-- db.print("level == normalLevels and score.getScore() >= masterLevel")
-- variableGameTime = gameTime + extraTime
-- else
-- -- game over
-- Runtime:removeEventListener("enterFrame", enterFrame)
-- speedController:endLevel()
-- end
-- else
-- scrollSpeed, level = speedController:getSpeed(levelTime)
scrollFunc[level](scrollSpeed * elapsed)
if score.getScore() < deadScore then
Runtime:removeEventListener("enterFrame", enterFrame)
return endLevel()
end
score.frame()
-- end
end
function startGame()
scrollSpeed = startScrollSpeed
background.parent:insert(background)
createWords()
words1:init()
createWordsLR()
wordsL:init()
wordsR:init()
createWordsUD()
wordsU:init()
wordsD:init()
createWordsH()
wordsH1:init()
wordsH2:init()
wordsH3:init()
wordsH4:init()
createWordsCarousel()
wordsCarousel:init()
createWordsSpiral()
wordsSpiral:init()
variableGameTime = gameTime
score.startLevel(startLevel)
speedController = getSpeedController(#scrollFunc)
speedController:start(score.getCurLevelTime(), startLevel)
levelComplete = false;
-- make sure cover is over all other graphics
blacking.parent:insert(blacking)
scoreboard.parent:insert(scoreboard)
Runtime:addEventListener("enterFrame", enterFrame)
end
--
-- These functions accessible from outside:
--
function pause()
score.pause()
db.print("paused")
end
function resume()
db.print("resumed")
score.resume()
end
function init(returnFunc, font)
returnFunction = returnFunc
fontName = font
background = display.newImage("background.png")
blacking = display.newRect(0, 0, globals.W, topBorder * 2 + 8)
blacking:setReferencePoint(display.TopLeftReferencePoint)
blacking.x = 0
blacking.y = -(topBorder+8)
blacking:setFillColor(40, 40, 40)
-- All this stuff only done once.
scoreboard = createScoreboard()
score.lightMiss = lightController(scoreboard[scoreboard.missIndex], 10)
score.lightHit = lightController(scoreboard[scoreboard.hitIndex], 10)
end
function cleanup()
removeMenuButtons()
scoreboard:removeSelf()
blacking:removeSelf()
background:removeSelf()
end
--
-- Move locals
--
local function endLevel1Out()
words1.isVisible = false
Runtime:addEventListener("enterFrame", enterFrame)
setLevel(2)
resume()
end
local function level1Out(ob)
transition.to(words1,
{
time = transitionTime,
y = -globals.H,
transition = easing.outExpo,
onComplete = endLevel1Out,
})
end
local function endLevel2Out()
wordsL.isVisible = false
wordsR.isVisible = false
Runtime:addEventListener("enterFrame", enterFrame)
setLevel(3)
resume()
end
local function level2Out(ob)
transition.to(wordsL,
{
time = transitionTime,
x = -globals.W,
transition = easing.outExpo,
onComplete = endLevel2Out,
})
transition.to(wordsR,
{
time = transitionTime,
x = globals.W * 1.5,
transition = easing.outExpo,
})
end
local function endLevel3Out()
wordsD.isVisible = false
wordsU.isVisible = false
Runtime:addEventListener("enterFrame", enterFrame)
setLevel(4)
resume()
end
local function level3Out(ob)
transition.to(wordsD,
{
time = transitionTime,
x = -globals.W,
transition = easing.outExpo,
onComplete = endLevel3Out,
})
transition.to(wordsU,
{
time = transitionTime,
x = globals.W * 1.5,
transition = easing.outExpo,
})
end
local function endLevel4Out()
wordsH1.isVisible = false
wordsH2.isVisible = false
wordsH3.isVisible = false
wordsH4.isVisible = false
local hits, misses = score.getHitsAndMisses()
if misses <= maxMisses then
setLevel(5)
Runtime:addEventListener("enterFrame", enterFrame)
resume()
else
Runtime:removeEventListener("enterFrame", enterFrame)
return endLevel()
end
end
local function level4Out(ob)
transition.to(wordsH1,
{
time = transitionTime,
x = -globals.W,
transition = easing.outExpo,
onComplete = endLevel4Out,
})
transition.to(wordsH2,
{
time = transitionTime,
x = -globals.W,
transition = easing.outExpo,
})
transition.to(wordsH3,
{
time = transitionTime,
x = globals.W * 1.5,
transition = easing.outExpo,
})
transition.to(wordsH4,
{
time = transitionTime,
x = globals.W * 1.5,
transition = easing.outExpo,
})
end
local function endLevel5Out()
wordsCarousel.visual.isVisible = false
Runtime:addEventListener("enterFrame", enterFrame)
setLevel(6)
resume()
end
local function level5Out(ob)
transition.to(wordsCarousel.visual,
{
time = transitionTime,
y = globals.H + globals.H4,
transition = easing.outExpo,
onComplete = endLevel5Out,
})
end
local function endLevel6Out()
wordsSpiral.isVisible = false
Runtime:removeEventListener("enterFrame", enterFrame)
return endLevel()
end
local function level6Out(ob)
transition.to(wordsSpiral,
{
time = transitionTime,
y = globals.H + globals.H4,
transition = easing.outExpo,
onComplete = endLevel6Out,
})
end
--
-- pre-declared
--
function clearLevel(n)
-- suspend animations
pause()
Runtime:removeEventListener("enterFrame", enterFrame)
if n == 1 then
level1Out()
elseif n == 2 then
level2Out()
elseif n == 3 then
level3Out()
elseif n == 4 then
level4Out()
elseif n == 5 then
level5Out()
elseif n == 6 then
level6Out()
end
end
function setLevel(n)
if n == 1 then
words1.isVisible = true
elseif n == 2 then
wordsL.isVisible = true
wordsR.isVisible = true
elseif n == 3 then
wordsU.isVisible = true
wordsD.isVisible = true
elseif n == 4 then
wordsH1.isVisible = true
wordsH2.isVisible = true
wordsH3.isVisible = true
wordsH4.isVisible = true
elseif n == 5 then
wordsCarousel.visual.isVisible = true
elseif n == 6 then
wordsSpiral.isVisible = true
end
end