Skip to content

Commit b86967c

Browse files
committed
fix sound portal
1 parent fbe85b4 commit b86967c

6 files changed

Lines changed: 29 additions & 18 deletions

File tree

includes/sound.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/04 18:00:00 by yourname #+# #+# */
9-
/* Updated: 2025/03/09 13:14:18 by hluiz-ma ### ########.fr */
9+
/* Updated: 2025/03/24 19:03:19 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -33,7 +33,7 @@ typedef enum e_sound_type
3333
# define SOUND_FILE_GUN "./assets/sound/gun_shot.wav"
3434
# define SOUND_FILE_PORTAL "./assets/sound/portal_effect.wav"
3535
# define SOUND_FILE_FOOTSTEP "./assets/sound/footstep.wav"
36-
# define SOUND_FILE_AMBIENT "./assets/sound/ambient.wav"
36+
# define SOUND_FILE_AMBIENT "./assets/sound/ambient2.wav"
3737
# define SOUND_FILE_HURT "./assets/sound/hurt.wav"
3838
# define SOUND_FILE_ENEMY "./assets/sound/enemy.wav"
3939

srcs/engine/sound/sound.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/09 11:03:49 by hluiz-ma #+# #+# */
9-
/* Updated: 2025/03/09 16:23:05 by hluiz-ma ### ########.fr */
9+
/* Updated: 2025/03/24 19:10:40 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

srcs/engine/sound/sound_utils.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* ************************************************************************** */
22
/* */
33
/* ::: :::::::: */
4-
/* sound.c :+: :+: :+: */
4+
/* sound_utils.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: yourname <yourname@student.42.fr> +#+ +:+ +#+ */
6+
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/04 18:00:00 by yourname #+# #+# */
9-
/* Updated: 2025/03/04 18:00:00 by yourname ### ########.fr */
9+
/* Updated: 2025/03/24 19:10:21 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -18,6 +18,7 @@ void init_sound_empty(t_game *game)
1818
return ;
1919
game->sounds->door = 0;
2020
game->sounds->gun = 0;
21+
game->sounds->portal = 0;
2122
game->sounds->footstep = 0;
2223
game->sounds->ambient = 0;
2324
game->sounds->hurt = 0;
@@ -34,7 +35,7 @@ int init_sounds(t_game *game)
3435
ft_printf("Warning: Failed to load door sound\n");
3536
if (!load_sound(&game->sounds->gun, SOUND_FILE_GUN))
3637
ft_printf("Warning: Failed to load gun sound\n");
37-
if (!load_sound(&game->sounds->gun, SOUND_FILE_PORTAL))
38+
if (!load_sound(&game->sounds->portal, SOUND_FILE_PORTAL))
3839
ft_printf("Warning: Failed to load portal sound\n");
3940
if (!load_sound(&game->sounds->footstep, SOUND_FILE_FOOTSTEP))
4041
ft_printf("Warning: Failed to load footstep sound\n");

srcs/events/key_handle.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/30 21:20:50 by hluiz-ma #+# #+# */
9-
/* Updated: 2025/03/22 20:01:39 by hluiz-ma ### ########.fr */
9+
/* Updated: 2025/03/24 18:55:52 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -18,6 +18,8 @@ static int handle_key_weapons(int keycode, t_game *game)
1818
{
1919
if (game->active_weapon == 0)
2020
game->p1.is_firing = 1;
21+
if (game->sounds && game->sounds->is_initialized)
22+
play_sound(game->sounds->gun);
2123
return (1);
2224
}
2325
else if (keycode == KEY_Q)

srcs/events/key_handle2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/09 12:11:37 by marsoare #+# #+# */
9-
/* Updated: 2025/03/22 20:01:42 by hluiz-ma ### ########.fr */
9+
/* Updated: 2025/03/24 18:51:49 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

srcs/main.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/29 16:37:53 by marsoare #+# #+# */
9-
/* Updated: 2025/03/22 17:51:52 by hluiz-ma ### ########.fr */
9+
/* Updated: 2025/03/24 19:13:09 by hluiz-ma ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -24,17 +24,25 @@ int mouse_press(int button, int x, int y, t_game *game)
2424
(void)y;
2525
if (!game)
2626
return (0);
27-
if (button == MOUSE_LEFT)
27+
if (button == MOUSE_LEFT && game->active_weapon == 0)
2828
{
29-
if (game->active_weapon == 0)
30-
game->p1.is_firing = 1;
31-
else if (game->portal_system)
32-
handle_portal_gun_input(game, button);
29+
game->p1.is_firing = 1;
30+
if (game->sounds && game->sounds->is_initialized)
31+
play_sound(game->sounds->gun);
3332
}
34-
else if (button == MOUSE_RIGHT)
33+
else if (button == MOUSE_LEFT && game->active_weapon == 1
34+
&& game->portal_system)
3535
{
36-
if (game->portal_system && game->active_weapon == 1)
37-
handle_portal_gun_input(game, button);
36+
handle_portal_gun_input(game, button);
37+
if (game->sounds && game->sounds->is_initialized)
38+
play_sound(game->sounds->portal);
39+
}
40+
else if (button == MOUSE_RIGHT && game->portal_system
41+
&& game->active_weapon == 1)
42+
{
43+
handle_portal_gun_input(game, button);
44+
if (game->sounds && game->sounds->is_initialized)
45+
play_sound(game->sounds->portal);
3846
}
3947
return (0);
4048
}

0 commit comments

Comments
 (0)