add game music (very rudimentary and hacky)

This commit is contained in:
2025-02-06 21:41:02 +01:00
parent 67e34a0cb0
commit 94ff2d200a
4 changed files with 10 additions and 5 deletions

BIN
assets/korobeiniki.wav Normal file

Binary file not shown.

View File

@@ -8,8 +8,10 @@
#include <time.h>
#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

View File

@@ -2,6 +2,7 @@
#include <stdint.h>
#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

View File

@@ -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