Add ability to switch weapons with number keys.

This commit is contained in:
Storm Dragon
2025-09-07 12:11:52 -04:00
parent 2bc27c0e28
commit cf3f27d9b8
20 changed files with 73 additions and 0 deletions

View File

@@ -21,6 +21,8 @@ class WickedQuest:
self.gameStartTime = None
self.lastThrowTime = 0
self.throwDelay = 250
self.lastWeaponSwitchTime = 0
self.weaponSwitchDelay = 200
self.player = None
self.currentGame = None
self.runLock = False # Toggle behavior of the run keys
@@ -216,6 +218,19 @@ class WickedQuest:
if keys[pygame.K_e]:
speak(f"Wielding {self.currentLevel.player.currentWeapon.name.replace('_', ' ')}")
# Weapon switching (1=shovel, 2=broom, 3=nunchucks)
currentTime = pygame.time.get_ticks()
if currentTime - self.lastWeaponSwitchTime >= self.weaponSwitchDelay:
if keys[pygame.K_1]:
if player.switch_to_weapon(1):
self.lastWeaponSwitchTime = currentTime
elif keys[pygame.K_2]:
if player.switch_to_weapon(2):
self.lastWeaponSwitchTime = currentTime
elif keys[pygame.K_3]:
if player.switch_to_weapon(3):
self.lastWeaponSwitchTime = currentTime
# Handle attack with either CTRL key
if (keys[pygame.K_LCTRL] or keys[pygame.K_RCTRL]) and player.start_attack(currentTime):
play_sound(self.sounds[player.currentWeapon.attackSound])
@@ -612,3 +627,4 @@ if __name__ == "__main__":
game = WickedQuest()
game.run()