(#134) Wire up the sound medium to the game
parent
f803dd3877
commit
d033ab78d9
|
@ -90,6 +90,11 @@ int game_render(const game_t *game, SDL_Renderer *renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int game_sound(game_t *game)
|
||||
{
|
||||
return level_sound(game->level, game->sound_medium);
|
||||
}
|
||||
|
||||
int game_update(game_t *game, Uint32 delta_time)
|
||||
{
|
||||
assert(game);
|
||||
|
|
|
@ -11,6 +11,7 @@ game_t *create_game(const char *platforms_file_path,
|
|||
void destroy_game(game_t *game);
|
||||
|
||||
int game_render(const game_t *game, SDL_Renderer *renderer);
|
||||
int game_sound(game_t *game);
|
||||
int game_update(game_t *game, Uint32 delta_time);
|
||||
|
||||
int game_event(game_t *game, const SDL_Event *event);
|
||||
|
|
|
@ -146,3 +146,11 @@ void goals_hide(goals_t *goals,
|
|||
goals->player_hitbox = player_hitbox;
|
||||
|
||||
}
|
||||
|
||||
int goals_sound(goals_t *goals,
|
||||
sound_medium_t *sound_medium)
|
||||
{
|
||||
(void) goals;
|
||||
(void) sound_medium;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define GOALS_H_
|
||||
|
||||
#include "./camera.h"
|
||||
#include "./sound_medium.h"
|
||||
|
||||
typedef struct goals_t goals_t;
|
||||
typedef struct SDL_Renderer SDL_Renderer;
|
||||
|
@ -15,8 +16,10 @@ void destroy_goals(goals_t *goals);
|
|||
rect_t goals_hitbox(const goals_t *goals);
|
||||
|
||||
int goals_render(const goals_t *goals,
|
||||
SDL_Renderer *renderer,
|
||||
const camera_t *camera);
|
||||
SDL_Renderer *renderer,
|
||||
const camera_t *camera);
|
||||
int goals_sound(goals_t *goals,
|
||||
sound_medium_t *sound_medium);
|
||||
void goals_update(goals_t *goals,
|
||||
Uint32 delta_time);
|
||||
void goals_hide(goals_t *goals,
|
||||
|
|
13
src/level.c
13
src/level.c
|
@ -249,3 +249,16 @@ int level_reload_preserve_player(level_t *level, const char *file_name)
|
|||
|
||||
RETURN_LT(lt, 0);
|
||||
}
|
||||
|
||||
int level_sound(level_t *level, sound_medium_t *sound_medium)
|
||||
{
|
||||
if (goals_sound(level->goals, sound_medium) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (player_sound(level->player, sound_medium) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,11 +10,13 @@ typedef struct platforms_t platforms_t;
|
|||
typedef struct SDL_Renderer SDL_Renderer;
|
||||
typedef union SDL_Event SDL_Event;
|
||||
typedef struct camera_t camera_t;
|
||||
typedef struct sound_medium_t sound_medium_t;
|
||||
|
||||
level_t *create_level_from_file(const char *file_name);
|
||||
void destroy_level(level_t *level);
|
||||
|
||||
int level_render(const level_t *level, SDL_Renderer *renderer);
|
||||
int level_sound(level_t *level, sound_medium_t *sound_medium);
|
||||
int level_update(level_t *level, Uint32 delta_time);
|
||||
|
||||
int level_event(level_t *level, const SDL_Event *event);
|
||||
|
|
|
@ -159,6 +159,11 @@ int main(int argc, char *argv[])
|
|||
print_current_error_msg("Failed rendering the game");
|
||||
RETURN_LT(lt, -1);
|
||||
}
|
||||
|
||||
if (game_sound(game) < 0) {
|
||||
print_current_error_msg("Failed handling the sound");
|
||||
RETURN_LT(lt, -1);
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_LT(lt, 0);
|
||||
|
|
10
src/player.c
10
src/player.c
|
@ -237,3 +237,13 @@ void player_die_from_lava(player_t *player,
|
|||
player_die(player);
|
||||
}
|
||||
}
|
||||
|
||||
int player_sound(const player_t * player,
|
||||
sound_medium_t * sound_medium)
|
||||
{
|
||||
const rect_t hitbox = rigid_rect_hitbox(player->alive_body);
|
||||
|
||||
return sound_medium_listen_sounds(
|
||||
sound_medium,
|
||||
vec(hitbox.x, hitbox.y));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "./goals.h"
|
||||
#include "./lava.h"
|
||||
#include "./camera.h"
|
||||
#include "./sound_medium.h"
|
||||
|
||||
typedef struct player_t player_t;
|
||||
typedef struct platforms_t platforms_t;
|
||||
|
@ -16,6 +17,8 @@ void destroy_player(player_t * player);
|
|||
int player_render(const player_t * player,
|
||||
SDL_Renderer *renderer,
|
||||
const camera_t *camera);
|
||||
int player_sound(const player_t * player,
|
||||
sound_medium_t * sound_medium);
|
||||
void player_update(player_t * player,
|
||||
const platforms_t *platforms,
|
||||
Uint32 delta_time);
|
||||
|
|
Loading…
Reference in New Issue