diff --git a/patterns.c b/patterns.c new file mode 100644 index 0000000..cebd574 --- /dev/null +++ b/patterns.c @@ -0,0 +1,64 @@ +/* +** patterns.c - <+DESC+> +** +** 2014 - Frank Villaro-Dixon +*/ + +#include +#include +#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); +} + + diff --git a/patterns.h b/patterns.h new file mode 100644 index 0000000..4067934 --- /dev/null +++ b/patterns.h @@ -0,0 +1,14 @@ +/* +** patterns.h - <+DESC+> +** +** 2014 - Frank Villaro-Dixon +*/ + +#ifndef PATTERNS_H +#define PATTERNS_H + +void +add_pattern(struct s_game *g); + +#endif /* ndef PATTERNS_H */ +