forked from Moe-/Bacteria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobj.enemy-boss.lua
341 lines (270 loc) · 8.46 KB
/
obj.enemy-boss.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
cEnemyBossBase = CreateClass(cEnemyBase)
kBossUnit = 60*gEnemyBossGfxScale
kEnemyBossMidBlockShotRadius = 0.8*kBossUnit
kTentacleRespawnInterval = 3.0
kShotInterval_BossPart = 1.2
kBossWallEvadeSpeed = 40
-- ***** ***** ***** ***** ***** final boss kill
function NotifyFinalBossKilled ()
-- this is called when final boss dies, show game over / won / highscore screen when boss is killed
gGameFinished = true
end
-- ***** ***** ***** ***** ***** boss variants
cEnemyBoss01 = CreateClass(cEnemyBossBase)
function cEnemyBoss01:Init(x,y)
self:BossInitBase(x,y)
local e = kBossUnit
local ry = 2
for i=-ry,ry do
if (abs(i) == ry) then
local o = self:MakePart( 0*e, i*e, gfx_boss_core) self.cores[o] = true
local core = o
if (i < 0) then
local o = self:MakeTentacle( 0,-2, 4,-1, -0.5, core, gfx_boss_spike)
local o = self:MakeTentacle( 0,-2, 4, 1, -0.5, core, gfx_boss_spike)
else
local o = self:MakeTentacle( 0, 2, 4,-1, 0.5, core, gfx_boss_spike)
local o = self:MakeTentacle( 0, 2, 4, 1, 0.5, core, gfx_boss_spike)
end
else
local o = self:MakePart( 0, i*e, gfx_boss_mid)
end
end
self:UpdatePartsStatus()
end
cEnemyBoss02 = CreateClass(cEnemyBossBase)
function cEnemyBoss02:Init(x,y)
self:BossInitBase(x,y)
local e = kBossUnit
local o = self:MakePart( 0*e,0*e, gfx_boss_core) self.cores[o] = true
local core = o
local o = self:MakeTentacle( 0,0, 4,-1, 0, core, gfx_boss_spike)
local o = self:MakeTentacle( 0,0, 4, 1, 0, core, gfx_boss_spike)
local o = self:MakeTentacle( 0,0, 4, 0,-1, core, gfx_boss_gun)
local o = self:MakeTentacle( 0,0, 4, 0, 1, core, gfx_boss_gun)
self:UpdatePartsStatus()
end
cEnemyBossFinal = CreateClass(cEnemyBossBase)
function cEnemyBossFinal:Init(x,y)
self:BossInitBase(x,y)
gFinalBoss = true
self.bIsFinalBoss = true
local e = kBossUnit
local rx,ry = 2,2
for ix=-rx,rx do
for iy=-ry,ry do
if (abs(ix) == rx and abs(iy) == ry) then
local o = self:MakePart( ix*e, iy*e, gfx_boss_core) self.cores[o] = true
local core = o
local o = self:MakeTentacle(ix,iy, 4,sgn(ix), 0, core, gfx_boss_spike)
local o = self:MakeTentacle(ix,iy, 4, 0, sgn(iy), core, gfx_boss_gun)
else
local o = self:MakePart( ix*e, iy*e, gfx_boss_mid)
end
--~ if (ix ~= 0 or iy ~= 0) then local o = self:MakePart( ix*e, iy*e, gfx_boss_mid) end
end
end
self:UpdatePartsStatus()
end
-- ***** ***** ***** ***** ***** boss variants
function cEnemyBossBase:Init(x,y)
self:BossInitBase(x,y)
local e = kBossUnit
local o = self:MakePart( 0*e, 0*e, gfx_boss_core) self.cores[o] = true
self:UpdatePartsStatus()
end
function cEnemyBossBase:BossInitBase(x,y)
self.enemy_kind = "bossbase"
self.x = x
self.y = y
self.x0 = x
self.y0 = y
self.energy = 100
self:Register()
self.bInvulnerable = true
self.bIgnoreWalls = true
self.parts = {}
self.cores = {}
self.tentacles = {}
love.audio.stop(snd_background)
love.audio.play(snd_bossfight)
end
function cEnemyBossBase:MakeTentacle(x,y,num,vx,vy,core,gfx_head)
return cTentacle:New(x,y,num,vx,vy,gfx_head,core,self)
end
function cEnemyBossBase:MakePart(x,y,gfx,tentacle)
local o = cEnemyBossPartBase:New(x,y,gfx,self,tentacle)
self.parts[o] = true
return o
end
function cEnemyBossBase:NotifyPartDie(o)
self.parts[o] = nil
self.cores[o] = nil
self:UpdatePartsStatus()
end
function cEnemyBossBase:UpdatePartsStatus()
-- set cores invul if guns/spikes alive
local bCoresAlive = false
for o,_ in pairs(self.cores) do bCoresAlive = true o:CoreCheckInvul() end
-- death if no cores left
if (not bCoresAlive) then
for o,_ in pairs(self.parts) do o:Die() end
self:Die()
love.audio.stop(snd_bossfight)
love.audio.play(snd_background)
if (self.bIsFinalBoss) then
NotifyFinalBossKilled()
end
end
end
function cEnemyBossBase:Update(dt)
self.y = self.y0 + 50 * sin(0.35*gMyTime*PI)
local bCollidingWithTop = false
local bCollidingWithBottom = false
for o,_ in pairs(self.parts) do
if (o.bCollidingWithTop ) then bCollidingWithTop = true o.bCollidingWithTop = false end
if (o.bCollidingWithBottom ) then bCollidingWithBottom = true o.bCollidingWithBottom = false end
end
if (bCollidingWithTop ) then self.y0 = self.y0 + kBossWallEvadeSpeed * dt end
if (bCollidingWithBottom) then self.y0 = self.y0 - kBossWallEvadeSpeed * dt end
end
function cEnemyBossBase:Draw()
end
-- ***** ***** ***** ***** ***** cTentacle
cTentacle = CreateClass()
function cTentacle:Init (x,y,num,vx,vy,gfx_head,core,boss)
self.parts = {}
self.x = x
self.y = y
self.num = num
self.vx = vx
self.vy = vy
self.gfx_head = gfx_head
self.core = core
self.boss = boss
core.tentacles[self] = true
self:Respawn()
end
function cTentacle:TryRespawn ()
if (self.bIsAlive) then return end
self:Respawn()
return true
end
function cTentacle:Respawn ()
self.bIsAlive = true
local e = kBossUnit
local boss = self.boss
local x = self.x
local y = self.y
local vx = self.vx
local vy = self.vy
local num = self.num
local gfx_head = self.gfx_head
for i = 0,num do
local gfx = (i == num) and gfx_head or gfx_boss_mid
local o = boss:MakePart( (x+i*vx)*e, (y+i*vy)*e, gfx, self)
end
end
function cTentacle:NotifyPartDie (o)
--~ print("tentacle part die",o)
self.parts[o] = nil
if (o.gfx ~= gfx_boss_mid) then
self.bIsAlive = false
self:KillAll()
self.core:UpdateCoreTentacleRespawnTimer()
end
end
function cTentacle:KillAll ()
for o,_ in pairs(self.parts) do o:Die() end
end
function cTentacle:Add (o)
self.parts[o] = true
end
function cTentacle:CoreCheckInvul ()
for o,_ in pairs(self.parts) do
if (o.gfx == gfx_boss_gun or o.gfx == gfx_boss_spike) then return true end
end
end
-- ***** ***** ***** ***** ***** cEnemyBossPartBase
cEnemyBossPartBase = CreateClass(cEnemyBase)
function cEnemyBossPartBase:Init (x,y,gfx,boss,tentacle)
self.bIsBossPart = true
self.x = boss.x+x
self.y = boss.y+y
self.x0 = x
self.y0 = y
self.gfx = gfx
self.energy = 100
self.boss = boss
self.tentacles = {}
self.tentacle = tentacle
if (tentacle) then tentacle:Add(self) end
self:Register()
if (self.gfx == gfx_boss_mid) then self.bInvulnerable = true end
self.respawn_t = 0
self.next_shot_t = 0
end
function cEnemyBossPartBase:UpdateCoreTentacleRespawnTimer()
self.respawn_t = gMyTime + kTentacleRespawnInterval
end
function cEnemyBossPartBase:Update(dt)
local x = self.x0
local y = self.y0
local ang_per_pixel = PI / 100
local ang_phase = gMyTime / 1.5 * PI
local bHorz = abs(x) > abs(y)
local d = max(abs(x),abs(y))
local waber_d = 20*min(1.0,d / 100)
iOff = waber_d * sin(d * ang_per_pixel + ang_phase)
self.x = self.boss.x + x + (bHorz and 0 or iOff)
self.y = self.boss.y + y + (bHorz and iOff or 0)
if (self.gfx == gfx_boss_mid) then
Shots_BlockPlayerShotsAtPos(self.x,self.y,kEnemyBossMidBlockShotRadius)
end
-- respawn tentacles if core
if (self.gfx == gfx_boss_core and gMyTime > self.respawn_t) then
for o,_ in pairs(self.tentacles) do
if (o:TryRespawn()) then
self:UpdateCoreTentacleRespawnTimer()
self:CoreCheckInvul()
break
end
end
end
-- shot if gun
if (self.gfx == gfx_boss_gun) then
if (gMyTime > self.next_shot_t) then
self.next_shot_t = gMyTime + (0.8 + 0.4*randf()) * kShotInterval_BossPart
local x = self.x
local y = self.y
local dirX = gPlayer.x - x
local dirY = gPlayer.y - y + math.random(-250, 250)
local norm = math.sqrt(dirX*dirX + dirY*dirY)
local lifetime = 5.0
cShot:New(x, y, dirX/norm, dirY/norm, lifetime, "white", "blue")
end
end
end
function cEnemyBossPartBase:CoreCheckInvul()
self.bInvulnerable = false
for o,_ in pairs(self.tentacles) do
if (o:CoreCheckInvul()) then self.bInvulnerable = true end
end
end
function cEnemyBossPartBase:Die()
cEnemyBase.Die(self)
self.boss:NotifyPartDie(self)
if (self.tentacle) then self.tentacle:NotifyPartDie(self) end
end
function cEnemyBossPartBase:Draw() self:DrawWobble(0.1,0.1,gEnemyBossGfxScale) end
-- ***** ***** ***** ***** ***** *****
cEnemyEgg = CreateClass(cEnemyBase)
function cEnemyEgg:Init(x,y)
self.enemy_kind = "egg"
self.x = x
self.y = y
self.energy = 100
self.gfx = gfx_egg
self:Register()
end
function cEnemyEgg:Draw() self:DrawWobble(0.1,0.1,gEnemyGfxScale) end