From 9ce6ae9d28c0cfe200f70e26e99c4d9abf8c250a Mon Sep 17 00:00:00 2001 From: Giuseppe Gadola Date: Mon, 13 Feb 2023 19:56:54 +0100 Subject: feat(pets): pets now play a death animation when killed --- lua/pets/animations.lua | 14 ++++++++++++++ lua/pets/pet.lua | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'lua/pets') diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 960230f..fad62e8 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -28,6 +28,7 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts) instance.actions = listdir(sourcedir) instance.frames = {} instance.popup = popup + instance.diying = false -- user options instance.row, instance.col = user_opts.row, user_opts.col @@ -82,6 +83,10 @@ function M.Animation:next_frame() end if self.frame_counter > #self.frames[self.current_action] then -- true every 8 frames M.Animation.set_next_action(self) + if self.dead then + self.timer = nil + return + end self.frame_counter = 1 end -- frames contains the images for every action @@ -93,6 +98,15 @@ end -- @function decide which action comes after the following function M.Animation:set_next_action() + if self.dying then + if self.current_action == "die" then + self.dead = true + M.Animation.stop(self) + self.popup:unmount() + end + self.current_action = "die" + return + end local next_actions = { crouch = { "liedown", "sneak", "sit" }, idle = { "idle_blink", "walk", "sit" }, diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 175e51d..a132a1e 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -47,8 +47,7 @@ end -- delete the pet :( function M.Pet:kill() - self.popup:unmount() - self.animation:stop() + self.animation.dying = true end return M -- cgit v1.3-2-g11bf