| 65 | |
| 66 | |
| 67 | class CrowAnimationController: |
| 68 | def __init__(self, crow): |
| 69 | self.crow = crow |
| 70 | self.head_index = 0 |
| 71 | self.idle_index = 0 |
| 72 | self.fly_index = 0 |
| 73 | self.blink_timer = 0 |
| 74 | self.lookback_timer = 0 |
| 75 | |
| 76 | |
| 77 | # Animation speeds |
| 78 | self.head_animation_speed = 10 # frames per second |
| 79 | self.idle_animation_speed = 1 # frames per second |
| 80 | self.fly_animation_speed = 10 # frames per second |
| 81 | self.blink_interval = 10 # frames between blinks |
| 82 | self.lookback_interval = 120 # frames between lookbacks |
| 83 | |
| 84 | # Timers |
| 85 | self.idle_timer = 0 |
| 86 | self.fly_timer = 0 |
| 87 | self.blink_cooldown = 0 |
| 88 | self.lookback_cooldown = 0 |
| 89 | |
| 90 | def update(self): |
| 91 | # Update head animation based on volume |
| 92 | if self.crow.volume > 0: |
| 93 | target_index = int(len(self.crow.head) * self.crow.volume) |
| 94 | self.head_index = min(target_index, len(self.crow.head) - 1) |
| 95 | else: |
| 96 | self.head_index = 0 |
| 97 | |
| 98 | # Update idle animation |
| 99 | if not self.crow.flying: |
| 100 | self.idle_timer += 1 |
| 101 | if self.idle_timer >= (60 / self.idle_animation_speed): |
| 102 | self.idle_index = (self.idle_index + 1) % len(self.crow.idle) |
| 103 | self.idle_timer = 0 |
| 104 | |
| 105 | # Update fly animation |
| 106 | if self.crow.flying: |
| 107 | self.fly_timer += 1 |
| 108 | if self.fly_timer >= (60 / self.fly_animation_speed): |
| 109 | self.fly_index = (self.fly_index + 1) % len(self.crow.fly) |
| 110 | self.fly_timer = 0 |
| 111 | |
| 112 | # Update blink timer |
| 113 | if self.crow.volume == 0: |
| 114 | self.blink_cooldown -= 1 |
| 115 | if self.blink_cooldown <= 0: |
| 116 | self.blink_timer = self.blink_interval |
| 117 | self.blink_cooldown = random.randint(self.blink_interval, self.blink_interval * 20) |
| 118 | if random.random() < 0.1: # 10% chance to look back instead of blink |
| 119 | self.lookback_timer = 120 |
| 120 | else: |
| 121 | self.lookback_timer = 0 |
| 122 | |
| 123 | # Decrement blink timer |
| 124 | if self.blink_timer > 0: |