major rework for drawing

This commit is contained in:
Frank Villaro-Dixon 2015-01-01 06:19:10 +01:00
parent 76276c5275
commit 4036e380eb
6 changed files with 39 additions and 14 deletions

24
game.c
View file

@ -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

6
game.h
View file

@ -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);

10
obs.c
View file

@ -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];

3
obs.h
View file

@ -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);

View file

@ -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);
}
} //}}}

View file

@ -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);