-
Notifications
You must be signed in to change notification settings - Fork 0
/
Heart.lua
47 lines (39 loc) · 1.62 KB
/
Heart.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
Heart = Object:extend()
Heart.Animation = {}
for i=0, 3 do
table.insert(Heart.Animation, love.graphics.newImage("images/animations/heart_" .. i .. ".png"))
end
Heart.AnimationContainer = {}
for i=0, 3 do
table.insert(Heart.AnimationContainer, love.graphics.newImage("images/animations/heart_container_" .. i .. ".png"))
end
function Heart:new(x, y, container)
self.rect = createRect(x, y, 20, 20, "static", 1)
self.rect.body:setFixedRotation(true)
self.container = container
if not self.container then
self.rect.fixture:setUserData("Heart")
else
self.rect.fixture:setUserData("HeartContainer")
end
self.AnimationTimer = 1
end
function Heart:update(dt)
self.AnimationTimer = self.AnimationTimer + dt * 5
if self.AnimationTimer >= 5 then
self.AnimationTimer = 1
end
end
function Heart:draw()
local x = self.rect.body:getX() - self.rect.width / 2
local y = self.rect.body:getY() - self.rect.height / 2
if not self.container then
love.graphics.draw(self.Animation[math.floor(self.AnimationTimer)], x, y, 0,
self.rect.width / self.Animation[math.floor(self.AnimationTimer)]:getWidth(),
self.rect.height / self.Animation[math.floor(self.AnimationTimer)]:getHeight())
else
love.graphics.draw(self.AnimationContainer[math.floor(self.AnimationTimer)], x, y, 0,
self.rect.width / self.AnimationContainer[math.floor(self.AnimationTimer)]:getWidth(),
self.rect.height / self.AnimationContainer[math.floor(self.AnimationTimer)]:getHeight())
end
end