From ce742ae7076f0df62832c2e9f037713d55a80cd8 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 21:44:06 +0200 Subject: [PATCH] Add actors/ghost_mode_controller.py --- actors/ghost_mode_controller.py | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 actors/ghost_mode_controller.py diff --git a/actors/ghost_mode_controller.py b/actors/ghost_mode_controller.py new file mode 100644 index 0000000..634d232 --- /dev/null +++ b/actors/ghost_mode_controller.py @@ -0,0 +1,40 @@ +import time +from enums import GhostMode + +class GhostModeController: + def __init__(self): + self.timers = [ + (GhostMode.SCATTER, 7), + (GhostMode.CHASE, 20), + (GhostMode.SCATTER, 7), + (GhostMode.CHASE, 20), + (GhostMode.SCATTER, 5), + (GhostMode.CHASE, 9999) # stay in chase mode eventually + ] + self.current_index = 0 + self.last_switch_time = time.time() + self.mode = self.timers[self.current_index][0] + self.frightened_until = 0 + + def update(self): + now = time.time() + + if self.mode == GhostMode.FRIGHTENED: + if now > self.frightened_until: + self.resume_cycle() + return + + mode, duration = self.timers[self.current_index] + if now - self.last_switch_time >= duration: + self.current_index = min(self.current_index + 1, len(self.timers) - 1) + self.mode = self.timers[self.current_index][0] + self.last_switch_time = now + + def trigger_frightened(self, duration=6): + self.mode = GhostMode.FRIGHTENED + self.frightened_until = time.time() + duration + + def resume_cycle(self): + # Return to normal cycle after frightened ends + self.mode = self.timers[self.current_index][0] + self.last_switch_time = time.time() \ No newline at end of file