From 33f6597d37b4b9bee4d8e39e396dc3e9774e7459 Mon Sep 17 00:00:00 2001 From: Giuseppe Gadola Date: Sat, 11 Feb 2023 17:51:20 +0100 Subject: feat(animations): set next action dinamically --- lua/pets/animations.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lua') diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 35ff5b8..e49883e 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -61,6 +61,7 @@ function M.Animation:next_frame() self.current_image:delete(0, { free = false }) end if self.frame_counter > #self.frames[self.current_action] then + M.Animation.set_next_action(self) self.frame_counter = 1 end local image = self.frames[self.current_action][self.frame_counter] @@ -69,6 +70,21 @@ function M.Animation:next_frame() self.current_image = image end +function M.Animation:set_next_action() + local next_actions = { + crouch = { "liedown", "sneak", "sit" }, + idle = { "idle_blink", "walk", "sit" }, + idle_blink = { "idle", "walk", "sit" }, + liedown = { "sneak", "crouch" }, + sit = { "idle", "idle_blink", "crouch", "liedown" }, + sneak = { "crouch", "walk", "liedown" }, + walk = { "idle", "idle_blink" }, + } + if math.random() < 0.5 then + self.current_action = next_actions[self.current_action][math.random(#next_actions[self.current_action])] + end +end + function M.Animation:set_next_col() if self.current_action == "walk" then if self.col < self.popup_width - 5 then -- cgit v1.3-2-g11bf