diff --git a/assets/audio/attack/claw.wav b/assets/audio/attack/claw.wav deleted file mode 100644 index 1a98889..0000000 Binary files a/assets/audio/attack/claw.wav and /dev/null differ diff --git a/assets/audio/attack/fireball.wav b/assets/audio/attack/fireball.wav deleted file mode 100644 index dc2c852..0000000 Binary files a/assets/audio/attack/fireball.wav and /dev/null differ diff --git a/assets/audio/attack/slash.wav b/assets/audio/attack/slash.wav deleted file mode 100644 index 942aeb0..0000000 Binary files a/assets/audio/attack/slash.wav and /dev/null differ diff --git a/assets/audio/death.wav b/assets/audio/death.wav deleted file mode 100644 index ef03ab1..0000000 Binary files a/assets/audio/death.wav and /dev/null differ diff --git a/assets/audio/flame.wav b/assets/audio/flame.wav deleted file mode 100644 index 97bb0e4..0000000 Binary files a/assets/audio/flame.wav and /dev/null differ diff --git a/assets/audio/heal.wav b/assets/audio/heal.wav deleted file mode 100644 index e94bab0..0000000 Binary files a/assets/audio/heal.wav and /dev/null differ diff --git a/assets/audio/hit.wav b/assets/audio/hit.wav deleted file mode 100644 index 435b317..0000000 Binary files a/assets/audio/hit.wav and /dev/null differ diff --git a/assets/audio/main.ogg b/assets/audio/main.ogg deleted file mode 100644 index da5d252..0000000 Binary files a/assets/audio/main.ogg and /dev/null differ diff --git a/assets/audio/sword.wav b/assets/audio/sword.wav deleted file mode 100644 index 2e962d0..0000000 Binary files a/assets/audio/sword.wav and /dev/null differ diff --git a/effects/magic_effects.py b/effects/magic_effects.py index fe19577..a35127e 100644 --- a/effects/magic_effects.py +++ b/effects/magic_effects.py @@ -8,17 +8,6 @@ from configs.system.window_config import TILESIZE class MagicPlayer: def __init__(self, animation_player): self.animation_player = animation_player - script_dir = os.path.dirname(os.path.abspath(__file__)) - asset_path = os.path.join( - script_dir, '..', 'assets') - - # Sound Setup - self.sounds = { - 'heal': pygame.mixer.Sound(f'{asset_path}/audio/heal.wav'), - 'flame': pygame.mixer.Sound(f'{asset_path}/audio/flame.wav') - } - - self.sounds['flame'].set_volume(0) def heal(self, player, strength, cost, groups): if player.stats.energy >= cost: @@ -35,7 +24,6 @@ class MagicPlayer: def flame(self, player, cost, groups): if player.stats.energy >= cost: player.stats.energy -= cost - self.sounds['flame'].play() if player._input.status.split('_')[0] == 'right': direction = pygame.math.Vector2(1, 0) diff --git a/entities/components/_input.py b/entities/components/_input.py index cf4b330..af8bd35 100644 --- a/entities/components/_input.py +++ b/entities/components/_input.py @@ -79,56 +79,52 @@ class InputHandler: self.movement.move(speed, hitbox, obstacle_sprites, rect) - if self.sprite_type == 'player': - # Combat Input - if button == 4 and not self.attacking: # keys[pygame.K_e] - self.attacking = True - self.attack_time = pygame.time.get_ticks() - self.combat.create_attack_sprite(player) - self.combat.weapon_attack_sound.play() - self.action = 4 + # Combat Input + if button == 4 and not self.attacking: # keys[pygame.K_e] + self.attacking = True + self.attack_time = pygame.time.get_ticks() + self.combat.create_attack_sprite(player) + self.action = 4 - # Magic Input - if button == 5: # keys[pygame.K_q]: - self.attacking = True - self.attack_time = pygame.time.get_ticks() + # Magic Input + if button == 5: + self.attacking = True + self.attack_time = pygame.time.get_ticks() - self.combat.magic = list(magic_data.keys())[ - self.combat.magic_index] + self.combat.magic = list(magic_data.keys())[ + self.combat.magic_index] - strength = list(magic_data.values())[ - self.combat.magic_index]['strength'] + player.stats.magic + strength = list(magic_data.values())[ + self.combat.magic_index]['strength'] + player.stats.magic - cost = list(magic_data.values())[ - self.combat.magic_index]['cost'] - self.combat.create_magic_sprite( - player, self.combat.magic, strength, cost) - self.action = 5 + cost = list(magic_data.values())[ + self.combat.magic_index]['cost'] + self.combat.create_magic_sprite( + player, self.combat.magic, strength, cost) + self.action = 5 - # Rotating Weapons - # keys[pygame.K_LSHIFT] - if button == 6 and self.can_rotate_weapon: - self.can_rotate_weapon = False - self.weapon_rotation_time = pygame.time.get_ticks() - if self.combat.weapon_index < len(list(weapon_data.keys())) - 1: - self.combat.weapon_index += 1 - else: - self.combat.weapon_index = 0 + # Rotating Weapons + if button == 6 and self.can_rotate_weapon: + self.can_rotate_weapon = False + self.weapon_rotation_time = pygame.time.get_ticks() + if self.combat.weapon_index < len(list(weapon_data.keys())) - 1: + self.combat.weapon_index += 1 + else: + self.combat.weapon_index = 0 - self.combat.weapon = list(weapon_data.keys())[ - self.combat.weapon_index] - self.action = 6 + self.combat.weapon = list(weapon_data.keys())[ + self.combat.weapon_index] + self.action = 6 - # Swap Spells - # keys[pygame.K_LCTRL] : - if button == 7 and self.can_swap_magic: - self.can_swap_magic = False - self.magic_swap_time = pygame.time.get_ticks() - if self.combat.magic_index < len(list(magic_data.keys())) - 1: - self.combat.magic_index += 1 - else: - self.combat.magic_index = 0 - self.action = 7 + # Swap Spells + if button == 7 and self.can_swap_magic: + self.can_swap_magic = False + self.magic_swap_time = pygame.time.get_ticks() + if self.combat.magic_index < len(list(magic_data.keys())) - 1: + self.combat.magic_index += 1 + else: + self.combat.magic_index = 0 + self.action = 7 def cooldowns(self, vulnerable): current_time = pygame.time.get_ticks() diff --git a/entities/components/audio.py b/entities/components/audio.py deleted file mode 100644 index 378ada7..0000000 --- a/entities/components/audio.py +++ /dev/null @@ -1,27 +0,0 @@ -import os -import pygame - -from configs.game.monster_config import monster_data - - -class AudioHandler: - - def __init__(self, sprite_type, monster_name=None): - script_dir = os.path.dirname(os.path.abspath(__file__)) - asset_path = os.path.join( - script_dir, '../..', 'assets', 'audio') - - if sprite_type == 'player': - pass - - elif sprite_type == 'enemy': - - # Sounds - self.attack_sound = pygame.mixer.Sound( - monster_data[monster_name]['attack_sound']) - self.death_sound = pygame.mixer.Sound( - f'{asset_path}/death.wav') - self.hit_sound = pygame.mixer.Sound(f'{asset_path}/hit.wav') - self.death_sound.set_volume(0) - self.hit_sound.set_volume(0) - self.attack_sound.set_volume(0) diff --git a/entities/components/combat.py b/entities/components/combat.py index 6a1bf73..b9fe028 100644 --- a/entities/components/combat.py +++ b/entities/components/combat.py @@ -1,6 +1,3 @@ -import os -import pygame - from effects.weapon_effects import Weapon from effects.magic_effects import MagicPlayer @@ -30,15 +27,6 @@ class CombatHandler: self.hurt_time = None self.invulnerability_duration = 300 - # Import Sounds - script_dir = os.path.dirname(os.path.abspath(__file__)) - asset_path = os.path.join( - script_dir, '../..', 'assets', 'audio') - - self.weapon_attack_sound = pygame.mixer.Sound( - f"{asset_path}/sword.wav") - self.weapon_attack_sound.set_volume(0) - def create_attack_sprite(self, player): self.current_attack = Weapon( player, [player.visible_sprites, player.attack_sprites]) diff --git a/entities/enemy.py b/entities/enemy.py index 7c96958..40be325 100644 --- a/entities/enemy.py +++ b/entities/enemy.py @@ -6,8 +6,6 @@ from .components._input import InputHandler from effects.particle_effects import AnimationPlayer -from .components.audio import AudioHandler - class Enemy(pygame.sprite.Sprite): @@ -19,7 +17,6 @@ class Enemy(pygame.sprite.Sprite): self.position = position # Setup Graphics - self.audio = AudioHandler(self.sprite_type, self.name) self.animation_player = AnimationPlayer() self.animation = AnimationHandler(self.sprite_type, self.name) self.animation.import_assets(position) @@ -58,12 +55,10 @@ class Enemy(pygame.sprite.Sprite): self.add_exp(player) self.animation.trigger_death_particles( self.animation_player, self.rect.center, self.name, self.visible_sprites) - self.audio.death_sound.play() self.kill() def get_damaged(self, player, attack_type): if self._input.combat.vulnerable: - self.audio.hit_sound.play() for _, direction, attacking_player in self.distance_direction_from_player: if attacking_player == player: self._input.movement.direction = -direction diff --git a/entities/player.py b/entities/player.py index 17a481a..77b1e94 100644 --- a/entities/player.py +++ b/entities/player.py @@ -107,14 +107,15 @@ class Player(pygame.sprite.Sprite): self.action_features = [self._input.action] - self.reward_features = [self.stats.exp, - np.exp(-(nearest_dist)), - np.exp(-(nearest_enemy.stats.health)), - - np.exp(self.stats.health) - ] + self.reward_features = [ + 1 - np.exp(-self.stats.exp), + np.exp(-(nearest_dist)), + np.exp(-(nearest_enemy.stats.health)), + - np.exp(-self.stats.health) + ] self.state_features = [ - # TODO: Find a way to normalize + # TODO: Find a way to not use magic numbers self.rect.center[0]/3616, self.rect.center[1]/3168, self._input.movement.direction.x, @@ -126,14 +127,14 @@ class Player(pygame.sprite.Sprite): enemy_states = [] for distance, direction, enemy in sorted_distances[:5]: - + # TODO: Find a way to not use magic numbers enemy_states.extend([ distance/sorted_distances[-1][0], direction[0], direction[1], enemy.stats.health/enemy.stats.monster_info['health'], enemy.stats.attack/enemy.stats.monster_info['attack'], - enemy.stats.exp/enemy.stats.monster_info['exp'], + enemy.stats.exp/250, ]) self.state_features.extend(enemy_states) diff --git a/game.py b/game.py index 6e84c7f..7e36b6e 100644 --- a/game.py +++ b/game.py @@ -18,11 +18,6 @@ class Game: self.level = Level() - # Sound - main_sound = pygame.mixer.Sound('assets/audio/main.ogg') - main_sound.set_volume(0) - main_sound.play(loops=-1) - def run(self): for event in pygame.event.get(): diff --git a/main.py b/main.py index 9218561..b02ffe3 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1' if __name__ == '__main__': - n_episodes = 1 + n_episodes = 3000 figure_file = 'plots/score.png' score_history = [] @@ -15,7 +15,7 @@ if __name__ == '__main__': agent_list = [] - game_len = 1 + game_len = 5000 game = Game() diff --git a/tmp/ppo/actor_torch_ppo b/tmp/ppo/actor_torch_ppo new file mode 100644 index 0000000..d709201 Binary files /dev/null and b/tmp/ppo/actor_torch_ppo differ diff --git a/tmp/ppo/critic_torch_ppo b/tmp/ppo/critic_torch_ppo new file mode 100644 index 0000000..831a5f7 Binary files /dev/null and b/tmp/ppo/critic_torch_ppo differ