removed audio

This commit is contained in:
Vasilis Valatsos 2023-11-22 01:08:09 +01:00
parent 60c09ff2c4
commit b6cfee3775
19 changed files with 50 additions and 114 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -8,17 +8,6 @@ from configs.system.window_config import TILESIZE
class MagicPlayer: class MagicPlayer:
def __init__(self, animation_player): def __init__(self, animation_player):
self.animation_player = 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): def heal(self, player, strength, cost, groups):
if player.stats.energy >= cost: if player.stats.energy >= cost:
@ -35,7 +24,6 @@ class MagicPlayer:
def flame(self, player, cost, groups): def flame(self, player, cost, groups):
if player.stats.energy >= cost: if player.stats.energy >= cost:
player.stats.energy -= cost player.stats.energy -= cost
self.sounds['flame'].play()
if player._input.status.split('_')[0] == 'right': if player._input.status.split('_')[0] == 'right':
direction = pygame.math.Vector2(1, 0) direction = pygame.math.Vector2(1, 0)

View file

@ -79,56 +79,52 @@ class InputHandler:
self.movement.move(speed, hitbox, obstacle_sprites, rect) self.movement.move(speed, hitbox, obstacle_sprites, rect)
if self.sprite_type == 'player': # Combat Input
# Combat Input if button == 4 and not self.attacking: # keys[pygame.K_e]
if button == 4 and not self.attacking: # keys[pygame.K_e] self.attacking = True
self.attacking = True self.attack_time = pygame.time.get_ticks()
self.attack_time = pygame.time.get_ticks() self.combat.create_attack_sprite(player)
self.combat.create_attack_sprite(player) self.action = 4
self.combat.weapon_attack_sound.play()
self.action = 4
# Magic Input # Magic Input
if button == 5: # keys[pygame.K_q]: if button == 5:
self.attacking = True self.attacking = True
self.attack_time = pygame.time.get_ticks() self.attack_time = pygame.time.get_ticks()
self.combat.magic = list(magic_data.keys())[ self.combat.magic = list(magic_data.keys())[
self.combat.magic_index] self.combat.magic_index]
strength = list(magic_data.values())[ strength = list(magic_data.values())[
self.combat.magic_index]['strength'] + player.stats.magic self.combat.magic_index]['strength'] + player.stats.magic
cost = list(magic_data.values())[ cost = list(magic_data.values())[
self.combat.magic_index]['cost'] self.combat.magic_index]['cost']
self.combat.create_magic_sprite( self.combat.create_magic_sprite(
player, self.combat.magic, strength, cost) player, self.combat.magic, strength, cost)
self.action = 5 self.action = 5
# Rotating Weapons # Rotating Weapons
# keys[pygame.K_LSHIFT] if button == 6 and self.can_rotate_weapon:
if button == 6 and self.can_rotate_weapon: self.can_rotate_weapon = False
self.can_rotate_weapon = False self.weapon_rotation_time = pygame.time.get_ticks()
self.weapon_rotation_time = pygame.time.get_ticks() if self.combat.weapon_index < len(list(weapon_data.keys())) - 1:
if self.combat.weapon_index < len(list(weapon_data.keys())) - 1: self.combat.weapon_index += 1
self.combat.weapon_index += 1 else:
else: self.combat.weapon_index = 0
self.combat.weapon_index = 0
self.combat.weapon = list(weapon_data.keys())[ self.combat.weapon = list(weapon_data.keys())[
self.combat.weapon_index] self.combat.weapon_index]
self.action = 6 self.action = 6
# Swap Spells # Swap Spells
# keys[pygame.K_LCTRL] : if button == 7 and self.can_swap_magic:
if button == 7 and self.can_swap_magic: self.can_swap_magic = False
self.can_swap_magic = False self.magic_swap_time = pygame.time.get_ticks()
self.magic_swap_time = pygame.time.get_ticks() if self.combat.magic_index < len(list(magic_data.keys())) - 1:
if self.combat.magic_index < len(list(magic_data.keys())) - 1: self.combat.magic_index += 1
self.combat.magic_index += 1 else:
else: self.combat.magic_index = 0
self.combat.magic_index = 0 self.action = 7
self.action = 7
def cooldowns(self, vulnerable): def cooldowns(self, vulnerable):
current_time = pygame.time.get_ticks() current_time = pygame.time.get_ticks()

View file

@ -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)

View file

