Fixed attack sound sometimes not playing. Fixed a problem where a single attack was doing multiple attack damage. The means I reaqlly need to reword the first three levels, because they are very hard now lol.
This commit is contained in:
		| @@ -138,4 +138,4 @@ class Catapult(Object): | ||||
|                 pumpkin.stop_sound(self.sounds, player.xPos) | ||||
|                 pumpkin.isActive = False | ||||
|                 self.activePumpkins.remove(pumpkin) | ||||
|                 speak("Hit by a pumpkin!") | ||||
|                 self.sounds['player_takes_damage'].play() | ||||
|   | ||||
							
								
								
									
										15
									
								
								src/level.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/level.py
									
									
									
									
									
								
							| @@ -198,19 +198,14 @@ class Level: | ||||
|         # Only get attack range if attack is active | ||||
|         if self.player.currentWeapon and self.player.currentWeapon.is_attack_active(currentTime): | ||||
|             attackRange = self.player.currentWeapon.get_attack_range(self.player.xPos, self.player.facingRight) | ||||
|          | ||||
|  | ||||
|             # Check for enemy hits | ||||
|             for enemy in self.enemies: | ||||
|                 if enemy.isActive and enemy.xPos >= attackRange[0] and enemy.xPos <= attackRange[1]: | ||||
|                     if self.weapon_hit_channel is None or not self.weapon_hit_channel.get_busy(): | ||||
|                         self.weapon_hit_channel = self.sounds[self.player.currentWeapon.hitSound].play() | ||||
|                         self.weapon_hit_channel = play_sound(self.sounds[self.player.currentWeapon.hitSound]) | ||||
|  | ||||
|                     enemy.take_damage(self.player.currentWeapon.damage) | ||||
|                 else: | ||||
|                     # Reset weapon hit channel when not attacking | ||||
|                     if self.weapon_hit_channel is not None and not self.weapon_hit_channel.get_busy(): | ||||
|                         self.weapon_hit_channel = None | ||||
|                     # Only damage and play sound if this is a new hit for this attack | ||||
|                     if self.player.currentWeapon.register_hit(enemy, currentTime): | ||||
|                         play_sound(self.sounds[self.player.currentWeapon.hitSound]) | ||||
|                         enemy.take_damage(self.player.currentWeapon.damage) | ||||
|  | ||||
|             # Check for coffin hits | ||||
|             for obj in self.objects: | ||||
|   | ||||
| @@ -8,6 +8,7 @@ class Weapon: | ||||
|         self.cooldown = cooldown  # Milliseconds between attacks | ||||
|         self.attackDuration = attackDuration  # Milliseconds the attack is active | ||||
|         self.lastAttackTime = 0 | ||||
|         self.hitEnemies = set() | ||||
|          | ||||
|     def can_attack(self, currentTime): | ||||
|         """Check if enough time has passed since last attack""" | ||||
| @@ -24,6 +25,7 @@ class Weapon: | ||||
|         """Begin an attack and return True if allowed""" | ||||
|         if self.can_attack(currentTime): | ||||
|             self.lastAttackTime = currentTime | ||||
|             self.hitEnemies.clear()  # Clear hit enemies for new attack | ||||
|             return True | ||||
|         return False | ||||
|          | ||||
| @@ -31,3 +33,11 @@ class Weapon: | ||||
|         """Check if the attack is still in its active frames""" | ||||
|         timeSinceAttack = currentTime - self.lastAttackTime | ||||
|         return 0 <= timeSinceAttack <= self.attackDuration | ||||
|  | ||||
|     def register_hit(self, enemy, currentTime): | ||||
|         """Register a hit on an enemy for this attack. Returns True if it's a new hit.""" | ||||
|         if self.is_attack_active(currentTime): | ||||
|             if enemy not in self.hitEnemies: | ||||
|                 self.hitEnemies.add(enemy) | ||||
|                 return True | ||||
|         return False | ||||
|   | ||||
		Reference in New Issue
	
	Block a user