Some minor cleanup.
This commit is contained in:
		| @@ -20,15 +20,15 @@ class Pumpkin: | ||||
|         """Update pumpkin position and sound""" | ||||
|         if not self.isActive: | ||||
|             return False | ||||
|          | ||||
|  | ||||
|         self.x += self.direction * self.speed | ||||
|          | ||||
|  | ||||
|         # Update or start positional audio | ||||
|         if self.soundChannel is None or not self.soundChannel.get_busy(): | ||||
|             self.soundChannel = obj_play(sounds, self.soundName, playerX, self.x) | ||||
|         else: | ||||
|             self.soundChannel = obj_update(self.soundChannel, playerX, self.x) | ||||
|              | ||||
|  | ||||
|         return True | ||||
|  | ||||
|     def stop_sound(self, sounds, playerX): | ||||
| @@ -45,7 +45,7 @@ class Pumpkin: | ||||
|         """Check if pumpkin hits player""" | ||||
|         if not self.isActive: | ||||
|             return False | ||||
|              | ||||
|  | ||||
|         distance = abs(player.xPos - self.x) | ||||
|         if distance < 1:  # Within 1 tile | ||||
|             if self.isHigh and not player.isJumping: | ||||
| @@ -75,21 +75,21 @@ class Catapult(Object): | ||||
|     def fire(self, currentTime, player): | ||||
|         """Start the firing sequence""" | ||||
|         self.lastFireTime = currentTime | ||||
|      | ||||
|  | ||||
|         # Play launch sound using directional audio | ||||
|         play_directional_sound(self.sounds, 'catapult_launch', player.xPos, self.xPos) | ||||
|      | ||||
|  | ||||
|         # Set up pending pumpkin | ||||
|         isHigh = random.choice([True, False]) | ||||
|         fireDirection = 1 if player.xPos > self.xPos else -1 | ||||
|      | ||||
|  | ||||
|         # Store pumpkin data for later creation | ||||
|         self.pendingPumpkin = { | ||||
|             'isHigh': isHigh, | ||||
|             'direction': fireDirection, | ||||
|             'playerMaxHealth': player.get_max_health() | ||||
|         } | ||||
|      | ||||
|  | ||||
|         # Set when to actually launch the pumpkin | ||||
|         self.pumpkinLaunchTime = currentTime + self.launchDelay | ||||
|  | ||||
| @@ -97,11 +97,11 @@ class Catapult(Object): | ||||
|         """Update catapult and its pumpkins""" | ||||
|         if not self.isActive: | ||||
|             return | ||||
|              | ||||
|  | ||||
|         # Check if player is in range | ||||
|         distance = abs(player.xPos - self.xPos) | ||||
|         inRange = distance <= self.firingRange | ||||
|          | ||||
|  | ||||
|         # Handle entering/leaving range | ||||
|         if inRange and not self.isFiring: | ||||
|             self.isFiring = True | ||||
| @@ -110,7 +110,7 @@ class Catapult(Object): | ||||
|         elif not inRange and self.isFiring: | ||||
|             self.isFiring = False | ||||
|             speak("Out of pumpkin catapult range.") | ||||
|              | ||||
|  | ||||
|         # Check for pending pumpkin launch | ||||
|         if self.pendingPumpkin and currentTime >= self.pumpkinLaunchTime: | ||||
|             # Create and fire the pending pumpkin | ||||
| @@ -122,18 +122,18 @@ class Catapult(Object): | ||||
|             ) | ||||
|             self.activePumpkins.append(pumpkin) | ||||
|             self.pendingPumpkin = None | ||||
|              | ||||
|  | ||||
|         # Only start new fire sequence if in range and enough time has passed | ||||
|         if self.isFiring and currentTime - self.lastFireTime >= self.fireInterval: | ||||
|             self.fire(currentTime, player) | ||||
|              | ||||
|  | ||||
|         # Always update existing pumpkins | ||||
|         for pumpkin in self.activePumpkins[:]:  # Copy list to allow removal | ||||
|             if not pumpkin.update(self.sounds, player.xPos): | ||||
|                 pumpkin.stop_sound(self.sounds, player.xPos) | ||||
|                 self.activePumpkins.remove(pumpkin) | ||||
|                 continue | ||||
|                  | ||||
|  | ||||
|             if pumpkin.check_collision(player): | ||||
|                 player.set_health(player.get_health() - pumpkin.damage) | ||||
|                 pumpkin.stop_sound(self.sounds, player.xPos) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user