Skip to content

Commit

Permalink
Merge pull request #192 from X-R-G-B/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Saverio976 authored Jun 8, 2022
2 parents 9888270 + 82a3c84 commit 0bb6329
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 32 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ SRC_NPC_UPDATE := update_dialog_text.c \
update_dialogue_box.c \
update_npc.c \
update_elder.c \
event_skip_tp_magi.c
event_skip_tp_magi.c \
update_ninho.c
SRC_NPC_UPDATE := $(addprefix update/,$(SRC_NPC_UPDATE))

SRC_CHEST := dropping_infinity_86.c \
Expand All @@ -257,7 +258,8 @@ SRC_NPC := $(addprefix npc/,$(SRC_NPC))
# --------- SRC_AUDIO ----------------------------------------------------------
SRC_AUDIO := init_sound.c \
play_audio.c \
audio_static.c
audio_static.c \
init_music.c
SRC_AUDIO := $(addprefix audio/,$(SRC_AUDIO))
# ----------------------------------------------------------------------------
# ------ POP_TEXT_GENERATOR --------------------------------------------------
Expand Down
Binary file added assets/music/sound/ninho_sound.ogg
Binary file not shown.
3 changes: 3 additions & 0 deletions include/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern const char CONSUM_CAN_SOUND[];
extern const char INFINITY_86_SOUND[];
extern const char PARCHEMIN_SOUND[];
extern const char LEVEL_UP_SOUND[];
extern const char NINHO[];

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

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

int init_music_game(window_t *win, scene_t *scene);

