patterns
This commit is contained in:
parent
94ad076fc8
commit
a3ec028aec
6 changed files with 113 additions and 23 deletions
59
game.c
59
game.c
|
@ -14,8 +14,51 @@
|
|||
#include "SDL/SDL.h"
|
||||
|
||||
|
||||
union color {
|
||||
struct {
|
||||
unsigned char col[4];
|
||||
} rgb;
|
||||
int col;
|
||||
};
|
||||
|
||||
int
|
||||
divide_color(int color, int divider) {
|
||||
union color col;
|
||||
|
||||
col.col = color;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
col.rgb.col[i] /= divider;
|
||||
}
|
||||
|
||||
return col.col;
|
||||
}
|
||||
|
||||
void
|
||||
draw_background(struct s_game *g) {
|
||||
change_game_color(struct s_game *g) {
|
||||
static int from_canal = 0;
|
||||
static int to_canal = 1;
|
||||
|
||||
union color col;
|
||||
|
||||
col.col = g->color;
|
||||
printf("%x - %d %d %d\n", col.col, col.rgb.col[0], col.rgb.col[1], col.rgb.col[2]);
|
||||
|
||||
|
||||
col.rgb.col[from_canal]--;
|
||||
col.rgb.col[to_canal]++;
|
||||
|
||||
if(col.rgb.col[from_canal] > 255) {
|
||||
from_canal = to_canal;
|
||||
to_canal = (to_canal + rand()%2)%3;
|
||||
}
|
||||
|
||||
g->color = col.col;
|
||||
puts("changed");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
draw_background(struct s_game *g) { //{{{
|
||||
int face;
|
||||
void (*drawer)(struct s_game *, int faceno, int dist, int thick, int col);
|
||||
|
||||
|
@ -23,10 +66,9 @@ draw_background(struct s_game *g) {
|
|||
|
||||
for(face = 0; face < g->polygon_type; face++) {
|
||||
drawer(g, face, POLYGON_SIZE, SCREEN_DIAGONAL,
|
||||
g->color * ((face%2)+1) / 4);
|
||||
divide_color(g->color, 2 + 2*(face%2)));
|
||||
}
|
||||
}
|
||||
|
||||
} //}}}
|
||||
|
||||
int
|
||||
get_face_from_cursor(struct s_game *g) {
|
||||
|
@ -46,7 +88,7 @@ get_circle_vertice(int angle, int dist) { //{{{
|
|||
} //}}}
|
||||
|
||||
SDL_Point
|
||||
to_screen_coords(struct s_game *g, SDL_Point p) {
|
||||
to_screen_coords(struct s_game *g, SDL_Point p) { //{{{
|
||||
SDL_Point q;
|
||||
|
||||
p.x -= SCREEN_WIDTH/2;
|
||||
|
@ -62,9 +104,8 @@ to_screen_coords(struct s_game *g, SDL_Point p) {
|
|||
q.x += SCREEN_WIDTH/2;
|
||||
q.y += SCREEN_HEIGHT/2;
|
||||
|
||||
|
||||
return q;
|
||||
}
|
||||
}//}}}
|
||||
|
||||
void
|
||||
draw_cursor(struct s_game *g) { //{{{
|
||||
|
@ -110,9 +151,9 @@ get_keys(struct s_game *g) { //{{{
|
|||
exit(0);
|
||||
|
||||
if(g->keys[SDLK_LEFT])
|
||||
g->cursor_angle -= TO_DEG(3);
|
||||
g->cursor_angle -= TO_DEG(CURSOR_DEG_FRAME);
|
||||
if(g->keys[SDLK_RIGHT])
|
||||
g->cursor_angle += TO_DEG(3);
|
||||
g->cursor_angle += TO_DEG(CURSOR_DEG_FRAME);
|
||||
|
||||
g->cursor_angle %= ANGLE_MAX;
|
||||
if(g->cursor_angle < 0)
|
||||
|
|
24
game.h
24
game.h
|
@ -12,20 +12,32 @@
|
|||
|
||||
#define SCREEN_WIDTH 1000
|
||||
#define SCREEN_HEIGHT 700
|
||||
#define SCREEN_DIAGONAL (sqrt(SCREEN_HEIGHT*SCREEN_HEIGHT + SCREEN_WIDTH*SCREEN_WIDTH))
|
||||
#define SCREEN_DIAGONAL (sqrt(SCREEN_HEIGHT*SCREEN_HEIGHT + SCREEN_WIDTH*SCREEN_WIDTH)/2)
|
||||
|
||||
#define CLEVER_MODULO(n, mod) do { while(n < 0) { n += mod; };;;; n %= mod; } while(0);
|
||||
|
||||
|
||||
#define DEC_COLOR 0x00020202
|
||||
#define DIVIDE_COLOR(color, times) (((color) & 0x00ff0000 / (times)) | ((color) & 0x0000ff00 / (times)) | ((color) & 0x000000ff / (times)))
|
||||
|
||||
////POLYGON
|
||||
#define POLYGON_SIZE 50
|
||||
|
||||
#define POLYGON_THICK 15
|
||||
//SHAPES
|
||||
#define SHAPE_SQUARE 4
|
||||
#define SHAPE_PENTAGON 5
|
||||
#define SHAPE_HEXAGON 6
|
||||
|
||||
#define SHAPE_THICK 15
|
||||
#define CURSOR_DIST (POLYGON_SIZE + SHAPE_THICK + 10)
|
||||
#define SHAPE_THICK 60
|
||||
#define DFT_OBS_SPEED (SHAPE_THICK / 15)
|
||||
|
||||
#define CURSOR_DIST (POLYGON_SIZE + POLYGON_THICK + 20)
|
||||
#define CURSOR_DEG_FRAME 4
|
||||
#define ANGLE_MAX 3600
|
||||
|
||||
#define OFFSET_POINT(p) {p.x += SCREEN_WIDTH/2; p.y += SCREEN_HEIGHT/2;}
|
||||
#define MAX(a, b) (a < b) ? (b) : (a)
|
||||
|
||||
#define TO_DEG(x) (x*ANGLE_MAX/360)
|
||||
#define TO_RAD(x) (x * 2 * M_PI / ANGLE_MAX)
|
||||
|
||||
|
@ -36,6 +48,7 @@ struct s_obstacle {
|
|||
int face;
|
||||
int distance;
|
||||
int speed;
|
||||
#define K_CLEARANCE (SHAPE_THICK * 5)
|
||||
};
|
||||
|
||||
struct s_game {
|
||||
|
@ -78,6 +91,9 @@ draw_game(struct s_game *g);
|
|||
void
|
||||
get_keys(struct s_game *g);
|
||||
|
||||
void
|
||||
change_game_color(struct s_game *g);
|
||||
|
||||
|
||||
#endif /* ndef GAME_H */
|
||||
|
||||
|
|
17
main.c
17
main.c
|
@ -11,6 +11,7 @@
|
|||
#include "game.h"
|
||||
#include "sdl.h"
|
||||
#include "obs.h"
|
||||
#include "patterns.h"
|
||||
|
||||
|
||||
int
|
||||
|
@ -22,16 +23,22 @@ start:
|
|||
init_game(&ga);
|
||||
init_SDL(&ga);
|
||||
|
||||
|
||||
struct s_obstacle a = create_obstacle(SHAPE_THICK, 2, 1);
|
||||
struct s_obstacle a = create_obstacle(SHAPE_THICK, 2, 1, -1);
|
||||
add_obstacle(&ga, a);
|
||||
|
||||
|
||||
while(1) {
|
||||
SDL_FillRect(ga.screen, NULL, 0);
|
||||
|
||||
/*
|
||||
if(!(ga.counter % 28)) {
|
||||
add_random_obstacle(&ga);
|
||||
}
|
||||
*/
|
||||
|
||||
if(get_max_obs_dist(&ga) < SCREEN_DIAGONAL)
|
||||
add_pattern(&ga);
|
||||
|
||||
update_obstacles(&ga);
|
||||
draw_game(&ga);
|
||||
SDL_Flip(ga.screen);
|
||||
|
@ -44,7 +51,7 @@ start:
|
|||
|
||||
get_keys(&ga);
|
||||
|
||||
SDL_Delay(5);
|
||||
SDL_Delay(3);
|
||||
|
||||
ga.counter++;
|
||||
|
||||
|
@ -52,6 +59,10 @@ start:
|
|||
|
||||
ga.sexual_pulsation = 0.3 * fabs(cos(ga.counter*M_PI/45)) + 1 +
|
||||
0.3 * fabs(sin(ga.counter*M_PI/90));
|
||||
|
||||
if(!(ga.counter % 10))
|
||||
change_game_color(&ga);
|
||||
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
29
obs.c
29
obs.c
|
@ -35,13 +35,18 @@ add_obstacle(struct s_game *g, struct s_obstacle o) { //{{{
|
|||
} //}}}
|
||||
|
||||
struct s_obstacle
|
||||
create_obstacle(int thick, int face, int speed) { //{{{
|
||||
create_obstacle(int thick, int face, int speed, int dist) { //{{{
|
||||
struct s_obstacle o;
|
||||
|
||||
o.used = 1;
|
||||
o.thick = thick;
|
||||
o.face = face;
|
||||
o.distance = SCREEN_DIAGONAL;
|
||||
|
||||
if(dist != -1)
|
||||
o.distance = dist;
|
||||
else
|
||||
o.distance = SCREEN_DIAGONAL;
|
||||
|
||||
o.speed = speed;
|
||||
|
||||
return o;
|
||||
|
@ -73,8 +78,8 @@ update_obstacles(struct s_game *g) { //{{{
|
|||
int i;
|
||||
for(i = 0; i < g->num_obs; i++) {
|
||||
if(g->obs[i].used) {
|
||||
g->obs[i].distance -= g->obs[i].speed;
|
||||
g->obs[i].thick = 3 * g->sexual_pulsation * SHAPE_THICK;
|
||||
g->obs[i].distance -= DFT_OBS_SPEED*g->obs[i].speed;
|
||||
g->obs[i].thick = 1 * g->sexual_pulsation + SHAPE_THICK;
|
||||
|
||||
if(g->obs[i].distance <= 0)
|
||||
g->obs[i].used = 0;
|
||||
|
@ -86,10 +91,24 @@ void
|
|||
add_random_obstacle(struct s_game *g) {
|
||||
struct s_obstacle o;
|
||||
|
||||
o = create_obstacle(SHAPE_THICK, rand()%g->polygon_type, 1);
|
||||
o = create_obstacle(SHAPE_THICK, rand()%g->polygon_type, 1, -1);
|
||||
add_obstacle(g, o);
|
||||
}
|
||||
|
||||
int
|
||||
get_max_obs_dist(struct s_game *g) {
|
||||
int i;
|
||||
int d_max = 0;
|
||||
for(i = 0; i < g->num_obs; i++) {
|
||||
if(g->obs[i].used) {
|
||||
d_max = MAX(d_max, g->obs[i].distance);
|
||||
}
|
||||
}
|
||||
|
||||
return d_max;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
check_collisions(struct s_game *g) {
|
||||
int i;
|
||||
|
|
5
obs.h
5
obs.h
|
@ -14,7 +14,7 @@ void
|
|||
add_obstacle(struct s_game *g, struct s_obstacle o);
|
||||
|
||||
struct s_obstacle
|
||||
create_obstacle(int thick, int face, int speed);
|
||||
create_obstacle(int thick, int face, int speed, int dist);
|
||||
|
||||
void
|
||||
delete_obstacle(struct s_game *g, int obs);
|
||||
|
@ -31,5 +31,8 @@ add_random_obstacle(struct s_game *g);
|
|||
int
|
||||
check_collisions(struct s_game *g);
|
||||
|
||||
int
|
||||
get_max_obs_dist(struct s_game *g);
|
||||
|
||||
#endif /* ndef OBS_H */
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ draw_polygon(struct s_game *g) { //{{{
|
|||
|
||||
|
||||
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
|
||||
drawer(g, faces, POLYGON_SIZE, SHAPE_THICK-5, g->color);
|
||||
drawer(g, faces, POLYGON_SIZE, POLYGON_THICK, g->color);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue