Skip to content

Commit 0bb6329

Browse files
authored
Merge pull request #192 from X-R-G-B/dev
Dev
2 parents 9888270 + 82a3c84 commit 0bb6329

10 files changed

Lines changed: 159 additions & 32 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ SRC_NPC_UPDATE := update_dialog_text.c \
231231
update_dialogue_box.c \
232232
update_npc.c \
233233
update_elder.c \
234-
event_skip_tp_magi.c
234+
event_skip_tp_magi.c \
235+
update_ninho.c
235236
SRC_NPC_UPDATE := $(addprefix update/,$(SRC_NPC_UPDATE))
236237

237238
SRC_CHEST := dropping_infinity_86.c \
@@ -257,7 +258,8 @@ SRC_NPC := $(addprefix npc/,$(SRC_NPC))
257258
# --------- SRC_AUDIO ----------------------------------------------------------
258259
SRC_AUDIO := init_sound.c \
259260
play_audio.c \
260-
audio_static.c
261+
audio_static.c \
262+
init_music.c
261263
SRC_AUDIO := $(addprefix audio/,$(SRC_AUDIO))
262264
# ----------------------------------------------------------------------------
263265
# ------ POP_TEXT_GENERATOR --------------------------------------------------

assets/music/sound/ninho_sound.ogg

84.2 KB
Binary file not shown.

include/audio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern const char CONSUM_CAN_SOUND[];
1818
extern const char INFINITY_86_SOUND[];
1919
extern const char PARCHEMIN_SOUND[];
2020
extern const char LEVEL_UP_SOUND[];
21+
extern const char NINHO[];
2122

2223
extern const char AUDIO_LIST[];
2324
extern const char SOUND_LIST[];
@@ -65,4 +66,6 @@ void play_sound(window_t *win, const char *comp_key);
6566

6667
void play_music(window_t *win, const char *comp_key);
6768

69+
int init_music_game(window_t *win, scene_t *scene);
70+
6871
#endif /* !SOUND_H_ */

