-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from X-R-G-B/ninho_sound
Ninho sound
- Loading branch information
Showing
11 changed files
with
180 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 X-R-G-B | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |