rotagon/patterns.c
Frank Villaro-Dixon 113192f897 patterns
2015-01-01 12:46:48 +01:00

102 lines
2.2 KiB
C

/*
** 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_spec(struct s_game *g, int cleared_face) {
int times;
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_copyleft(struct s_game *g) {
pattern_copyleft_spec(g, rand() % g->polygon_type);
}
void
pattern_copy3left(struct s_game *g) {
pattern_copyleft_spec(g, 0);
pattern_copyleft_spec(g, g->polygon_type/2);
pattern_copyleft_spec(g, 0);
}
void
pattern_opposing_forces(struct s_game *g) {
int times;
int max_dist = get_max_obs_dist(g);
int cleared_face = rand() % g->polygon_type;
for(times = 0; times < g->polygon_type; times+=2) {
struct s_obstacle o;
o = create_obstacle(SHAPE_THICK,
(times + cleared_face)%g->polygon_type,
1, max_dist + K_CLEARANCE);
add_obstacle(g, o);
}
}
void
pattern_3opposing_forces(struct s_game *g) {
pattern_opposing_forces(g);
pattern_opposing_forces(g);
pattern_opposing_forces(g);
}
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 = 5;
void (*patterns[])(struct s_game *g) = {pattern_copyleft,
pattern_schenille,
pattern_copy3left,
pattern_opposing_forces,
pattern_3opposing_forces};
int choosen_pattern = rand() % n_patterns;
patterns[choosen_pattern](g);
}