diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-11 17:51:20 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-11 17:51:20 +0100 |
| commit | 33f6597d37b4b9bee4d8e39e396dc3e9774e7459 (patch) | |
| tree | 6578353427375c890f80681c33f32f9b26789452 /lua | |
| parent | feat(animations): set next position based on current action (diff) | |
feat(animations): set next action dinamically
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets/animations.lua | 16 |
1 files changed, 16 insertions, 0 deletions
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 |