summaryrefslogtreecommitdiff
path: root/_RELEASE/Packs/tutorial/Scripts/Levels/babysteps.lua
blob: a7bd3ea7b725f7ded799f3f4cbf5e95c6621c521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
-- include useful files
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "utils.lua")
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "common.lua")
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "commonpatterns.lua")

-- this function adds a pattern to the timeline based on a key
function addPattern(mKey)
    if mKey == 0 then pBarrageSpiral(u_rndInt(1, 2), 1, 1)
    elseif mKey == 1 then pInverseBarrage(0)
    elseif mKey == 2 then pAltBarrage(u_rndInt(2, 4), 2)
    elseif mKey == 3 then pSpiral(12, 0)
    end
end

-- shuffle the keys, and then call them to add all the patterns
-- shuffling is better than randomizing - it guarantees all the patterns will be called
keys = { 0, 1, 2, 3 }
shuffle(keys)
index = 0
achievementUnlocked = false
challengeFailed = false
challengeFailedText = "yes, so far..."

step0 = false
step1 = false
step2 = false
step25 = false
step3 = false
step35 = false
step4 = false
step5 = false
step6 = false

step0_trRotateLeft = "nope"
step0_trRotateRight = "nope"

step0_completionTime = 0
step3_completionTime = 0

step1_trFocus = "nope"

-- onInit is an hardcoded function that is called when the level is first loaded
function onInit()
    l_setSpeedMult(0.65)
    l_setSpeedInc(0.15)
    l_setRotationSpeed(0.04)
    l_setRotationSpeedMax(0.4)
    l_setRotationSpeedInc(0.04)
    l_setDelayMult(1.65)
    l_setDelayInc(0.0)
    l_setFastSpin(0.0)
    l_setSides(6)
    l_setSidesMin(6)
    l_setSidesMax(6)
    l_setIncTime(1500)
    l_setTutorialMode(true)

    l_setBeatPulseMax(14)
    l_setBeatPulseDelayMax(21.95) -- BPM is 164, 3600/164 is 21.95
    l_setBeatPulseSpeedMult(0.45) -- Slows down the center going back to normal
end

-- onLoad is an hardcoded function that is called when the level is started/restarted
function onLoad()
end

-- onStep is an hardcoded function that is called when the level timeline is empty
-- onStep should contain your pattern spawning logic
function onStep()
    if not step35 then
        return
    end

    addPattern(keys[index])
    index = index + 1

    if index - 1 == #keys then
        index = 1
        shuffle(keys)
    end
end

-- onIncrement is an hardcoded function that is called when the level difficulty is incremented
function onIncrement()
end

-- onUnload is an hardcoded function that is called when the level is closed/restarted
function onUnload()
end

-- onInput is a hardcoded function invoked when the player executes input
function onInput(mFrameTime, mMovement, mFocus, mSwap)
    if not step25 and step1 then
        if mMovement == -1 then
            step0_trRotateLeft = "yes!"
        end

        if mMovement == 1 then
            step0_trRotateRight = "yes!"
        end
    end

    if step25 then
        if mFocus then
            step1_trFocus = "yes!"

            if mMovement == -1 then
                step0_trRotateLeft = "yes!"
            end

            if mMovement == 1 then
                step0_trRotateRight = "yes!"
            end
        end
    end
end

-- onUpdate is an hardcoded function that is called every frame
function onUpdate(mFrameTime)
    if not step0 then
        step0 = true

        l_resetTime()

        e_messageAddImportant("welcome to open hexagon 2!", 120)
        e_messageAddImportant("let's learn about the controls", 120)
        e_messageAddImportant("use left/right to rotate around the center", 200)
        e_messageAddImportant("try it now!", 120)
        e_stopTimeS(9)
    end

    if not step1 and l_getLevelTime() > 0.2 then
        step1 = true

        l_addTracked("step0_trRotateLeft", "rotated counter-clockwise")
        l_addTracked("step0_trRotateRight", "rotated clockwise")
    end

    if step1 and not step2 and step0_trRotateLeft == "yes!" and step0_trRotateRight == "yes!" then
        step2 = true
        step0_completionTime = l_getLevelTime()

        e_messageAddImportant("well done!", 120)
        e_messageAddImportant("you can slow down by focusing", 160)
        e_messageAddImportant("by default, use left shift", 160)
        e_messageAddImportant("try it while rotating!", 140)
        e_stopTimeS(8)
    end

    if not step25 and step2 and l_getLevelTime() > step0_completionTime + 0.2 then
        step25 = true

        step0_trRotateLeft = "nope"
        step0_trRotateRight = "nope"

        l_addTracked("step1_trFocus", "focused")
        l_addTracked("step0_trRotateLeft", "rotated counter-clockwise while focusing")
        l_addTracked("step0_trRotateRight", "rotated clockwise while focusing")
    end

    if step25 and not step3 and step0_trRotateLeft == "yes!" and step0_trRotateRight == "yes!" and step1_trFocus == "yes!" then
        step3 = true
        step3_completionTime = l_getLevelTime()

        e_stopTimeS(7)
        e_messageAddImportant("great!", 120)
        e_messageAddImportant("the goal of open hexagon is to survive", 180)
        e_messageAddImportant("avoid the walls!", 120)
    end

    if not step35 and step3 and l_getLevelTime() > step3_completionTime + 0.2 then
        step35 = true

        l_clearTracked()
        l_addTracked("challengeFailedText", "survived until the end")

        l_resetTime()
        l_setIncTime(15)
    end

    if step35 and not step4 and l_getLevelTime() > 30 then
        step4 = true

        e_stopTimeS(5)

        if not challengeFailed then
            e_messageAddImportant("great job!", 110)
        else
            e_messageAddImportant("nice try...", 110)
        end

        e_messageAddImportant("after a while, things get harder", 140)
        e_messageAddImportant("get to 45 seconds to complete the tutorial!", 160)
    end

    if step4 and not step5 and l_getLevelTime() > 43 then
        step5 = true

        u_clearWalls()
        l_setIncEnabled(false);

        if not achievementUnlocked then
            steam_unlockAchievement("a0_babysteps")
            achievementUnlocked = true
        end

        if challengeFailed == false then
            a_playPackSound("fanfare.ogg")
            e_messageAddImportant("well done! you survived!", 120)
            e_messageAddImportant("now play some real levels!", 180)
        else
            a_playPackSound("failure.ogg")
            e_messageAddImportant("nice try, but not quite...", 120)
            e_messageAddImportant("try again without hitting any wall!", 220)
        end
    end

    if step5 and not step6 and l_getLevelTime() > 45 then
        step6 = true
        e_kill()
    end
end

-- onPreDeath is an hardcoded function that is called when the player is killed, even
-- in tutorial mode
function onPreDeath()
    if challengeFailed == false and l_getLevelTime() < 42 then
        challengeFailed = true
        challengeFailedText = "not this time!"
        e_messageAddImportant("whoops!", 60)
    end
end