patterns and things

This commit is contained in:
Frank Villaro-Dixon 2015-01-01 13:46:13 +01:00
parent 5759435515
commit a9fae6dff0
8 changed files with 80 additions and 28 deletions

3
game.c
View file

@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "game.h"
#include "polygons.h"
#include "obs.h"
@ -173,5 +174,7 @@ init_game(struct s_game *g) { //{{{
g->counter = 0;
clock_gettime(CLOCK_REALTIME, &g->start_time);
init_obs(g);
} //}}}

7
game.h
View file

@ -45,7 +45,7 @@
struct s_obstacle {
int used;
int thick;
int thick, original_thick;
int face;
int distance;
int speed;
@ -68,6 +68,11 @@ struct s_game {
#define NUM_OBS 100
struct s_obstacle obs[NUM_OBS];
int num_obs;
struct timespec start_time;
int beat_already_done;
};

3
main.c
View file

@ -22,6 +22,7 @@ main()
start:
init_game(&ga);
init_music(&ga);
init_SDL(&ga);
struct s_obstacle a = create_obstacle(SHAPE_THICK, 2, 1, -1);
@ -30,7 +31,7 @@ start:
while(1) {
SDL_FillRect(ga.screen, NULL, 0);
if(did_have_beat()) {
if(did_have_beat(&ga)) {
ga.sexual_pulsation = 60;
puts("Pulse");
}

30
music.c
View file

@ -8,31 +8,35 @@
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include "SDL_mixer.h"
#include "game.h"
#include "mus_beats.h"
int
did_have_beat(void) {
static struct timespec start_time;
static int inited = 0;
static int already_done = 0;
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);
if(!inited) {
inited = 1;
clock_gettime(CLOCK_REALTIME, &start_time);
}
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 - start_time.tv_sec +
(actual_time.tv_nsec - start_time.tv_nsec) / 1e9;
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[already_done] < secs_passed) {
already_done++;
if(mus_beats[g->beat_already_done] < secs_passed) {
g->beat_already_done++;
return 1;
}
return 0;

View file

@ -7,8 +7,11 @@
#ifndef MUSIC_H
#define MUSIC_H
void
init_music(struct s_game *g);
int
did_have_beat(void);
did_have_beat(struct s_game *g);
#endif /* ndef MUSIC_H */

5
obs.c
View file

@ -39,7 +39,8 @@ create_obstacle(int thick, int face, int speed, int dist) { //{{{
struct s_obstacle o;
o.used = 1;
o.thick = thick;
o.original_thick = thick;
o.thick = o.original_thick;
o.face = face;
if(dist != -1)
@ -79,7 +80,7 @@ update_obstacles(struct s_game *g) { //{{{
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
g->obs[i].distance -= DFT_OBS_SPEED*g->obs[i].speed;
g->obs[i].thick = 1 * g->sexual_pulsation + SHAPE_THICK;
g->obs[i].thick = 1 * g->sexual_pulsation + g->obs[i].original_thick;
if(g->obs[i].distance <= 0)
g->obs[i].used = 0;

View file

@ -10,6 +10,7 @@
#include "obs.h"
//Rond avec une sortie
void
pattern_copyleft_spec(struct s_game *g, int cleared_face) {
int times;
@ -36,6 +37,7 @@ pattern_copy3left(struct s_game *g) {
pattern_copyleft_spec(g, 0);
}
//comme 3 opposing forces affilé mais en escalier - super dur x)
void
pattern_le_decafeine(struct s_game *g) {
int times, i;
@ -54,6 +56,7 @@ pattern_le_decafeine(struct s_game *g) {
}
}
//cotés opposés
void
pattern_opposing_forces(struct s_game *g) {
int times;
@ -77,7 +80,7 @@ pattern_3opposing_forces(struct s_game *g) {
}
//La spirale
void
pattern_schenille(struct s_game *g) {
int times;
@ -101,16 +104,55 @@ pattern_schenille(struct s_game *g) {
}
}
//C imbriqués avec grande barre/gros coté
void
pattern_zigzagone(struct s_game *g) {
int max_dist = get_max_obs_dist(g);
int cleared_face = rand() % g->polygon_type;
int perim;
for(perim = 0; perim < g->polygon_type/2; perim++) {
int face = (cleared_face + perim)%g->polygon_type;
struct s_obstacle o;
o = create_obstacle(SHAPE_THICK,
(perim + cleared_face)%g->polygon_type,
1, max_dist + K_CLEARANCE);
add_obstacle(g, o);
o = create_obstacle(SHAPE_THICK,
(perim + cleared_face)%g->polygon_type,
1, max_dist + 3*K_CLEARANCE + 2*SHAPE_THICK);
add_obstacle(g, o);
face -= 3;
CLEVER_MODULO(face, g->polygon_type/2);
o = create_obstacle(SHAPE_THICK,
(perim + cleared_face)%g->polygon_type,
1, max_dist + 2*K_CLEARANCE + 1*SHAPE_THICK);
add_obstacle(g, o);
}
struct s_obstacle o;
o = create_obstacle((SHAPE_THICK+K_CLEARANCE)*3,
cleared_face,
1, max_dist + K_CLEARANCE);
add_obstacle(g, o);
}
void
add_pattern(struct s_game *g) {
int n_patterns = 6;
int n_patterns = 7;
void (*patterns[])(struct s_game *g) = {pattern_copyleft,
pattern_schenille,
pattern_copy3left,
pattern_opposing_forces,
pattern_3opposing_forces,
pattern_le_decafeine};
pattern_le_decafeine,
pattern_zigzagone};
int choosen_pattern = rand() % n_patterns;

7
sdl.c
View file

@ -7,7 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"
#include "SDL_mixer.h"
#include "game.h"
void
@ -21,10 +20,4 @@ init_SDL(struct s_game *g)
/* create window */
g->screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
Mix_OpenAudio(22050,AUDIO_S16SYS,2,640);
Mix_Music *mus;
mus = Mix_LoadMUS("./mus.mp3");
Mix_PlayMusic(mus,1);
}