More content added, weapons, coin collecting, basic combat.

This commit is contained in:
Storm Dragon
2025-01-30 19:11:33 -05:00
parent 0d115b2bef
commit 53009373c2
10 changed files with 344 additions and 63 deletions

View File

@@ -1,5 +1,8 @@
from src.weapon import Weapon
class Player:
def __init__(self, xPos, yPos):
# Movement attributes
self.xPos = xPos
self.yPos = yPos
self.moveSpeed = 0.05
@@ -7,7 +10,76 @@ class Player:
self.jumpStartTime = 0
self.isJumping = False
self.facingRight = True
self.collectedItems = []
# Track distance for footsteps
# Stats and tracking
self._health = 10
self._lives = 1
self.distanceSinceLastStep = 0
self.stepDistance = 0.5 # Play a step sound every 0.5 units moved
self.stepDistance = 0.5
# Inventory system
self.inventory = []
self.collectedItems = []
self.coins = 0
# Combat related attributes
self.weapons = []
self.currentWeapon = None
self.isAttacking = False
self.lastAttackTime = 0
# Initialize starting weapon (rusty shovel)
self.add_weapon(Weapon(
name="rusty_shovel",
damage=2,
range=2,
attackSound="player_shovel_attack",
hitSound="player_shovel_hit",
attackDuration=200 # 200ms attack duration
))
def get_health(self):
"""Get current health"""
return self._health
def set_health(self, value):
"""Set health and handle death if needed"""
self._health = max(0, value) # Health can't go below 0
if self._health == 0:
self._lives -= 1
if self._lives > 0:
self._health = 10 # Reset health if we still have lives
def get_lives(self):
"""Get remaining lives"""
return self._lives
def add_weapon(self, weapon):
"""Add a new weapon to inventory and equip if first weapon"""
self.weapons.append(weapon)
if len(self.weapons) == 1: # If this is our first weapon, equip it
self.equip_weapon(weapon)
def equip_weapon(self, weapon):
"""Equip a specific weapon"""
if weapon in self.weapons:
self.currentWeapon = weapon
def add_item(self, item):
"""Add an item to inventory"""
self.inventory.append(item)
self.collectedItems.append(item)
def start_attack(self, currentTime):
"""Attempt to start an attack with the current weapon"""
if self.currentWeapon and self.currentWeapon.start_attack(currentTime):
self.isAttacking = True
self.lastAttackTime = currentTime
return True
return False
def get_attack_range(self, currentTime):
"""Get the current attack's range based on position and facing direction"""
if not self.currentWeapon or not self.currentWeapon.is_attack_active(currentTime):
return None
return self.currentWeapon.get_attack_range(self.xPos, self.facingRight)