From 4036e380eb61573cde7fec4e877ab0973a0a6882 Mon Sep 17 00:00:00 2001 From: Frank Villaro-Dixon Date: Thu, 1 Jan 2015 06:19:10 +0100 Subject: [PATCH] major rework for drawing --- game.c | 24 +++++++++++++++++++----- game.h | 6 ++++++ obs.c | 10 +++++++--- obs.h | 3 +-- polygons.c | 8 +++++--- polygons.h | 2 +- 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/game.c b/game.c index 6dded2d..8697fba 100644 --- a/game.c +++ b/game.c @@ -14,6 +14,14 @@ #include "SDL/SDL.h" +void +draw_background(struct s_game *g) { + int face; + for(face = 0; face < g->polygon_type; face++) { + } +} + + int get_face_from_cursor(struct s_game *g) { return g->cursor_angle * g->polygon_type / ANGLE_MAX; @@ -45,16 +53,22 @@ draw_cursor(struct s_game *g) { //{{{ void -draw_game(struct s_game *g) { +(*get_polygon_drawer(struct s_game *g)) +(struct s_game *, int faceno, int dist, int thick, int col) { //{{{ switch(g->polygon_type) { case SHAPE_HEXAGON: - draw_hexagon(g); - draw_obstacles(g, draw_hexagon_side); - break; + return draw_hexagon_side; + default: + return NULL; } +} //}}} +void +draw_game(struct s_game *g) { //{{{ + draw_polygon(g); + draw_obstacles(g); draw_cursor(g); -} +} //}}} void diff --git a/game.h b/game.h index 4cad165..57a7e39 100644 --- a/game.h +++ b/game.h @@ -11,6 +11,7 @@ #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 +#define SCREEN_DIAGONAL (sqrt(SCREEN_HEIGHT*SCREEN_HEIGHT + SCREEN_WIDTH*SCREEN_WIDTH)/2) #define POLYGON_SIZE 30 @@ -59,6 +60,11 @@ init_game(struct s_game *g); int get_face_from_cursor(struct s_game *g); +//ugly ! +void +(*get_polygon_drawer(struct s_game *g)) +(struct s_game *, int faceno, int dist, int thick, int col); + void draw_game(struct s_game *g); diff --git a/obs.c b/obs.c index 212b2aa..662effc 100644 --- a/obs.c +++ b/obs.c @@ -41,7 +41,7 @@ create_obstacle(int thick, int face, int speed) { //{{{ o.used = 1; o.thick = thick; o.face = face; - o.distance = sqrt(SCREEN_WIDTH*SCREEN_WIDTH + SCREEN_HEIGHT*SCREEN_HEIGHT)/2; + o.distance = SCREEN_DIAGONAL; o.speed = speed; return o; @@ -53,9 +53,13 @@ delete_obstacle(struct s_game *g, int obs) { //{{{ } //}}} void -draw_obstacles(struct s_game *g, - void(*drawer)(struct s_game *, int faceno, int dist, int thick, int col)) { //{{{ +draw_obstacles(struct s_game *g) { //{{{ + int i; + + void(*drawer)(struct s_game *, int faceno, int dist, int thick, int col); + drawer = get_polygon_drawer(g); + for(i = 0; i < g->num_obs; i++) { if(g->obs[i].used) { struct s_obstacle o = g->obs[i]; diff --git a/obs.h b/obs.h index 6214cdd..9f8febc 100644 --- a/obs.h +++ b/obs.h @@ -20,8 +20,7 @@ void delete_obstacle(struct s_game *g, int obs); void -draw_obstacles(struct s_game *g, - void(*drawer)(struct s_game *, int faceno, int dist, int thick, int col)); +draw_obstacles(struct s_game *g); void update_obstacles(struct s_game *g); diff --git a/polygons.c b/polygons.c index 46cdc4d..9b06a3f 100644 --- a/polygons.c +++ b/polygons.c @@ -37,12 +37,14 @@ draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col) { SDL_FillPolygon(g->screen, points, 4, col); }//}}} void -draw_hexagon(struct s_game *g) { //{{{ +draw_polygon(struct s_game *g) { //{{{ int faces; -#define DFT_COLOR 128 + void (*drawer)(struct s_game *, int faceno, int dist, int thick, int col); + drawer = get_polygon_drawer(g); + for(faces = 0; faces < SHAPE_HEXAGON; faces++) { - draw_hexagon_side(g, faces, POLYGON_SIZE, SHAPE_THICK-5, g->color); + drawer(g, faces, POLYGON_SIZE, SHAPE_THICK-5, g->color); } } //}}} diff --git a/polygons.h b/polygons.h index 3fabe38..812c3e2 100644 --- a/polygons.h +++ b/polygons.h @@ -8,7 +8,7 @@ #define POLYGONS_H void -draw_hexagon(struct s_game *g); +draw_polygon(struct s_game *g); void draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col);