-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagicarrow.lua
56 lines (46 loc) · 1.12 KB
/
magicarrow.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
require "collisions"
local magicarrow = {}
magicarrow.__index = magicarrow
function newMagicarrow(object)
local n = object
n.type = "magicarrow"
n.width = 8
n.height = 3
n.direction = n.holder.direction
n.x = n.holder.x
n.y = n.holder.y+8
n.xspeed = 0
n.anims = {}
n.anims.left = newAnimation(IMG_magicarrow_left, 8, 3, 1, 30)
n.anims.right = newAnimation(IMG_magicarrow_right, 8, 3, 1, 30)
n.anim = n.anims[n.direction]
n.t = 0
return setmetatable(n, magicarrow)
end
function magicarrow:update(dt)
self.t = self.t + 1
if self.direction == "left" then
self.xspeed = -4
else
self.xspeed = 4
end
self.x = self.x + self.xspeed
self.anim:update(dt)
if self.t >= 15 then
table.insert(effects, newSparkle({x = self.x-6, y = self.y-6}))
entities_remove(self)
return
end
solid_collisions(self)
end
function magicarrow:draw()
self.anim:draw(self.x, self.y)
end
function magicarrow:on_collide(e1, e2, dx, dy)
if e2.type == "ground" or (e2.type == "fatknight" and e2.hp > 0) then
-- sfx_magicarrow:play()
table.insert(effects, newSparkle({x = self.x-6, y = self.y-6}))
entities_remove(self)
return
end
end