Added points system with scoreboard.
This commit is contained in:
Submodule libstormgames updated: 7cbbc64d27...c242fc6832
@@ -24,6 +24,7 @@ class CoffinObject(Object):
|
|||||||
if not self.isBroken:
|
if not self.isBroken:
|
||||||
self.isBroken = True
|
self.isBroken = True
|
||||||
play_sound(self.sounds['coffin_shatter'])
|
play_sound(self.sounds['coffin_shatter'])
|
||||||
|
self.level.levelScore += 500
|
||||||
self.level.player.stats.update_stat('Coffins broken', 1)
|
self.level.player.stats.update_stat('Coffins broken', 1)
|
||||||
|
|
||||||
# Stop the ongoing coffin sound
|
# Stop the ongoing coffin sound
|
||||||
|
|||||||
11
src/enemy.py
11
src/enemy.py
@@ -226,6 +226,17 @@ class Enemy(Object):
|
|||||||
if self.channel:
|
if self.channel:
|
||||||
obj_stop(self.channel)
|
obj_stop(self.channel)
|
||||||
self.channel = None
|
self.channel = None
|
||||||
|
|
||||||
|
# Calculate and award points based on enemy stats
|
||||||
|
basePoints = self.health * 500
|
||||||
|
damageModifier = self.damage * 750
|
||||||
|
rangeModifier = self.attackRange * 250
|
||||||
|
speedModifier = int(self.movementSpeed * 1000)
|
||||||
|
totalPoints = max(basePoints + damageModifier + rangeModifier + speedModifier, 1000)
|
||||||
|
|
||||||
|
# Award points
|
||||||
|
self.level.levelScore += totalPoints
|
||||||
|
|
||||||
# Play death sound if available using positional audio
|
# Play death sound if available using positional audio
|
||||||
deathSound = f"{self.enemyType}_dies"
|
deathSound = f"{self.enemyType}_dies"
|
||||||
if deathSound in self.sounds:
|
if deathSound in self.sounds:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Level:
|
|||||||
self.isLocked = levelData.get("locked", False) # Default to False if not specified
|
self.isLocked = levelData.get("locked", False) # Default to False if not specified
|
||||||
self.levelId = levelData["level_id"]
|
self.levelId = levelData["level_id"]
|
||||||
self.levelName = levelData.get("name", "Unnamed Level")
|
self.levelName = levelData.get("name", "Unnamed Level")
|
||||||
|
self.levelScore = 0
|
||||||
|
|
||||||
# Get footstep sound for this level, default to 'footstep' if not specified
|
# Get footstep sound for this level, default to 'footstep' if not specified
|
||||||
self.footstepSound = levelData.get("footstep_sound", "footstep")
|
self.footstepSound = levelData.get("footstep_sound", "footstep")
|
||||||
@@ -242,6 +243,7 @@ class Level:
|
|||||||
if abs(item._currentX - self.player.xPos) < 1 and self.player.isJumping:
|
if abs(item._currentX - self.player.xPos) < 1 and self.player.isJumping:
|
||||||
play_sound(self.sounds[f'get_{item.soundName}'])
|
play_sound(self.sounds[f'get_{item.soundName}'])
|
||||||
item.apply_effect(self.player)
|
item.apply_effect(self.player)
|
||||||
|
self.levelScore += 1000 # All items collected points awarded
|
||||||
item.isActive = False
|
item.isActive = False
|
||||||
self.bouncing_items.remove(item)
|
self.bouncing_items.remove(item)
|
||||||
|
|
||||||
@@ -324,6 +326,7 @@ class Level:
|
|||||||
self.player.stats.update_stat('Items collected', 1)
|
self.player.stats.update_stat('Items collected', 1)
|
||||||
if obj.soundName == "coin":
|
if obj.soundName == "coin":
|
||||||
self.player._coins += 1
|
self.player._coins += 1
|
||||||
|
self.levelScore += 100
|
||||||
self.player.stats.update_stat('Bone dust', 1)
|
self.player.stats.update_stat('Bone dust', 1)
|
||||||
if self.player._coins % 5 == 0:
|
if self.player._coins % 5 == 0:
|
||||||
# Only heal if below max health
|
# Only heal if below max health
|
||||||
@@ -337,6 +340,7 @@ class Level:
|
|||||||
# Extra life
|
# Extra life
|
||||||
self.player._coins = 0
|
self.player._coins = 0
|
||||||
self.player._lives += 1
|
self.player._lives += 1
|
||||||
|
self.levelScore += 1000
|
||||||
play_sound(self.sounds['get_extra_life'])
|
play_sound(self.sounds['get_extra_life'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -409,6 +413,9 @@ class Level:
|
|||||||
# Level complete
|
# Level complete
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
play_sound(self.sounds['end_of_level'])
|
play_sound(self.sounds['end_of_level'])
|
||||||
|
self.levelScore += 10000
|
||||||
|
# Actually update the scoreboard with level completion
|
||||||
|
self.player.scoreboard.increase_score(self.levelScore)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ class Player:
|
|||||||
attackDuration=200 # 200ms attack duration
|
attackDuration=200 # 200ms attack duration
|
||||||
))
|
))
|
||||||
|
|
||||||
|
self.scoreboard = Scoreboard()
|
||||||
|
|
||||||
def should_play_footstep(self, currentTime):
|
def should_play_footstep(self, currentTime):
|
||||||
"""Check if it's time to play a footstep sound"""
|
"""Check if it's time to play a footstep sound"""
|
||||||
return (self.distanceSinceLastStep >= self.get_step_distance() and
|
return (self.distanceSinceLastStep >= self.get_step_distance() and
|
||||||
|
|||||||
@@ -108,5 +108,8 @@ class PowerUp(Object):
|
|||||||
nunchucksWeapon = Weapon.create_nunchucks()
|
nunchucksWeapon = Weapon.create_nunchucks()
|
||||||
player.add_weapon(nunchucksWeapon)
|
player.add_weapon(nunchucksWeapon)
|
||||||
player.equip_weapon(nunchucksWeapon)
|
player.equip_weapon(nunchucksWeapon)
|
||||||
|
basePoints = nunchucksWeapon.damage * 1000
|
||||||
|
rangeModifier = nunchucksWeapon.range * 500
|
||||||
|
player.scoreboard.increase_score(basePoints + rangeModifier)
|
||||||
play_sound(self.sounds['get_nunchucks'])
|
play_sound(self.sounds['get_nunchucks'])
|
||||||
player.stats.update_stat('Items collected', 1)
|
player.stats.update_stat('Items collected', 1)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class WickedQuest:
|
|||||||
if keys[pygame.K_h]:
|
if keys[pygame.K_h]:
|
||||||
speak(f"{player.get_health()} health of {player.get_max_health()}")
|
speak(f"{player.get_health()} health of {player.get_max_health()}")
|
||||||
if keys[pygame.K_i]:
|
if keys[pygame.K_i]:
|
||||||
speak(f"Level {self.currentLevel.levelId}, {self.currentLevel.levelName}. {player.get_health()} health of {player.get_max_health()}. {player.get_lives()} lives remaining.")
|
speak(f"Level {self.currentLevel.levelId}, {self.currentLevel.levelName}. {player.get_health()} health of {player.get_max_health()}. {self.currentLevel.levelScore} points on this level so far. {player.get_lives()} lives remaining.")
|
||||||
if keys[pygame.K_l]:
|
if keys[pygame.K_l]:
|
||||||
speak(f"{player.get_lives()} lives")
|
speak(f"{player.get_lives()} lives")
|
||||||
if keys[pygame.K_j]: # Check jack o'lanterns
|
if keys[pygame.K_j]: # Check jack o'lanterns
|
||||||
@@ -150,6 +150,8 @@ class WickedQuest:
|
|||||||
if key != 'Total time': # Skip time since we already displayed it
|
if key != 'Total time': # Skip time since we already displayed it
|
||||||
report.append(f"{key}: {self.currentLevel.player.stats.get_level_stat(key)}")
|
report.append(f"{key}: {self.currentLevel.player.stats.get_level_stat(key)}")
|
||||||
|
|
||||||
|
report.append(f"Score: {self.currentLevel.levelScore}")
|
||||||
|
|
||||||
# Stop all sounds and music then play fanfare
|
# Stop all sounds and music then play fanfare
|
||||||
try:
|
try:
|
||||||
speak(f"Level {self.currentLevel.levelId}, {self.currentLevel.levelName}, complete!")
|
speak(f"Level {self.currentLevel.levelId}, {self.currentLevel.levelName}, complete!")
|
||||||
@@ -174,6 +176,11 @@ class WickedQuest:
|
|||||||
if key not in ['Total time', 'levelsCompleted']: # Skip these
|
if key not in ['Total time', 'levelsCompleted']: # Skip these
|
||||||
report.append(f"Total {key}: {self.currentLevel.player.stats.get_total_stat(key)}")
|
report.append(f"Total {key}: {self.currentLevel.player.stats.get_total_stat(key)}")
|
||||||
|
|
||||||
|
report.append(f"Final Score: {self.player.scoreboard.get_score()}")
|
||||||
|
|
||||||
|
if self.player.scoreboard.check_high_score():
|
||||||
|
self.player.scoreboard.add_high_score()
|
||||||
|
|
||||||
cut_scene(self.sounds, "game_over")
|
cut_scene(self.sounds, "game_over")
|
||||||
display_text(report)
|
display_text(report)
|
||||||
|
|
||||||
@@ -269,8 +276,8 @@ class WickedQuest:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
choice = game_menu(self.sounds, "play", "instructions", "learn_sounds",
|
choice = game_menu(self.sounds, "play", "high_scores", "instructions",
|
||||||
"credits", "donate", "exit")
|
"learn_sounds", "credits", "donate", "exit")
|
||||||
|
|
||||||
if choice == "exit":
|
if choice == "exit":
|
||||||
exit_game()
|
exit_game()
|
||||||
@@ -281,6 +288,16 @@ class WickedQuest:
|
|||||||
self.gameStartTime = pygame.time.get_ticks()
|
self.gameStartTime = pygame.time.get_ticks()
|
||||||
if self.load_level(1):
|
if self.load_level(1):
|
||||||
self.game_loop()
|
self.game_loop()
|
||||||
|
elif choice == "high_scores":
|
||||||
|
board = Scoreboard()
|
||||||
|
scores = board.get_high_scores()
|
||||||
|
lines = ["High Scores:"]
|
||||||
|
for i, entry in enumerate(scores, 1):
|
||||||
|
scoreStr = f"{i}. {entry['name']}: {entry['score']}"
|
||||||
|
lines.append(scoreStr)
|
||||||
|
|
||||||
|
pygame.event.clear()
|
||||||
|
display_text(lines)
|
||||||
elif choice == "learn_sounds":
|
elif choice == "learn_sounds":
|
||||||
choice = learn_sounds(self.sounds)
|
choice = learn_sounds(self.sounds)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user