45 lines
866 B
C
45 lines
866 B
C
/*
|
|
** music.c - <+DESC+>
|
|
**
|
|
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/time.h>
|
|
#include <time.h>
|
|
#include "SDL_mixer.h"
|
|
#include "game.h"
|
|
#include "mus_beats.h"
|
|
|
|
void
|
|
init_music(struct s_game *g) {
|
|
Mix_OpenAudio(22050,AUDIO_S16SYS,2,640);
|
|
Mix_Music *mus;
|
|
mus = Mix_LoadMUS("./mus.mp3");
|
|
Mix_PlayMusic(mus,1);
|
|
|
|
g->beat_already_done = 0;
|
|
}
|
|
|
|
|
|
int
|
|
did_have_beat(struct s_game *g) {
|
|
|
|
struct timespec actual_time;
|
|
clock_gettime(CLOCK_REALTIME, &actual_time);
|
|
|
|
float secs_passed = actual_time.tv_sec - g->start_time.tv_sec +
|
|
(actual_time.tv_nsec - g->start_time.tv_nsec) / 1e9;
|
|
|
|
|
|
// printf("Secs passed: %lf, actual: %lf\n", secs_passed, mus_beats[already_done]);
|
|
|
|
if(mus_beats[g->beat_already_done] < secs_passed) {
|
|
g->beat_already_done++;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|