Hopefully fixed a race condition where you could be killed while getting a cauldron and come back to life. Added sound for fill in grave and for survivor bonus.
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								sounds/fill_in_grave.ogg
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								sounds/fill_in_grave.ogg
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								sounds/survivor_bonus.ogg
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								sounds/survivor_bonus.ogg
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										11
									
								
								src/level.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/level.py
									
									
									
									
									
								
							| @@ -366,8 +366,8 @@ class Level: | |||||||
|             if not obj.is_in_range(self.player.xPos): |             if not obj.is_in_range(self.player.xPos): | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             # Handle collectibles |             # Handle collectibles (but not if player died this frame) | ||||||
|             if obj.isCollectible and self.player.isJumping: |             if obj.isCollectible and self.player.isJumping and not self.player.diedThisFrame: | ||||||
|                 currentPos = round(self.player.xPos) |                 currentPos = round(self.player.xPos) | ||||||
|                 if currentPos not in obj.collectedPositions: |                 if currentPos not in obj.collectedPositions: | ||||||
|                     play_sound(self.sounds[f'get_{obj.soundName}']) |                     play_sound(self.sounds[f'get_{obj.soundName}']) | ||||||
| @@ -400,7 +400,7 @@ class Level: | |||||||
|                                     self.player._coins = 0 |                                     self.player._coins = 0 | ||||||
|                                     self.levelScore += 2000  # Double score bonus instead of extra life |                                     self.levelScore += 2000  # Double score bonus instead of extra life | ||||||
|                                     speak("100 bone dust collected! Bonus score!") |                                     speak("100 bone dust collected! Bonus score!") | ||||||
|                                     play_sound(self.sounds['bone_dust']) |                                     play_sound(self.sounds.get('survivor_bonus', 'bone_dust'))  # Use survivor_bonus sound if available, fallback to bone_dust | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             # Handle spiderweb - this should trigger for both walking and jumping if not ducking |             # Handle spiderweb - this should trigger for both walking and jumping if not ducking | ||||||
| @@ -425,12 +425,13 @@ class Level: | |||||||
|             # Handle graves and other hazards |             # Handle graves and other hazards | ||||||
|             if obj.isHazard and not self.player.isJumping: |             if obj.isHazard and not self.player.isJumping: | ||||||
|                 if isinstance(obj, GraveObject): |                 if isinstance(obj, GraveObject): | ||||||
|                     can_collect = obj.collect_grave_item(self.player) |                     can_collect = obj.collect_grave_item(self.player) and not self.player.diedThisFrame | ||||||
|                     can_fill = obj.can_fill_grave(self.player) |                     can_fill = obj.can_fill_grave(self.player) | ||||||
|  |  | ||||||
|                     if can_collect: |                     if can_collect: | ||||||
|                         # Successfully collected item while ducking with shovel |                         # Successfully collected item while ducking with shovel | ||||||
|                         play_sound(self.sounds[f'get_{obj.graveItem}']) |                         play_sound(self.sounds[f'get_{obj.graveItem}']) | ||||||
|  |                         play_sound(self.sounds.get('fill_in_grave', 'shovel_dig'))  # Also play fill sound | ||||||
|                         self.player.stats.update_stat('Items collected', 1) |                         self.player.stats.update_stat('Items collected', 1) | ||||||
|                         # Create PowerUp to handle the item effect |                         # Create PowerUp to handle the item effect | ||||||
|                         item = PowerUp(obj.xPos, obj.yPos, obj.graveItem, self.sounds, 1, |                         item = PowerUp(obj.xPos, obj.yPos, obj.graveItem, self.sounds, 1, | ||||||
| @@ -446,7 +447,7 @@ class Level: | |||||||
|                         continue |                         continue | ||||||
|                     elif can_fill and obj.fill_grave(self.player): |                     elif can_fill and obj.fill_grave(self.player): | ||||||
|                         # Successfully filled empty grave with shovel |                         # Successfully filled empty grave with shovel | ||||||
|                         play_sound(self.sounds.get('shovel_dig', obj.soundName))  # Use dig sound if available |                         play_sound(self.sounds.get('fill_in_grave', 'shovel_dig'))  # Use fill_in_grave sound if available, fallback to shovel_dig | ||||||
|                         self.player.stats.update_stat('Graves filled', 1) |                         self.player.stats.update_stat('Graves filled', 1) | ||||||
|                         # Stop grave's current audio channel |                         # Stop grave's current audio channel | ||||||
|                         if obj.channel: |                         if obj.channel: | ||||||
|   | |||||||
| @@ -58,6 +58,9 @@ class Player: | |||||||
|         self.isInvincible = False |         self.isInvincible = False | ||||||
|         self.invincibilityStartTime = 0 |         self.invincibilityStartTime = 0 | ||||||
|         self.invincibilityDuration = 10000  # 10 seconds of invincibility |         self.invincibilityDuration = 10000  # 10 seconds of invincibility | ||||||
|  |          | ||||||
|  |         # Death state tracking (to prevent revival after death in same frame) | ||||||
|  |         self.diedThisFrame = False | ||||||
|  |  | ||||||
|         # Initialize starting weapon (rusty shovel) |         # Initialize starting weapon (rusty shovel) | ||||||
|         self.add_weapon(Weapon( |         self.add_weapon(Weapon( | ||||||
| @@ -92,6 +95,9 @@ class Player: | |||||||
|  |  | ||||||
|     def update(self, currentTime): |     def update(self, currentTime): | ||||||
|         """Update player state""" |         """Update player state""" | ||||||
|  |         # Reset death flag at start of each frame | ||||||
|  |         self.diedThisFrame = False | ||||||
|  |          | ||||||
|         if hasattr(self, 'webPenaltyEndTime'): |         if hasattr(self, 'webPenaltyEndTime'): | ||||||
|             if currentTime >= self.webPenaltyEndTime: |             if currentTime >= self.webPenaltyEndTime: | ||||||
|                 self.moveSpeed *= 2  # Restore speed |                 self.moveSpeed *= 2  # Restore speed | ||||||
| @@ -218,6 +224,8 @@ class Player: | |||||||
|  |  | ||||||
|         if self._health == 0 and old_health > 0: |         if self._health == 0 and old_health > 0: | ||||||
|             self._lives -= 1 |             self._lives -= 1 | ||||||
|  |             # Mark that player died this frame to prevent revival | ||||||
|  |             self.diedThisFrame = True | ||||||
|             # Stop all current sounds before playing death sound |             # Stop all current sounds before playing death sound | ||||||
|             pygame.mixer.stop() |             pygame.mixer.stop() | ||||||
|             try: |             try: | ||||||
|   | |||||||
| @@ -74,6 +74,7 @@ class PowerUp(Object): | |||||||
|                 # In survival mode, give bonus score instead |                 # In survival mode, give bonus score instead | ||||||
|                 level.levelScore += 2000 |                 level.levelScore += 2000 | ||||||
|                 speak("Extra life found! Bonus score in survival mode!") |                 speak("Extra life found! Bonus score in survival mode!") | ||||||
|  |                 play_sound(self.sounds.get('survivor_bonus', 'get_extra_life'))  # Use survivor_bonus sound if available | ||||||
|             else: |             else: | ||||||
|                 player.extra_life() |                 player.extra_life() | ||||||
|         elif self.item_type == 'shin_bone':  # Add shin bone handling |         elif self.item_type == 'shin_bone':  # Add shin bone handling | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user