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 --
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
require("lldebugger").start()
|
||||
end
|
||||
-- if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
-- require("lldebugger").start()
|
||||
-- end
|
||||
|
||||
-- libraries --
|
||||
Object = require 'lib/classic/classic'
|
||||
|
|
|
|||
|
|
@ -10,14 +10,18 @@ function Healthbar:new(x, y, hp)
|
|||
end
|
||||
|
||||
function Healthbar:decrease(amount)
|
||||
if self.hp - amount <= 0 then
|
||||
self.hp = 0
|
||||
else
|
||||
self.hp = self.hp - amount
|
||||
if self.hp ~= 0 then
|
||||
if fg then timer:cancel(fg) end
|
||||
if bg then timer:cancel(bg) end
|
||||
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
|
||||
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
|
||||
|
||||
function Healthbar:update(dt)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue