mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
add game music (very rudimentary and hacky)
This commit is contained in:
BIN
assets/korobeiniki.wav
Normal file
BIN
assets/korobeiniki.wav
Normal file
Binary file not shown.
@@ -8,8 +8,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
|
#include "../window/audio.h"
|
||||||
#include "../window/colour8.h"
|
#include "../window/colour8.h"
|
||||||
#include "./tetromino/shapes.h"
|
#include "./tetromino/shapes.h"
|
||||||
|
#include "SDL_audio.h"
|
||||||
#include "tetromino/placing.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
|
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)
|
next_shape(game_data); // select the next shape (shuffle should not be triggered)
|
||||||
shuffle(TETROMINO_COUNT, game_data->nxt); // manually trigger a shuffle
|
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
|
// called every time the game's state is updated
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "../window/audio.h"
|
||||||
#include "../window/colour8.h"
|
#include "../window/colour8.h"
|
||||||
#include "tetromino/shapes.h"
|
#include "tetromino/shapes.h"
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ typedef Colour8* Row;
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Row rows[ROWS];
|
Row rows[ROWS];
|
||||||
|
AudioDevice const* audio_device;
|
||||||
|
AudioData music;
|
||||||
uint16_t score;
|
uint16_t score;
|
||||||
ShapeId nxt[7]; // the order of the shape ids that they should appear in
|
ShapeId nxt[7]; // the order of the shape ids that they should appear in
|
||||||
uint8_t curr_idx; // current shape index
|
uint8_t curr_idx; // current shape index
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "game/game.h"
|
#include "game/game.h"
|
||||||
// #include "window/audio.h"
|
|
||||||
#include "window/renderer.h"
|
#include "window/renderer.h"
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__ // for web builds
|
#ifdef __EMSCRIPTEN__ // for web builds
|
||||||
@@ -39,10 +38,6 @@ static void init(void) {
|
|||||||
// initialize units
|
// initialize units
|
||||||
game_init(&game_data);
|
game_init(&game_data);
|
||||||
renderer_init(&render_data, &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
|
// handles game application updating
|
||||||
|
|||||||
Reference in New Issue
Block a user