summaryrefslogtreecommitdiff
path: root/src/walk_particle.lua
blob: edb81d4078488c61448323b096f0f466baa16988 (plain)
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
local anim8 = require'libs/anim8'
local Object = require'src/object'

local Particle = Object:extend()

Particle.draw_layer = 10

Particle.image =
  love.graphics.newImage'assets/art/animations/walk_particle.png'
local g = anim8.newGrid(8, 8, Particle.image:getWidth(),
  Particle.image:getHeight())

function Particle:new(x, y, dx)
  if not particles then
    return nil
  end
  self.x = x or 0
  self.x = self.x + (dx < 0 and 7 or 0)
  self.y = (y or 0) + 4
  dx = dx or 0
  self.duration = 18
  self.x = math.floor(self.x)
  self.y = math.floor(self.y)
  self.animation = anim8.newAnimation(g('1-6', 1), 3, 'pauseAtEnd')
end

function Particle:update()
  if not particles then
    self:destroy()
    return nil
  end

  if pause then return nil end

  self.animation:update(1)
  self.duration = self.duration - 1
  if self.duration == 0 then
    self:destroy()
  end
end

function Particle:draw()
  love.graphics.setColor(1, 1, 1, 1)
  if current_stage == "discroom" then
    love.graphics.setColor(0, 0, 0, 1)
  end
  self.animation:draw(Particle.image, self.x, self.y, 0, dx, 1)
end

return Particle