162 lines
4 KiB
C
162 lines
4 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"
|
|
|
|
|
|
//Rond avec une sortie
|
|
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);
|
|
}
|
|
|
|
//comme 3 opposing forces affilé mais en escalier - super dur x)
|
|
void
|
|
pattern_le_decafeine(struct s_game *g) {
|
|
int times, i;
|
|
int max_dist = get_max_obs_dist(g);
|
|
int cleared_face = rand() % g->polygon_type;
|
|
|
|
for(i = 0; i < 5; i++) {
|
|
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 + i*K_CLEARANCE/2);
|
|
add_obstacle(g, o);
|
|
}
|
|
cleared_face = (cleared_face+1)%g->polygon_type;
|
|
}
|
|
}
|
|
|
|
//cotés opposés
|
|
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);
|
|
}
|
|
|
|
|
|
//La spirale
|
|
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);
|
|
}
|
|
}
|
|
|
|
//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 = 7;
|
|
void (*patterns[])(struct s_game *g) = {pattern_copyleft,
|
|
pattern_schenille,
|
|
pattern_copy3left,
|
|
pattern_opposing_forces,
|
|
pattern_3opposing_forces,
|
|
pattern_le_decafeine,
|
|
pattern_zigzagone};
|
|
|
|
int choosen_pattern = rand() % n_patterns;
|
|
|
|
patterns[choosen_pattern](g);
|
|
}
|
|
|
|
|