Code cleanup, added more functionality. Floating coffins that spawn items, graves can spawn zombies, etc.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from src.weapon import Weapon
|
||||
|
||||
class Player:
|
||||
def __init__(self, xPos, yPos):
|
||||
# Movement attributes
|
||||
@@ -28,6 +27,14 @@ class Player:
|
||||
self.isAttacking = False
|
||||
self.lastAttackTime = 0
|
||||
|
||||
# Power-up states
|
||||
self.isInvincible = False
|
||||
self.invincibilityStartTime = 0
|
||||
self.invincibilityDuration = 5000 # 5 seconds of invincibility
|
||||
|
||||
# Projectiles
|
||||
self.projectiles = [] # List of type and quantity tuples
|
||||
|
||||
# Initialize starting weapon (rusty shovel)
|
||||
self.add_weapon(Weapon(
|
||||
name="rusty_shovel",
|
||||
@@ -38,12 +45,58 @@ class Player:
|
||||
attackDuration=200 # 200ms attack duration
|
||||
))
|
||||
|
||||
def update(self, currentTime):
|
||||
"""Update player state"""
|
||||
# Check if invincibility has expired
|
||||
if self.isInvincible and currentTime - self.invincibilityStartTime >= self.invincibilityDuration:
|
||||
self.isInvincible = False
|
||||
speak("Invincibility wore off!")
|
||||
|
||||
def start_invincibility(self):
|
||||
"""Activate invincibility from Hand of Glory"""
|
||||
self.isInvincible = True
|
||||
self.invincibilityStartTime = pygame.time.get_ticks()
|
||||
|
||||
def add_projectile(self, projectile_type):
|
||||
"""Add a projectile to inventory"""
|
||||
# Find if we already have this type
|
||||
for proj in self.projectiles:
|
||||
if proj[0] == projectile_type:
|
||||
proj[1] += 1 # Increase quantity
|
||||
speak(f"Now have {proj[1]} {projectile_type}s")
|
||||
return
|
||||
|
||||
# If not found, add new type with quantity 1
|
||||
self.projectiles.append([projectile_type, 1])
|
||||
|
||||
def throw_projectile(self):
|
||||
"""Throw the first available projectile"""
|
||||
if not self.projectiles:
|
||||
speak("No projectiles to throw!")
|
||||
return None
|
||||
|
||||
# Get the first projectile type
|
||||
projectile = self.projectiles[0]
|
||||
projectile[1] -= 1 # Decrease quantity
|
||||
|
||||
if projectile[1] <= 0:
|
||||
self.projectiles.pop(0) # Remove if none left
|
||||
|
||||
return {
|
||||
'type': projectile[0],
|
||||
'start_x': self.xPos,
|
||||
'direction': 1 if self.facingRight else -1
|
||||
}
|
||||
|
||||
def get_health(self):
|
||||
"""Get current health"""
|
||||
return self._health
|
||||
|
||||
def set_health(self, value):
|
||||
"""Set health and handle death if needed"""
|
||||
if self.isInvincible:
|
||||
return # No damage while invincible
|
||||
|
||||
self._health = max(0, value) # Health can't go below 0
|
||||
if self._health == 0:
|
||||
self._lives -= 1
|
||||
|
Reference in New Issue
Block a user