Got end of level working. Added floating coffins, shatter them and collect what comes out.

This commit is contained in:
Storm Dragon
2025-02-01 19:50:13 -05:00
parent 6fda41f57b
commit 0a7052094d
8 changed files with 124 additions and 74 deletions

View File

@@ -1,6 +1,11 @@
import pygame
from libstormgames import *
from src.weapon import Weapon
class Player:
def __init__(self, xPos, yPos):
def __init__(self, xPos, yPos, sounds):
self.sounds = sounds
# Movement attributes
self.xPos = xPos
self.yPos = yPos
@@ -98,15 +103,21 @@ class Player:
return self._maxHealth
def set_health(self, value):
"""Set health and handle death if needed"""
"""Set health and handle death if needed."""
if self.isInvincible:
return # No damage while invincible
old_health = self._health
self._health = max(0, value) # Health can't go below 0
if self._health == 0:
if self._health == 0 and old_health > 0:
self._lives -= 1
# Stop all current sounds before playing death sound
pygame.mixer.stop()
cut_scene(self.sounds, 'lose_a_life')
if self._lives > 0:
self._health = 10 # Reset health if we still have lives
self._health = self._maxHealth # Reset health if we still have lives
speak(f"{self._lives} lives remaining")
def set_max_health(self, value):
"""Set max health"""