diff --git a/assets/korobeiniki.wav b/assets/korobeiniki.wav new file mode 100644 index 0000000..01abed8 Binary files /dev/null and b/assets/korobeiniki.wav differ diff --git a/src/game/game.c b/src/game/game.c index 1a4e6a6..25d905a 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -8,8 +8,10 @@ #include #include "../main.h" +#include "../window/audio.h" #include "../window/colour8.h" #include "./tetromino/shapes.h" +#include "SDL_audio.h" #include "tetromino/placing.h" @@ -60,6 +62,11 @@ void game_init(GameData* const game_data) { game_data->curr_idx = -1; // set the current index to the max so it becomes zero after increasement next_shape(game_data); // select the next shape (shuffle should not be triggered) shuffle(TETROMINO_COUNT, game_data->nxt); // manually trigger a shuffle + + // initialize audio + game_data->audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096); + game_data->music = audio_load_wav(game_data->audio_device, "korobeiniki.wav"); + audio_play(game_data->audio_device, game_data->music); } // called every time the game's state is updated diff --git a/src/game/game.h b/src/game/game.h index 97cfa76..59fa1b3 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -2,6 +2,7 @@ #include +#include "../window/audio.h" #include "../window/colour8.h" #include "tetromino/shapes.h" @@ -14,6 +15,8 @@ typedef Colour8* Row; typedef struct { Row rows[ROWS]; + AudioDevice const* audio_device; + AudioData music; uint16_t score; ShapeId nxt[7]; // the order of the shape ids that they should appear in uint8_t curr_idx; // current shape index diff --git a/src/main.c b/src/main.c index 784e29e..b6d15c5 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,6 @@ #include "SDL_ttf.h" #include "errors.h" #include "game/game.h" -// #include "window/audio.h" #include "window/renderer.h" #ifdef __EMSCRIPTEN__ // for web builds @@ -39,10 +38,6 @@ static void init(void) { // initialize units game_init(&game_data); renderer_init(&render_data, &game_data); - - // initialize audio - // AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096); - // AudioData audio1 = audio_load_wav(audio_device, "FILE MANE"); } // handles game application updating