aboutsummaryrefslogtreecommitdiff
path: root/waves.lua
blob: 4daf6576c52c905cb3706c7d30bcedc1a02fa622 (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
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
wave = {} --store wave functions here
currentwave = 1 --THIS IS THE CURRENT WAVE, SHOLD BE 1 UNLESS TESTING SOMETHING
currentwavetime = 0
delaytimer = 0
everysecondtimer = 0
checkpoint = 1
bossmusic = false
targetplayer = 1

--NOTE - slow BG during boss waves / make bosses their own checkpoint

wave[1] = {
    delay = 2,
    start = function()
        addbasicenemy(150, 60, 0.15)
    end,
}

for i = 2, 16, 1 do
    wave[i] = {}
end

wave[2] = {
    delay = 2,
    start = function()
        addbasicenemy(128, 30, 0.4)
        addtargetingenemy(128, 60, 0.1)
        addbasicenemy(128, 90, 0.4)
    end,
    conditions = function()
        if #enemies < 2 then return true
        end
    end
}

wave[3] = {
    delay = 2,
    start = function()
        for i = 1, 7, 1 do
            addbasicenemy(128, i*16, 0.5 + 0.075*i)
            addbasicenemy(170, i*16, 1.05 - 0.075*i)
        end
    end,
    conditions = function()
        if #enemies < 5 then return true
        end
    end
}

wave[4] = {
    delay = 0,
    start = function()
        addwallshooter(140, true, 0.4)
        addbasicenemy(128, 30, 0.5)
        addtargetingenemy(155, 60, 0.15)
        addbasicenemy(128, 90, 0.5)
    end,
    conditions = function()
        if #enemies < 2 then return true
        end
    end
}

wave[5] = {
    delay = 2,
    start = function()
        for i = 1, 12, 1 do
            addwallshooter(100 + (54-i)*i, (i%2==1), 0.4)
        end
        addpickup(490, 60, "health")
    end,
    everysecond = function()
        if flr(currentwavetime%3) == 2 and currentwavetime < 16 then
            for i = 1, currentwavetime/4, 1 do
                addbasicenemy(128+rnd(20), rnd(100)+10, 0.6) 
            end
        end
    end,
    conditions = function()
        if #enemies < 2 and currentwavetime > 12 then return true
        end
    end
}

wave[6] = {
    delay = 2,
    start = function()
        addbasicenemy(240, 58, 1.1)
        addbasicenemy(240, 68, 0.9)
        addbasicenemy(240, 63, 1)
        addlasershooter(128, 64, 100, 0.4, true, true)
        
    end,
    everysecond = function()
        if rnd() < 0.1 and #enemies > 1 then
            for i = 1, rnd(2), 1 do
                addbasicenemy(128+rnd(20), rnd(20)+54, 0.6) 
            end
        end
    end,
    conditions = function()
        if #enemies < 1 then checkpoint = currentwave+1 return true
        end
    end,
    boss = true
}

wave[7] = {
    delay = 5,
    start = function()
        addballshooter(128, 56, 0.1)
        addballshooter(160, 14, 0.1)
        addballshooter(160, 100, 0.1)
    end,
}

wave[8] = {
    delay = 1,
    start = function()
        addballshooter(140, 56, 0.2)
        addwallshooter(120, true, 0.3)
        addwallshooter(220, true, 0.3)
        addbasicenemy(128, 30, 0.5)
        addbasicenemy(128, 110, 0.5)
        addbasicenemy(140, 30, 0.2)
        addbasicenemy(140, 110, 0.2)
    end,
}

wave[9] = {
    delay = 1,
    start = function()
        addtargetingenemy(128,1,0.1)
        addtargetingenemy(262,60,0.2)
        addwallshooter(138, true, 0.4, 0)
        addwallshooter(144, true, 0.4, 0)
        addwallshooter(185, false, 0.4, 0)
        addwallshooter(230, true, 0.4)
        addballshooter(230, 56, 0.2)
    end,
    conditions = function()
        if #enemies < 2 then return true
        end
    end
}

wave[10] = {
    delay = 3,
    start = function()
        for i = 1, 7, 1 do
            addtargetingenemy(128, i*16-4, 0.085)
            addtargetingenemy(144, i*16-4, 0.085)
        end
    end,
    conditions = function()
        if #enemies < 2 then return true
        end
    end
}

wave[11] = {
    delay = 1,
    start = function()
        for i = 1, 3, 1 do
            addwallshooter(128+i*65, true, 0.4, 0, 0.68)
            addwallshooter(128+i*65, false, 0.4, 0, 0.68)
        end
        addballshooter(200, 56, 0.2)
    end,
}

wave[12] = {
    delay = 2,
    start = function()
        addwallboss(128,4,15,225,0.05,true,false,true)
    end,
    everysecond = wave[6].everysecond,
    conditions = wave[6].conditions,
    boss = true
}

wave[13] = {
    delay = 5,
    start = function()
        addbasicenemy(130, 58, 0.6)
        addbasicenemy(130, 68, 0.5)
        addbasicenemy(130, 63, 0.7)
        addlasershooter(128, 2, 50, 0.1, false)
        addbomb(128,46, 0)
        addlasershooter(128, 94, 50, 0.1, false)
    end,
    everysecond = wave[6].everysecond,
}

wave[14] = {
    delay = 0,
    start = function()
        addbomb(140,46, 4)
        addtargetingenemy(140, 52, 0.2)
        addtargetingenemy(140, 68, 0.2)
        addballshooter(128, 14, 0.03)
        addballshooter(128, 100, 0.03)
    end,
}

wave[15] = {
    delay = 0,
    start = function()
        for i = 1, 6, 1 do
            addtargetingenemy(128, i*16-14+flr(i/4)*36, 0.05)
        end
        addbomb(140,46, 1)
    end
}

wave[16] = {
    delay = 0,
    start = function()
        addwallboss(128, 2, 7, 30, 0.05, false, 3, false)
        addwallboss(128, 70, 7, 30, 0.05, false, 3, false)
    end,
    everysecond = function ()
        if flr(currentwavetime%6) == 5 and currentwavetime < 20 then
            local ylaserpos = 16
            if players[targetplayer].y > 64 then
                ylaserpos = 80
            end
            addlasershooter(128, ylaserpos, 50, 0.1, false)
        end
    end
}

wave[17] = {
    delay = 0,
    start = wave[5].start,
    everysecond = function()
        if currentwavetime%5 > 4 and currentwavetime < 20 then
            addbomb(128,20+currentwavetime*2,0)
        end
        if currentwavetime > 18 and not bossmusic then
            music(8, 0, 3)
            bossmusic = true
        end
        addbasicenemy(128,rnd(100)+14,0.4+rnd(0.4))
    end,
    conditions = function()
        if currentwavetime > 24 then return true
        end
    end
}

wave[18] = {
    delay = 0,
    start = function()
        killallenemies()
        addmissileboss(128, 0)
    end,
    everysecond = wave[6].everysecond,
    conditions = wave[6].conditions,
    boss = true
}

wave[19] = {
    delay = 7,
    start = function()
        canshootatx = 110
        addfinalboss()
    end,
    boss = true
}

--ending score screen
wave[20] = {
    delay = 3,
    start = function()
        if not coopmode and highscore0 < currentscore then
            dset(0, currentscore) --set singleplayer score
        elseif coopmode and highscore1 < currentscore then
            dset(1, currentscore) --set multiplayer score
        end
    end,
    conditions = function()
    end
}

foreach(wave, function(wave) if not wave.conditions then wave.conditions = function() if #enemies < 1 then return true end end end end) --if there are no conditons for a wave, give them one. look at all those ends!!!!

function updatewaves()
    currentwavetime += ft
    everysecondtimer += ft
    if everysecondtimer >= 1 then
        targetplayer = rnd({1,#players}) --swaps target every second
        everysecondtimer = 0
        if wave[currentwave].everysecond then
            wave[currentwave].everysecond()
        end
    end
    if wave[currentwave].conditions() then
        if wave[currentwave+1].boss and not bossmusic then
            bossmusic = true
            music(8,0,3)
        end
        delaytimer += ft
        if delaytimer > wave[currentwave+1].delay then
            everysecondtimer = 0
            currentwave += 1
            if not wave[currentwave].boss and bossmusic then
                music(2,0,3)
                bossmusic = false
            end
            currentwavetime = 0
            delaytimer = 0
            -- currentwave = (currentwave - 1) % #wave+1 --temporarily looping the waves
            -- if currentwave < checkpoint then
            --     checkpoint = 1
            -- end
            wave[currentwave].start()
        end
    end
end

function setwave(num)
    everysecondtimer = 0
    currentwave = num
    currentwavetime = 0
    delaytimer = 0
    wave[currentwave].start()
    music(2, 0, 3)
end