40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
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() |