include/my_rpg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,7 @@ void update_energy_text_hud(object_t *object, scene_t *scene,
205205
int update_text_hud(object_t *obj, player_t *player,
206206
const char stat_name[], float *stat_value);
207207

208+
void update_ninho(object_t *obj, scene_t *scene, window_t *win,
209+
__attribute__((unused)) float dtime);
210+
208211
#endif /* !RPG_H_ */

src/audio/audio_static.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ const char CONSUM_CAN_SOUND[] = "usepotion";
2121
const char INFINITY_86_SOUND[] = "86infsound";
2222
const char PARCHEMIN_SOUND[] = "parcheminsound";
2323
const char LEVEL_UP_SOUND[] = "level_up_sound";
24+
const char NINHO[] = "salut_c_ninho";

src/audio/init_music.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
** EPITECH PROJECT, 2022
3+
** B-MUL-200-TLS-2-1-myrpg-xavier.mitault
4+
** File description:
5+
** init_music
6+
*/
7+
8+
#include "my_rpg.h"
9+
#include "my_bgs_components.h"
10+
#include "audio.h"
11+
#include "macro.h"
12+
13+
extern const int layer;
14+
15+
static const char music_in_game[] =
16+
"./assets/music/game_music.ogg";
17+
const char MUSIC_GAME[] = "musicgame";
18+
19+
static const char *keys_to_get[] = {
20+
MUSIC_GAME, NULL
21+
};
22+
23+
static const char *paths_to_data_sound[] = {
24+
music_in_game, NULL
25+
};
26+
27+
static int init_win_component_music(window_t *win, scene_t *scene,
28+
const char *key_to_get, const char *path_to_data)
29+
{
30+
object_t *obj = NULL;
31+
32+
if (scene == NULL || win == NULL) {
33+
return RET_ERR_INPUT;
34+
}
35+
obj = create_object(NULL, NULL, scene, layer);
36+
if (object_set_audio(obj, path_to_data, false, false) != BGS_OK) {
37+
return RET_ERR_MALLOC;
38+
}
39+
add_new_audio(obj, win);
40+
window_add_component(win, obj, key_to_get, NULL);
41+
return RET_OK;
42+
}
43+
44+
int init_music_game(window_t *win, scene_t *scene)
45+
{
46+
for (int i = 0; keys_to_get[i] != NULL ||
47+
paths_to_data_sound[i] != NULL; i++) {
48+
init_win_component_music(win, scene, keys_to_get[i],
49+
paths_to_data_sound[i]);
50+
}
51+
return RET_OK;
52+
}

src/audio/init_sound.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,36 @@ static const char sound_open_parchemin[] =
2222
"./assets/music/sound/paper.ogg";
2323
static const char sound_level_up[] =
2424
"./assets/music/sound/level_up_sound.ogg";
25-
const char MUSIC_GAME[] = "musicgame";
26-
static const char music_in_game[] =
27-
"./assets/music/game_music.ogg";
28-
static const int layer = 0;
25+
static const char sound_ninho[] =
26+
"./assets/music/sound/ninho_sound.ogg";
2927

30-
static int init_win_component_music(window_t *win, scene_t *scene,
31-
const char *key_to_get, const char *path_to_data)
32-
{
33-
object_t *obj = NULL;
28+
const int layer = 0;
3429

35-
if (scene == NULL || win == NULL) {
36-
return RET_ERR_INPUT;
37-
}
38-
obj = create_object(NULL, NULL, scene, layer);
39-
if (object_set_audio(obj, path_to_data, false, false) != BGS_OK) {
40-
return RET_ERR_MALLOC;
41-
}
42-
add_new_audio(obj, win);
43-
window_add_component(win, obj, key_to_get, NULL);
44-
return RET_OK;
45-
}
30+
static const char *keys_to_get[] = {
31+
HURTED_SOUND,
32+
HURT_SOUNG,
33+
OPEN_INV_SOUND,
34+
CLOSE_INV_SOUND,
35+
CONSUM_CAN_SOUND,
36+
INFINITY_86_SOUND,
37+
PARCHEMIN_SOUND,
38+
LEVEL_UP_SOUND,
39+
NINHO,
40+
NULL
41+
};
42+
43+
static const char *paths_to_data_sound[] = {
44+
sound_hited_path,
45+
sound_hit_path,
46+
sound_open_fridge,
47+
sound_close_fridge,
48+
sound_consum_86,
49+
sound_infinity_86,
50+
sound_open_parchemin,
51+
sound_level_up,
52+
sound_ninho,
53+
NULL
54+
};
4655

4756
static int init_win_component_sound(window_t *win, scene_t *scene,
4857
const char *key_to_get, const char *path_to_data)
@@ -63,15 +72,10 @@ static int init_win_component_sound(window_t *win, scene_t *scene,
6372

6473
int init_sounds(scene_t *scene, window_t *win)
6574
{
66-
67-
init_win_component_sound(win, scene, HURTED_SOUND, sound_hited_path);
68-
init_win_component_sound(win, scene, HURT_SOUNG, sound_hit_path);
69-
init_win_component_sound(win, scene, OPEN_INV_SOUND, sound_open_fridge);
70-
init_win_component_sound(win, scene, CLOSE_INV_SOUND, sound_close_fridge);
71-
init_win_component_sound(win, scene, CONSUM_CAN_SOUND, sound_consum_86);
72-
init_win_component_sound(win, scene, INFINITY_86_SOUND, sound_infinity_86);
73-
init_win_component_sound(win, scene, PARCHEMIN_SOUND, sound_open_parchemin);
74-
init_win_component_sound(win, scene, LEVEL_UP_SOUND, sound_level_up);
75-
init_win_component_music(win, scene, MUSIC_GAME, music_in_game);
75+
for (int i = 0; keys_to_get[i] != NULL ||
76+
paths_to_data_sound[i] != NULL; i++) {
77+
init_win_component_sound(win, scene, keys_to_get[i],
78+
paths_to_data_sound[i]);
79+
}
7680
return RET_OK;
7781
}

src/map/create_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void (*square_updates[])(object_t *, scene_t *, window_t *, float) = {
3030
update_magician,
3131
update_elder,
3232
init_npc_spawner,
33-
init_npc_spawner,
33+
update_ninho,
3434
update_spawner,
3535
update_spawner,
3636
update_spawner,

src/menu/main/init_menu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int init_menu(window_t *win)
8787
return (RET_ERR_MALLOC);
8888
}
8989
init_sounds(scene, win);
90+
init_music_game(win, scene);
9091
init_making_of(scene);
9192
add_escape_event(obj);
9293
return RET_OK;

src/npc/update/update_ninho.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
** EPITECH PROJECT, 2022
3+
** FlashBackToTheFuture
4+
** File description:
5+
** update_ninho
6+
*/
7+
8+
#include "npc.h"
9+
#include "my_rpg.h"
10+
#include "macro.h"
11+
#include "stage.h"
12+
#include "player.h"
13+
#include "audio.h"
14+
15+
extern const char npc_path_key[];
16+
17+
static const sfKeyCode key_interract = sfKeyE;
18+
19+
static void check_next_stage_event(object_t *obj, window_t *win,
20+
__attribute__((unused)) scene_t *scene)
21+
{
22+
player_t *player = dico_t_get_value(win->components, PLAYER);
23+
sfFloatRect player_rect = {0};
24+
sfFloatRect npc_rect = sfSprite_getGlobalBounds(obj->drawable.sprite);
25+
26+
if (player == NULL) {
27+
return;
28+
}
29+
player_rect = sfSprite_getGlobalBounds(player->obj->drawable.sprite);
30+
if (sfFloatRect_intersects(&player_rect, &npc_rect, NULL) == sfTrue &&
31+
sfKeyboard_isKeyPressed(key_interract) == sfTrue) {
32+
play_sound(win, NINHO);
33+
}
34+
}
35+
36+
static void ninho_npc_update(object_t *obj, scene_t *scene, window_t *win,
37+
float dtime)
38+
{
39+
check_next_stage_event(obj, win, scene);
40+
update_npc(obj, scene, win, dtime);
41+
}
42+
43+
void update_ninho(object_t *obj, scene_t *scene, window_t *win,
44+
__attribute__((unused)) float dtime)
45+
{
46+
char *npc_path = NULL;
47+
object_t *npc = NULL;
48+
49+
if (obj == NULL || obj->components == NULL ||
50+
scene == NULL || win == NULL) {
51+
return;
52+
}
53+
npc_path = dico_t_get_value(obj->components, npc_path_key);
54+
if (npc_path == NULL) {
55+
return;
56+
}
57+
npc = add_npc(scene, npc_path, obj->bigdata.sprite_bigdata.pos,
58+
&callback_npc);
59+
npc->update = &ninho_npc_update;
60+
obj->components = dico_t_rem(obj->components, npc_path_key);
61+
}

0 commit comments

Comments
 (0)