-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.lua
215 lines (199 loc) · 5.78 KB
/
skeleton.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
Skeleton = Class{__includes = Enemy,
init = function(self, x, y, collider, gravity)
Enemy.init(self, x,y)
self.bbox = collider:addRectangle(x,y,32,64)
self.bbox.type = "skeleton"
self.bbox.ref = self
self.gravity = gravity
self.velocity.x = 3
self.facingRight = false
self.sprite = love.graphics.newImage('/assets/art/skeleton.png')
self.icecube = love.graphics.newImage('/assets/art/icecube.png')
end
}
function Skeleton:update(dt)
--update status effects
if self.thaw > 0 then
self.thaw = self.thaw-dt
if self.thaw < 0 then
self.thaw = 0
end
end
-- update invulnerability
if self.invuln > 0 then
self.invuln = self.invuln-dt
if self.invuln <0 then
self.invuln = 0
end
end
if self.jumping and not self:isFrozen() then
self.velocity.y = self.velocity.y + self.gravity*dt
end
if self.facingRight then
self.velocity.x = self.speed
else
self.velocity.x = -self.speed
end
-- update movement
if not self:isFrozen() then
self.bbox:move(self.velocity.x*dt,self.velocity.y*dt)
end
end
function Skeleton:isFrozen()
if self.thaw > 0 then
return true
end
return false
end
function Skeleton:isInvuln()
return self.invuln > 0
end
function Skeleton:draw()
love.graphics.setColor(255,0,0, 255)
--self.bbox:draw("fill")
love.graphics.setColor(255,255,255, 255)
local blink = false
if self.invuln <= 0.1 then
blink = false
elseif self.invuln <= 0.2 then
blink = true
elseif self.invuln <= 0.3 then
blink = false
elseif self.invuln <= 0.4 then
blink = true
elseif self.invuln <= 0.5 then
blink = false
elseif self.invuln <= 0.6 then
blink = true
elseif self.invuln <= 0.7 then
blink = false
elseif self.invuln <= 0.8 then
blink = true
elseif self.invuln <= 0.9 then
blink = false
elseif self.invuln <= 1 then
blink = true
end
local x,y = self.bbox:center()
if not blink then
if self.facingRight then
love.graphics.draw(sprites.skeleton, x - 16, y - 32)
else
love.graphics.draw(sprites.skeleton, x + 16, y - 32, 0, -1, 1)
end
else
if self.facingRight then
love.graphics.draw(sprites.skeletonDmg, x - 16, y - 32)
else
love.graphics.draw(sprites.skeletonDmg, x + 16, y - 32, 0, -1, 1)
end
end
if self:isFrozen() then
love.graphics.draw(sprites.icecube, x - 16, y - 32)
end
end
function Skeleton:takeDamage(damage)
if damage > 0 then
--[[
AudioController.sounds["skeletonhit"]:rewind()
AudioController.sounds["skeletonhit"]:play()
]]
self.hp = self.hp - damage
self.invuln = self.MAXINVULN
if self.hp <= 0 then
AudioController:playAndRewindSoundPitchy("skeletondeath2")
AudioController:playAndRewindSoundPitchy("skeletondeath")
else
AudioController:playAndRewindSoundPitchy("skeletonhit")
end
end
end
function Skeleton:isDead()
if self.hp <=0 then
return true
end
return false
end
function Skeleton:move(x,y)
self.bbox:move(x,y)
end
function Skeleton:collisionWithSolid(mtv_x,mtv_y)
local fromleft = false
local fromright = false
local fromup = false
local fromdown = false
if mtv_x < 0 then fromleft = true end
if mtv_x > 0 then fromright = true end
if mtv_y < 0 then fromup = true end
if mtv_y > 0 then fromdown = true end
self:move(mtv_x, mtv_y)
if fromleft or fromright then
self.velocity.x = 0
if self.facingRight then
self.facingRight = false
else
self.facingRight = true
end
if self.velocity.y >0 then
self.velocity.y = 0
end
elseif fromup then
self.velocity.y = 0
if self.velocity.y >= 0 then
self.jumping = false
end
elseif fromdown then
self.velocity.y = 0
elseif mtv_y == 0 then
self.velocity.x = 0
end
end
function Skeleton:knockback(mtv_x,mtv_y)
local fromleft = false
local fromright = false
local fromup = false
local fromdown = false
if mtv_x < 0 then fromleft = true end
if mtv_x > 0 then fromright = true end
if mtv_y < 0 then fromup = true end
if mtv_y > 0 then fromdown = true end
if fromleft then
self.velocity.x = -self.speed
self:move(mtv_x-5,0)
elseif fromright then
self.velocity.x = self.speed
self:move(mtv_x+5, 0)
else
if self.velocity.x > 0 then
self.velocity.x = -self.speed
elseif self.velocity.x < 0 then
self.velocity.x = self.speed
end
end
self.velocity.y = -self.speed*2
if fromup then
self:move(0,mtv_y-5)
elseif fromdown then
self:move(0,mtv_y+5)
end
end
function Skeleton:collide(dt, me, other, mtv_x, mtv_y)
if other.type == "tile" or other.type == "spike" or other.type == "breakable" or other.type == "movable" then
self:collisionWithSolid(mtv_x,mtv_y)
elseif other.type == "door" then
if not other.ref.isOpen then
self:collisionWithSolid(mtv_x,mtv_y)
end
elseif other.type == "frostbolt" then
self.thaw = self.MAXTHAW
elseif other.type == "sword" or other.type == "mace" then
if not self:isInvuln() and not self:isFrozen() then
-- ekki frosinn
self:knockback(mtv_x,mtv_y)
self:takeDamage(other.ref.damage)
elseif not self:isInvuln() and self:isFrozen() then
--frosinn
self:takeDamage(other.ref.bluntDamage)
end
end
end