From 461b4f94dd2223b8f3d7067ae4ffc11e8c0c8855 Mon Sep 17 00:00:00 2001 From: Frank Villaro-Dixon Date: Thu, 1 Jan 2015 11:40:44 +0100 Subject: [PATCH] patterns(bis) --- patterns.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ patterns.h | 14 ++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 patterns.c create mode 100644 patterns.h 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 */ +