@ -1,6 +1,3 @@
import os
import pygame
from effects.weapon_effects import Weapon from effects.weapon_effects import Weapon
from effects.magic_effects import MagicPlayer from effects.magic_effects import MagicPlayer
@ -30,15 +27,6 @@ class CombatHandler:
self.hurt_time = None self.hurt_time = None
self.invulnerability_duration = 300 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): def create_attack_sprite(self, player):
self.current_attack = Weapon( self.current_attack = Weapon(
player, [player.visible_sprites, player.attack_sprites]) player, [player.visible_sprites, player.attack_sprites])

View file

@ -6,8 +6,6 @@ from .components._input import InputHandler
from effects.particle_effects import AnimationPlayer from effects.particle_effects import AnimationPlayer
from .components.audio import AudioHandler
class Enemy(pygame.sprite.Sprite): class Enemy(pygame.sprite.Sprite):
@ -19,7 +17,6 @@ class Enemy(pygame.sprite.Sprite):
self.position = position self.position = position
# Setup Graphics # Setup Graphics
self.audio = AudioHandler(self.sprite_type, self.name)
self.animation_player = AnimationPlayer() self.animation_player = AnimationPlayer()
self.animation = AnimationHandler(self.sprite_type, self.name) self.animation = AnimationHandler(self.sprite_type, self.name)
self.animation.import_assets(position) self.animation.import_assets(position)
@ -58,12 +55,10 @@ class Enemy(pygame.sprite.Sprite):
self.add_exp(player) self.add_exp(player)
self.animation.trigger_death_particles( self.animation.trigger_death_particles(
self.animation_player, self.rect.center, self.name, self.visible_sprites) self.animation_player, self.rect.center, self.name, self.visible_sprites)
self.audio.death_sound.play()
self.kill() self.kill()
def get_damaged(self, player, attack_type): def get_damaged(self, player, attack_type):
if self._input.combat.vulnerable: if self._input.combat.vulnerable:
self.audio.hit_sound.play()
for _, direction, attacking_player in self.distance_direction_from_player: for _, direction, attacking_player in self.distance_direction_from_player:
if attacking_player == player: if attacking_player == player:
self._input.movement.direction = -direction self._input.movement.direction = -direction

View file

@ -107,14 +107,15 @@ class Player(pygame.sprite.Sprite):
self.action_features = [self._input.action] self.action_features = [self._input.action]
self.reward_features = [self.stats.exp, self.reward_features = [
np.exp(-(nearest_dist)), 1 - np.exp(-self.stats.exp),
np.exp(-(nearest_enemy.stats.health)), np.exp(-(nearest_dist)),
- np.exp(self.stats.health) np.exp(-(nearest_enemy.stats.health)),
] - np.exp(-self.stats.health)
]
self.state_features = [ 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[0]/3616,
self.rect.center[1]/3168, self.rect.center[1]/3168,
self._input.movement.direction.x, self._input.movement.direction.x,
@ -126,14 +127,14 @@ class Player(pygame.sprite.Sprite):
enemy_states = [] enemy_states = []
for distance, direction, enemy in sorted_distances[:5]: for distance, direction, enemy in sorted_distances[:5]:
# TODO: Find a way to not use magic numbers
enemy_states.extend([ enemy_states.extend([
distance/sorted_distances[-1][0], distance/sorted_distances[-1][0],
direction[0], direction[0],
direction[1], direction[1],
enemy.stats.health/enemy.stats.monster_info['health'], enemy.stats.health/enemy.stats.monster_info['health'],
enemy.stats.attack/enemy.stats.monster_info['attack'], 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) self.state_features.extend(enemy_states)

View file

@ -18,11 +18,6 @@ class Game:
self.level = Level() 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): def run(self):
for event in pygame.event.get(): for event in pygame.event.get():

View file

@ -6,7 +6,7 @@ environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
if __name__ == '__main__': if __name__ == '__main__':
n_episodes = 1 n_episodes = 3000
figure_file = 'plots/score.png' figure_file = 'plots/score.png'
score_history = [] score_history = []
@ -15,7 +15,7 @@ if __name__ == '__main__':
agent_list = [] agent_list = []
game_len = 1 game_len = 5000
game = Game() game = Game()

BIN
tmp/ppo/actor_torch_ppo Normal file

Binary file not shown.

BIN
tmp/ppo/critic_torch_ppo Normal file

Binary file not shown.