-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathboss.lua
177 lines (156 loc) · 4.74 KB
/
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
Boss = { MAX_HEALTH = 15, GRAVITY = 350, JUMP_POWER = 200, IDLE_TIME = 1.5, MAX_JUMP = 128 }
Boss.__index = Boss
local BS_IDLE, BS_JUMP, BS_FLY, BS_LAND = 0,1,2,3
function Boss.create(x,y)
local self = setmetatable({}, Boss)
self.alive = true
self.hit = false
self.x, self.y = x,y
self.xspeed, self.yspeed = 0,0
self.time = self.IDLE_TIME
self.dir = 1
self.health = self.MAX_HEALTH
self.angry = false
self.addedFire = false
self.shockwaveActive = false
self.shockwaveFrame = 0
self.shockwaveX = 0
self.anims = {}
self.anims[BS_JUMP] = newAnimation(img.boss_jump, 58, 64, 0.14, 5,
function()
self:setState(BS_FLY)
self.yspeed = -self.JUMP_POWER
self.xspeed = 0.93*cap(cap(player.x,194,464) - self.x, -self.MAX_JUMP, self.MAX_JUMP)
self.addedFire = false
end
)
self.anims[BS_LAND] = newAnimation(img.boss_land, 58, 64, 0.14, 7,
function()
self:setState(BS_JUMP)
end
)
self:setState(BS_IDLE)
return self
end
function Boss:update(dt)
if self.anim then
self.anim:update(dt)
end
if self.state == BS_IDLE then
self.time = self.time - dt
if self.time <= 0 then
self.state = BS_JUMP
self.anim = self.anims[BS_JUMP]
end
elseif self.state == BS_FLY then
self.yspeed = self.yspeed + self.GRAVITY*dt
self.x = self.x + self.xspeed*dt
self.y = self.y + self.yspeed*dt
if self.yspeed > 0 and self.y > MAPH-48 then
self:setState(BS_LAND)
end
elseif self.state == BS_LAND then
self.yspeed = self.yspeed + self.GRAVITY*dt
self.y = self.y + self.yspeed*dt
if self.y > MAPH-16 then
self.y = MAPH-16
self.yspeed = 0
if self.addedFire == false then
-- Add fire
map:addFire(math.floor((self.x-8)/16), math.floor((self.y-5)/16))
map:addFire(math.floor((self.x+8)/16), math.floor((self.y-5)/16))
self.addedFire = true
-- Set shake
ingame.shake = 0.4
-- Add shockwave
if self.angry == true then
self.shockwaveX = math.floor(self.x)
self.shockwaveFrame = 0
self.shockwaveActive = true
end
end
else
self.x = self.x + self.xspeed*dt
end
end
self.x = cap(self.x, 194, 464)
-- Update shockwave if active
if self.shockwaveActive == true then
self.shockwaveFrame = self.shockwaveFrame + dt*24
if self.shockwaveFrame >= 10 then
self.shockwaveFrame = 0
self.shockwaveActive = false
end
end
-- Check if out of health
if self.health < self.MAX_HEALTH/2 then
self.angry = true
elseif self.health <= 0 then
self.alive = false
end
end
function Boss:draw()
self.flx = math.floor(self.x)
self.fly = math.floor(self.y)
-- Draw shockwave
if self.shockwaveActive == true then
local frame = math.floor(self.shockwaveFrame)
lg.drawq(img.shockwave, quad.shockwave[frame], self.shockwaveX, 240, 0, 1,1, 82, 32)
lg.drawq(img.shockwave, quad.shockwave[frame], self.shockwaveX, 240, 0,-1,1, 82, 32)
end
-- Draw boss
if self.hit == false then
if self.angry == false then
if self.state == BS_IDLE then
self.anims[BS_JUMP]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1)
elseif self.state == BS_FLY then
self.anims[BS_LAND]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1)
else
self.anim:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64)
end
else
if self.state == BS_IDLE then
self.anims[BS_JUMP]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1, img.boss_rage_jump)
elseif self.state == BS_FLY then
self.anims[BS_LAND]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1, img.boss_rage_land)
elseif self.state == BS_JUMP then
self.anim:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, nil, img.boss_rage_jump)
elseif self.state == BS_LAND then
self.anim:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, nil, img.boss_rage_land)
end
end
else
if self.state == BS_IDLE then
self.anims[BS_JUMP]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1, img.boss_jump_hit)
elseif self.state == BS_FLY then
self.anims[BS_LAND]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1, img.boss_land_hit)
elseif self.state == BS_JUMP then
self.anim:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, nil, img.boss_jump_hit)
elseif self.state == BS_LAND then
self.anim:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, nil, img.boss_land_hit)
end
end
end
function Boss:collideBox(bbox)
if self.x-11 > bbox.x+bbox.w or self.x+11 < bbox.x
or self.y-33 > bbox.y+bbox.h or self.y-7 < bbox.y then
return false
else
return true
end
end
function Boss:getBBox()
return {x = self.x-11, y = self.y-33, w = 22, h = 26}
end
function Boss:getShockwaveBBox()
local swwidth = self.shockwaveFrame*6.08
return {x = self.x-swwidth, y = 235, w = 2*swwidth, h = 5}
end
function Boss:setState(state)
self.state = state
self.anim = self.anims[state]
end
function Boss:shot(dt,dir)
self.health = self.health - dt
self.hit = true
end