-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspark.lua
More file actions
47 lines (37 loc) · 915 Bytes
/
Copy pathspark.lua
File metadata and controls
47 lines (37 loc) · 915 Bytes
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
local spark = {}
function spark:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function spark:update(dt)
if ctime > self.birth_time + self.duration then
self:die()
end
if self.gravity_multiplier then
self.dy = self.dy + (self.gravity_multiplier * gravity * dt)
end
self.x = self.x + (self.dx * dt)
self.y = self.y + (self.dy * dt)
end
function spark:die()
sparks[self.id] = nil
end
function spark:draw()
n = img.tile[self.sprite]['n'] or 1
if n ~= 1 then
-- figure out which frame we want
frame = 1 + self:anim_time() % n
else
frame = 1
end
love.graphics.setColor(self.color)
love.graphics.draw(img.tileset, img.tile[self.sprite][frame],
camera.view_x(self), camera.view_y(self), self.r, self.sx, self.sy,
self.center_x, self.center_y)
end
function spark:anim_time()
return math.floor(10 * (ctime - self.birth_time))
end
return spark