diff --git a/sounds/end_of_invincibility_warning.ogg b/sounds/end_of_invincibility_warning.ogg new file mode 100644 index 0000000..b130a6f --- /dev/null +++ b/sounds/end_of_invincibility_warning.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e25747abfd710287c48165b5b48c216a9390eb02dc40f725c53005ffd019d51 +size 13887 diff --git a/src/player.py b/src/player.py index 0370c4f..8b2598f 100644 --- a/src/player.py +++ b/src/player.py @@ -93,16 +93,32 @@ class Player: if self.currentWeapon: self.currentWeapon.attackDuration *= 0.5 # Restore attack speed del self.webPenaltyEndTime - - # Check if invincibility has expired - if self.isInvincible and currentTime - self.invincibilityStartTime >= self.invincibilityDuration: - self.isInvincible = False - speak("Invincibility wore off!") + + # Check invincibility status + if self.isInvincible: + remaining_time = (self.invincibilityStartTime + self.invincibilityDuration - currentTime) / 1000 # Convert to seconds + + # Handle countdown sounds + if not hasattr(self, '_last_countdown'): + self._last_countdown = 4 # Start counting from 4 to catch 3,2,1 + + current_second = int(remaining_time) + if current_second < self._last_countdown and current_second <= 3 and current_second > 0: + play_sound(self.sounds['end_of_invincibility_warning']) + self._last_countdown = current_second + + # Check if invincibility has expired + if currentTime - self.invincibilityStartTime >= self.invincibilityDuration: + self.isInvincible = False + speak("Invincibility wore off!") + del self._last_countdown # Clean up countdown tracker def start_invincibility(self): """Activate invincibility from Hand of Glory""" self.isInvincible = True self.invincibilityStartTime = pygame.time.get_ticks() + if hasattr(self, '_last_countdown'): + del self._last_countdown # Reset countdown if it exists def extra_life(self): """Increment lives by 1"""