mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
add audio looping
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
#include "SDL_audio.h"
|
#include "SDL_audio.h"
|
||||||
#include "tetromino/placing.h"
|
#include "tetromino/placing.h"
|
||||||
|
|
||||||
|
|
||||||
// shuffle the array using a Fisher–Yates shuffle
|
// shuffle the array using a Fisher–Yates shuffle
|
||||||
static inline void shuffle(uint8_t const size, shape_id* const elmnts) {
|
static inline void shuffle(uint8_t const size, shape_id* const elmnts) {
|
||||||
for (uint8_t i = 0; i < (size - 1); i++) {
|
for (uint8_t i = 0; i < (size - 1); i++) {
|
||||||
@@ -66,7 +65,6 @@ void game_init(game_data* const dat) {
|
|||||||
// initialize audio
|
// initialize audio
|
||||||
dat->audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096);
|
dat->audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096);
|
||||||
dat->music = audio_wav_load(dat->audio_device, "korobeiniki.wav");
|
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
|
// 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])
|
if (keys[SDL_SCANCODE_ESCAPE])
|
||||||
stop();
|
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;
|
InputData move = MOVE_NONE;
|
||||||
if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) move |= MOVE_LEFT;
|
if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) move |= MOVE_LEFT;
|
||||||
if (keys[SDL_SCANCODE_RIGHT] || keys[SDL_SCANCODE_D]) move |= MOVE_RIGHT;
|
if (keys[SDL_SCANCODE_RIGHT] || keys[SDL_SCANCODE_D]) move |= MOVE_RIGHT;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "../window/audio.h"
|
#include "../window/audio.h"
|
||||||
#include "../window/colour8.h"
|
#include "../window/colour8.h"
|
||||||
@@ -17,6 +18,7 @@ typedef struct {
|
|||||||
row rows[ROWS];
|
row rows[ROWS];
|
||||||
audio_device* audio_device;
|
audio_device* audio_device;
|
||||||
audio_data music;
|
audio_data music;
|
||||||
|
time_t music_timer;
|
||||||
uint16_t score;
|
uint16_t score;
|
||||||
shape_id nxt[7]; // the order of the shape ids that they should appear in
|
shape_id 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
|
||||||
|
|||||||
Reference in New Issue
Block a user