mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
add audio looping
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include "SDL_audio.h"
|
||||
#include "tetromino/placing.h"
|
||||
|
||||
|
||||
// shuffle the array using a Fisher–Yates shuffle
|
||||
static inline void shuffle(uint8_t const size, shape_id* const elmnts) {
|
||||
for (uint8_t i = 0; i < (size - 1); i++) {
|
||||
@@ -66,7 +65,6 @@ void game_init(game_data* const dat) {
|
||||
// initialize audio
|
||||
dat->audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096);
|
||||
dat->music = audio_wav_load(dat->audio_device, "korobeiniki.wav");
|
||||
audio_play(dat->audio_device, &dat->music);
|
||||
}
|
||||
|
||||
// called every time the game's state is updated
|
||||
@@ -74,6 +72,12 @@ void game_update(game_data* const dat, uint8_t const* const keys) {
|
||||
if (keys[SDL_SCANCODE_ESCAPE])
|
||||
stop();
|
||||
|
||||
time_t ctime = time(NULL);
|
||||
if (ctime > dat->music_timer) {
|
||||
dat->music_timer = ctime + dat->music.sec;
|
||||
audio_play(dat->audio_device, &dat->music);
|
||||
}
|
||||
|
||||
InputData move = MOVE_NONE;
|
||||
if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) move |= MOVE_LEFT;
|
||||
if (keys[SDL_SCANCODE_RIGHT] || keys[SDL_SCANCODE_D]) move |= MOVE_RIGHT;
|
||||
|
||||
Reference in New Issue
Block a user