rotagon/music.c

46 lines
866 B
C
Raw Normal View History

2015-01-01 11:34:36 +00:00
/*
** music.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
2015-01-01 12:46:13 +00:00
#include "SDL_mixer.h"
2015-01-01 11:34:36 +00:00
#include "game.h"
#include "mus_beats.h"
2015-01-01 12:46:13 +00:00
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;
}
2015-01-01 11:34:36 +00:00
int
2015-01-01 12:46:13 +00:00
did_have_beat(struct s_game *g) {
2015-01-01 11:34:36 +00:00
struct timespec actual_time;
clock_gettime(CLOCK_REALTIME, &actual_time);
2015-01-01 12:46:13 +00:00
float secs_passed = actual_time.tv_sec - g->start_time.tv_sec +
(actual_time.tv_nsec - g->start_time.tv_nsec) / 1e9;
2015-01-01 11:34:36 +00:00
// printf("Secs passed: %lf, actual: %lf\n", secs_passed, mus_beats[already_done]);
2015-01-01 12:46:13 +00:00
if(mus_beats[g->beat_already_done] < secs_passed) {
g->beat_already_done++;
2015-01-01 11:34:36 +00:00
return 1;
}
return 0;
}