diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-13 19:56:54 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-14 19:17:20 +0100 |
| commit | 9ce6ae9d28c0cfe200f70e26e99c4d9abf8c250a (patch) | |
| tree | 132d2452337989672b741fff6f7ba9eea0f90798 /lua | |
| parent | refactor(popup): the popup is now passed as a whole to the animation (diff) | |
feat(pets): pets now play a death animation when killed
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets/animations.lua | 14 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 3 |
2 files changed, 15 insertions, 2 deletions
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 |