Some minor cleanup.

This commit is contained in:
Storm Dragon
2025-03-21 20:54:13 -04:00
parent cb69189c8e
commit 87d0764156
16 changed files with 193 additions and 193 deletions

View File

@@ -18,7 +18,7 @@ class Enemy(Object):
isStatic=False,
isHazard=True
)
# Enemy specific properties
self.enemyType = enemyType
self.level = level
@@ -26,7 +26,7 @@ class Enemy(Object):
self.damage = kwargs.get('damage', 1) # Default 1 damage
self.attackRange = kwargs.get('attack_range', 1) # Default 1 tile range
self.sounds = sounds # Store reference to game sounds
# Movement and behavior properties
self.movingRight = True # Initial direction
self.movementSpeed = 0.03 # Base speed
@@ -35,7 +35,7 @@ class Enemy(Object):
self.lastAttackTime = 0
self.attackCooldown = 1000 # 1 second between attacks
self._currentX = self.xRange[0] # Initialize current position
# Add spawn configuration
self.canSpawn = kwargs.get('can_spawn', False)
if self.canSpawn:
@@ -48,7 +48,7 @@ class Enemy(Object):
# Attack pattern configuration
self.attackPattern = kwargs.get('attack_pattern', {'type': 'patrol'})
self.turnThreshold = self.attackPattern.get('turn_threshold', 5)
# Initialize vulnerability system
self.hasVulnerabilitySystem = kwargs.get('has_vulnerability', False)
if self.hasVulnerabilitySystem:
@@ -73,18 +73,18 @@ class Enemy(Object):
self.attackPattern = {'type': 'hunter'} # Spiders actively hunt the player
self.turnThreshold = 3 # Spiders turn around quickly to chase player
@property
def xPos(self):
"""Current x position"""
return self._currentX
@xPos.setter
def xPos(self, value):
"""Set current x position"""
self._currentX = value
def patrol_movement(self):
"""Standard back-and-forth patrol movement"""
if self.movingRight:
@@ -100,7 +100,7 @@ class Enemy(Object):
"""Update enemy position and handle attacks"""
if not self.isActive or self.health <= 0:
return
# Initialize sound for enemies with vulnerability system immediately upon creation
if self.hasVulnerabilitySystem:
if self.channel is None:
@@ -109,12 +109,12 @@ class Enemy(Object):
# Update existing channel position
else:
self.channel = obj_update(self.channel, player.xPos, self.xPos)
# Check for vulnerability state change
if currentTime - self.vulnerabilityTimer >= (self.vulnerabilityDuration if self.isVulnerable else self.invulnerabilityDuration):
self.isVulnerable = not self.isVulnerable
self.vulnerabilityTimer = currentTime
if self.channel:
obj_stop(self.channel)
soundName = f"{self.enemyType}_is_vulnerable" if self.isVulnerable else self.enemyType
@@ -124,17 +124,17 @@ class Enemy(Object):
if not self.hunting:
if self.patrolStart <= player.xPos <= self.patrolEnd:
self.hunting = True
# Handle movement based on enemy type and pattern
if (self.enemyType == "zombie" or
(self.attackPattern['type'] == 'hunter' and self.hunting)):
distanceToPlayer = player.xPos - self.xPos
# If we've moved past the player by more than the turn threshold, turn around
if abs(distanceToPlayer) >= self.turnThreshold:
self.movingRight = distanceToPlayer > 0
# Otherwise keep moving in current direction
self.xPos += self.movementSpeed if self.movingRight else -self.movementSpeed
@@ -152,7 +152,7 @@ class Enemy(Object):
# Check for attack opportunity
if self.can_attack(currentTime, player):
self.attack(currentTime, player)
if self.canSpawn:
if currentTime - self.lastSpawnTime >= self.spawnCooldown:
distanceToPlayer = abs(player.xPos - self.xPos)
@@ -197,22 +197,22 @@ class Enemy(Object):
# Must have cooled down from last attack
if currentTime - self.lastAttackTime < self.attackCooldown:
return False
# Don't attack if player is jumping
if player.isJumping:
return False
# Check if player is in range and on same side we're facing
distance = abs(player.xPos - self.xPos)
tolerance = 0.5 # Same tolerance as we used for the grave
if distance <= (self.attackRange + tolerance):
# Only attack if we're facing the right way
playerOnRight = player.xPos > self.xPos
return playerOnRight == self.movingRight
return False
def attack(self, currentTime, player):
"""Perform attack on player"""
if player.isInvincible: return
@@ -224,7 +224,7 @@ class Enemy(Object):
# Deal damage to player
player.set_health(player.get_health() - self.damage)
self.sounds['player_takes_damage'].play()
def take_damage(self, amount):
"""Handle enemy taking damage"""
if self.hasVulnerabilitySystem and not self.isVulnerable:
@@ -233,7 +233,7 @@ class Enemy(Object):
self.health -= amount
if self.health <= 0:
self.die()
def die(self):
"""Handle enemy death"""
self.isActive = False
@@ -247,7 +247,7 @@ class Enemy(Object):
rangeModifier = self.attackRange * 250
speedModifier = int(self.movementSpeed * 1000)
totalPoints = max(basePoints + damageModifier + rangeModifier + speedModifier, 1000)
# Award points
self.level.levelScore += totalPoints
@@ -263,12 +263,12 @@ class Enemy(Object):
hasNunchucks = any(weapon.name == "nunchucks" for weapon in self.level.player.weapons)
# Drop witch_broom only if player has neither broom nor nunchucks
itemType = "witch_broom" if not (hasBroom or hasNunchucks) else "cauldron"
# Create drop 1-2 tiles away in random direction
direction = random.choice([-1, 1])
dropDistance = random.randint(1, 2)
dropX = self.xPos + (direction * dropDistance)
droppedItem = PowerUp(
dropX,
self.yPos,