-
Notifications
You must be signed in to change notification settings - Fork 0
/
gust.lua
42 lines (38 loc) · 1.16 KB
/
gust.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
require("lovepunk.entity")
Gust = Entity.new(0, 0, 8, 8)
Gust.__index = Gust
function Gust.new(x, y, v)
local self = setmetatable({}, Gust)
self.x = x
self.y = y
if (math.abs(v.y) > math.abs(v.x)) then
if (v.y > 0) then self.rotation = toRadians(90) end
if (v.y < 0) then self.rotation = toRadians(-90) end
elseif math.abs(v.x) > math.abs(v.y) then
if (v.x <= 0) then self.scaleX = -1 end
end
self.lifetime = 0.2
self.type = "gust"
self.image = love.graphics.newImage("assets/img/gust.png")
local anim8 = require "libs.anim8"
local grid = anim8.newGrid(8, 8, self.image:getWidth(), self.image:getHeight())
self.anim = anim8.newAnimation(grid('1-3', 1), {self.lifetime/2, self.lifetime/4, self.lifetime/4})
self.counter = 0
self.layer = -5
self.v = v
return self
end
function Gust:update(dt)
self.anim:update(dt)
self.lifetime = self.lifetime - dt
if (self.lifetime < 0) then
self.scene:remove(self)
end
self.v.x = self.v.x * 0.9
self.v.y = self.v.y * 0.9
self.x = self.x + self.v.x
self.y = self.y + self.v.y
end
function Gust:draw()
self.anim:draw(self.image, self.x, self.y, self.rotation, self.scaleX, self.scaleY, self.originX, self.originY)
end