patterns(bis)

This commit is contained in:
Frank Villaro-Dixon 2015-01-01 11:40:44 +01:00
parent a3ec028aec
commit 461b4f94dd
2 changed files with 78 additions and 0 deletions

64
patterns.c Normal file
View file

@ -0,0 +1,64 @@
/*
** patterns.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
#include "obs.h"
void
pattern_copyleft(struct s_game *g) {
int times;
int cleared_face = rand() % g->polygon_type;
int max_dist = get_max_obs_dist(g);
for(times = 0; times < g->polygon_type; times++) {
if(times != cleared_face) {
struct s_obstacle o;
o = create_obstacle(SHAPE_THICK, times, 1, max_dist + K_CLEARANCE);
add_obstacle(g, o);
}
}
}
void
pattern_schenille(struct s_game *g) {
int times;
int cleared_face = rand() % g->polygon_type;
int max_dist = get_max_obs_dist(g);
int dir = 1 - 2 * (rand()%2);
int leng = rand()%7 + 10;
for(times = 0; times < leng; times++) {
struct s_obstacle o;
o = create_obstacle(SHAPE_THICK,
cleared_face,
1,
max_dist + K_CLEARANCE + times*SHAPE_THICK);
add_obstacle(g, o);
cleared_face += dir;
CLEVER_MODULO(cleared_face, g->polygon_type);
}
}
void
add_pattern(struct s_game *g) {
int n_patterns = 2;
void (*patterns[])(struct s_game *g) = {pattern_copyleft,
pattern_schenille};
int choosen_pattern = rand() % n_patterns;
patterns[choosen_pattern](g);
}

14
patterns.h Normal file
View file

@ -0,0 +1,14 @@
/*
** patterns.h - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#ifndef PATTERNS_H
#define PATTERNS_H
void
add_pattern(struct s_game *g);
#endif /* ndef PATTERNS_H */