#endif /* !SOUND_H_ */
3 changes: 3 additions & 0 deletions include/my_rpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,7 @@ void update_energy_text_hud(object_t *object, scene_t *scene,
int update_text_hud(object_t *obj, player_t *player,
const char stat_name[], float *stat_value);

void update_ninho(object_t *obj, scene_t *scene, window_t *win,
__attribute__((unused)) float dtime);

#endif /* !RPG_H_ */
1 change: 1 addition & 0 deletions src/audio/audio_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ const char CONSUM_CAN_SOUND[] = "usepotion";
const char INFINITY_86_SOUND[] = "86infsound";
const char PARCHEMIN_SOUND[] = "parcheminsound";
const char LEVEL_UP_SOUND[] = "level_up_sound";
const char NINHO[] = "salut_c_ninho";
52 changes: 52 additions & 0 deletions src/audio/init_music.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
** EPITECH PROJECT, 2022
** B-MUL-200-TLS-2-1-myrpg-xavier.mitault
** File description:
** init_music
*/

#include "my_rpg.h"
#include "my_bgs_components.h"
#include "audio.h"
#include "macro.h"

extern const int layer;

static const char music_in_game[] =
"./assets/music/game_music.ogg";
const char MUSIC_GAME[] = "musicgame";

static const char *keys_to_get[] = {
MUSIC_GAME, NULL
};

static const char *paths_to_data_sound[] = {
music_in_game, NULL
};

static int init_win_component_music(window_t *win, scene_t *scene,
const char *key_to_get, const char *path_to_data)
{
object_t *obj = NULL;

if (scene == NULL || win == NULL) {
return RET_ERR_INPUT;
}
obj = create_object(NULL, NULL, scene, layer);
if (object_set_audio(obj, path_to_data, false, false) != BGS_OK) {
return RET_ERR_MALLOC;
}
add_new_audio(obj, win);
window_add_component(win, obj, key_to_get, NULL);
return RET_OK;
}

int init_music_game(window_t *win, scene_t *scene)
{
for (int i = 0; keys_to_get[i] != NULL ||
paths_to_data_sound[i] != NULL; i++) {
init_win_component_music(win, scene, keys_to_get[i],
paths_to_data_sound[i]);
}
return RET_OK;
}
62 changes: 33 additions & 29 deletions src/audio/init_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,36 @@ static const char sound_open_parchemin[] =
"./assets/music/sound/paper.ogg";
static const char sound_level_up[] =
"./assets/music/sound/level_up_sound.ogg";
const char MUSIC_GAME[] = "musicgame";
static const char music_in_game[] =
"./assets/music/game_music.ogg";
static const int layer = 0;
static const char sound_ninho[] =
"./assets/music/sound/ninho_sound.ogg";

static int init_win_component_music(window_t *win, scene_t *scene,
const char *key_to_get, const char *path_to_data)
{
object_t *obj = NULL;
const int layer = 0;

if (scene == NULL || win == NULL) {
return RET_ERR_INPUT;
}
obj = create_object(NULL, NULL, scene, layer);
if (object_set_audio(obj, path_to_data, false, false) != BGS_OK) {
return RET_ERR_MALLOC;
}
add_new_audio(obj, win);
window_add_component(win, obj, key_to_get, NULL);
return RET_OK;
}
static const char *keys_to_get[] = {
HURTED_SOUND,
HURT_SOUNG,
OPEN_INV_SOUND,
CLOSE_INV_SOUND,
CONSUM_CAN_SOUND,
INFINITY_86_SOUND,
PARCHEMIN_SOUND,
LEVEL_UP_SOUND,
NINHO,
NULL
};

static const char *paths_to_data_sound[] = {
sound_hited_path,
sound_hit_path,
sound_open_fridge,
sound_close_fridge,
sound_consum_86,
sound_infinity_86,
sound_open_parchemin,
sound_level_up,
sound_ninho,
NULL
};

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

int init_sounds(scene_t *scene, window_t *win)
{

init_win_component_sound(win, scene, HURTED_SOUND, sound_hited_path);
init_win_component_sound(win, scene, HURT_SOUNG, sound_hit_path);
init_win_component_sound(win, scene, OPEN_INV_SOUND, sound_open_fridge);
init_win_component_sound(win, scene, CLOSE_INV_SOUND, sound_close_fridge);
init_win_component_sound(win, scene, CONSUM_CAN_SOUND, sound_consum_86);
init_win_component_sound(win, scene, INFINITY_86_SOUND, sound_infinity_86);
init_win_component_sound(win, scene, PARCHEMIN_SOUND, sound_open_parchemin);
init_win_component_sound(win, scene, LEVEL_UP_SOUND, sound_level_up);
init_win_component_music(win, scene, MUSIC_GAME, music_in_game);
for (int i = 0; keys_to_get[i] != NULL ||
paths_to_data_sound[i] != NULL; i++) {
init_win_component_sound(win, scene, keys_to_get[i],
paths_to_data_sound[i]);
}
return RET_OK;
}
2 changes: 1 addition & 1 deletion src/map/create_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void (*square_updates[])(object_t *, scene_t *, window_t *, float) = {
update_magician,
update_elder,
init_npc_spawner,
init_npc_spawner,
update_ninho,
update_spawner,
update_spawner,
update_spawner,
Expand Down
1 change: 1 addition & 0 deletions src/menu/main/init_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int init_menu(window_t *win)
return (RET_ERR_MALLOC);
}
init_sounds(scene, win);
init_music_game(win, scene);
init_making_of(scene);
add_escape_event(obj);
return RET_OK;
Expand Down
61 changes: 61 additions & 0 deletions src/npc/update/update_ninho.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
** EPITECH PROJECT, 2022
** FlashBackToTheFuture
** File description:
** update_ninho
*/

#include "npc.h"
#include "my_rpg.h"
#include "macro.h"
#include "stage.h"
#include "player.h"
#include "audio.h"

extern const char npc_path_key[];

static const sfKeyCode key_interract = sfKeyE;

static void check_next_stage_event(object_t *obj, window_t *win,
__attribute__((unused)) scene_t *scene)
{
player_t *player = dico_t_get_value(win->components, PLAYER);
sfFloatRect player_rect = {0};
sfFloatRect npc_rect = sfSprite_getGlobalBounds(obj->drawable.sprite);

if (player == NULL) {
return;
}
player_rect = sfSprite_getGlobalBounds(player->obj->drawable.sprite);
if (sfFloatRect_intersects(&player_rect, &npc_rect, NULL) == sfTrue &&
sfKeyboard_isKeyPressed(key_interract) == sfTrue) {
play_sound(win, NINHO);
}
}

static void ninho_npc_update(object_t *obj, scene_t *scene, window_t *win,
float dtime)
{
check_next_stage_event(obj, win, scene);
update_npc(obj, scene, win, dtime);
}

void update_ninho(object_t *obj, scene_t *scene, window_t *win,
__attribute__((unused)) float dtime)
{
char *npc_path = NULL;
object_t *npc = NULL;

if (obj == NULL || obj->components == NULL ||
scene == NULL || win == NULL) {
return;
}
npc_path = dico_t_get_value(obj->components, npc_path_key);
if (npc_path == NULL) {
return;
}
npc = add_npc(scene, npc_path, obj->bigdata.sprite_bigdata.pos,
&callback_npc);
npc->update = &ninho_npc_update;
obj->components = dico_t_rem(obj->components, npc_path_key);
}

0 comments on commit 0bb6329

Please sign in to comment.