fixed up exercise 23 (tween cancel)
This commit is contained in:
parent
ad7365cce0
commit
16b4cd92d8
2 changed files with 14 additions and 10 deletions
6
main.lua
6
main.lua
|
|
@ -1,7 +1,7 @@
|
||||||
-- debug --
|
-- debug --
|
||||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
-- if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||||
require("lldebugger").start()
|
-- require("lldebugger").start()
|
||||||
end
|
-- end
|
||||||
|
|
||||||
-- libraries --
|
-- libraries --
|
||||||
Object = require 'lib/classic/classic'
|
Object = require 'lib/classic/classic'
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,18 @@ function Healthbar:new(x, y, hp)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Healthbar:decrease(amount)
|
function Healthbar:decrease(amount)
|
||||||
if self.hp - amount <= 0 then
|
if self.hp ~= 0 then
|
||||||
self.hp = 0
|
if fg then timer:cancel(fg) end
|
||||||
else
|
if bg then timer:cancel(bg) end
|
||||||
self.hp = self.hp - amount
|
if self.hp - amount <= 0 then
|
||||||
|
self.hp = 0
|
||||||
|
else
|
||||||
|
self.hp = self.hp - amount
|
||||||
|
end
|
||||||
|
local target_width = self.max_width * (self.hp / 100)
|
||||||
|
fg = timer:tween(0.3, self, {qwidth = target_width}, 'in-out-cubic')
|
||||||
|
bg = timer:tween(0.6, self, {lwidth = target_width}, 'in-out-cubic')
|
||||||
end
|
end
|
||||||
local target_width = self.max_width * (self.hp / 100)
|
|
||||||
timer:tween(0.3, self, {qwidth = target_width}, 'in-out-cubic')
|
|
||||||
timer:tween(0.6, self, {lwidth = target_width}, 'in-out-cubic')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Healthbar:update(dt)
|
function Healthbar:update(dt)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue