taken out useless code @ polygons.c
This commit is contained in:
parent
a9fae6dff0
commit
0742cfe6d2
5 changed files with 35 additions and 79 deletions
23
game.c
23
game.c
|
@ -58,13 +58,10 @@ change_game_color(struct s_game *g) {
|
|||
void
|
||||
draw_background(struct s_game *g) { //{{{
|
||||
int face;
|
||||
void (*drawer)(struct s_game *, int faceno, int dist, int thick, int col);
|
||||
|
||||
drawer = get_polygon_drawer(g);
|
||||
|
||||
for(face = 0; face < g->polygon_type; face++) {
|
||||
drawer(g, face, POLYGON_SIZE, SCREEN_DIAGONAL,
|
||||
divide_color(g->color, 2 + 2*(face%2)));
|
||||
draw_polygon_side(g, face, POLYGON_SIZE, SCREEN_DIAGONAL,
|
||||
divide_color(g->color, 2 + 2*(face%2)));
|
||||
}
|
||||
} //}}}
|
||||
|
||||
|
@ -120,22 +117,6 @@ draw_cursor(struct s_game *g) { //{{{
|
|||
SDL_FillPolygon(g->screen, pts, 3, g->color);
|
||||
} //}}}
|
||||
|
||||
|
||||
void
|
||||
(*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:
|
||||
return draw_hexagon_side;
|
||||
case SHAPE_SQUARE:
|
||||
return draw_square_side;
|
||||
case SHAPE_TRIANGLE:
|
||||
return draw_triangle_side;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
} //}}}
|
||||
|
||||
void
|
||||
draw_game(struct s_game *g) { //{{{
|
||||
draw_background(g);
|
||||
|
|
5
game.h
5
game.h
|
@ -83,11 +83,6 @@ 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);
|
||||
|
||||
SDL_Point
|
||||
to_screen_coords(struct s_game *g, SDL_Point p);
|
||||
|
||||
|
|
6
obs.c
6
obs.c
|
@ -8,6 +8,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "game.h"
|
||||
#include "col.h"
|
||||
#include "polygons.h"
|
||||
#include <math.h>
|
||||
|
||||
void
|
||||
|
@ -63,13 +64,10 @@ 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];
|
||||
drawer(g, o.face, o.distance, o.thick, g->color);
|
||||
draw_polygon_side(g, o.face, o.distance, o.thick, g->color);
|
||||
}
|
||||
}
|
||||
} //}}}
|
||||
|
|
72
polygons.c
72
polygons.c
|
@ -13,6 +13,9 @@
|
|||
#include "SDL_prims.h"
|
||||
#include "SDL/SDL.h"
|
||||
|
||||
|
||||
|
||||
|
||||
SDL_Point
|
||||
get_hexagon_vertice(int faceno, int dist) { //{{{
|
||||
SDL_Point p1;
|
||||
|
@ -24,22 +27,6 @@ get_hexagon_vertice(int faceno, int dist) { //{{{
|
|||
|
||||
return p1;
|
||||
} //}}}
|
||||
void
|
||||
draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
||||
SDL_Point p1, p2, p3, p4;
|
||||
|
||||
p1 = get_hexagon_vertice(faceno, dist);
|
||||
p2 = get_hexagon_vertice(faceno+1, dist);
|
||||
p3 = get_hexagon_vertice(faceno+1, dist+thick);
|
||||
p4 = get_hexagon_vertice(faceno, dist+thick);
|
||||
|
||||
SDL_Point points[4] = {to_screen_coords(g, p1),
|
||||
to_screen_coords(g, p2),
|
||||
to_screen_coords(g, p3),
|
||||
to_screen_coords(g, p4)} ;
|
||||
SDL_FillPolygon(g->screen, points, 4, col);
|
||||
}//}}}
|
||||
|
||||
SDL_Point
|
||||
get_square_vertice(int faceno, int dist) { //{{{
|
||||
SDL_Point p1;
|
||||
|
@ -51,22 +38,6 @@ get_square_vertice(int faceno, int dist) { //{{{
|
|||
|
||||
return p1;
|
||||
} //}}}
|
||||
void
|
||||
draw_square_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
||||
SDL_Point p1, p2, p3, p4;
|
||||
|
||||
p1 = get_square_vertice(faceno, dist);
|
||||
p2 = get_square_vertice(faceno+1, dist);
|
||||
p3 = get_square_vertice(faceno+1, dist+thick);
|
||||
p4 = get_square_vertice(faceno, dist+thick);
|
||||
|
||||
SDL_Point points[4] = {to_screen_coords(g, p1),
|
||||
to_screen_coords(g, p2),
|
||||
to_screen_coords(g, p3),
|
||||
to_screen_coords(g, p4)} ;
|
||||
SDL_FillPolygon(g->screen, points, 4, col);
|
||||
}//}}}
|
||||
|
||||
SDL_Point
|
||||
get_triangle_vertice(int faceno, int dist) { //{{{
|
||||
SDL_Point p1;
|
||||
|
@ -78,14 +49,34 @@ get_triangle_vertice(int faceno, int dist) { //{{{
|
|||
|
||||
return p1;
|
||||
} //}}}
|
||||
|
||||
void
|
||||
draw_triangle_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
||||
draw_polygon_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
||||
|
||||
SDL_Point (*get_poly_vertice)(int faceno, int dist);
|
||||
SDL_Point p1, p2, p3, p4;
|
||||
|
||||
p1 = get_triangle_vertice(faceno, dist);
|
||||
p2 = get_triangle_vertice(faceno+1, dist);
|
||||
p3 = get_triangle_vertice(faceno+1, dist+thick);
|
||||
p4 = get_triangle_vertice(faceno, dist+thick);
|
||||
/* Depending on the polygon */
|
||||
switch(g->polygon_type) {
|
||||
case SHAPE_HEXAGON:
|
||||
get_poly_vertice = get_hexagon_vertice;
|
||||
break;
|
||||
case SHAPE_SQUARE:
|
||||
get_poly_vertice = get_square_vertice;
|
||||
break;
|
||||
case SHAPE_TRIANGLE:
|
||||
get_poly_vertice = get_triangle_vertice;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown SHAPE @ %s", __FILE__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
p1 = get_poly_vertice(faceno, dist);
|
||||
p2 = get_poly_vertice(faceno+1, dist);
|
||||
p3 = get_poly_vertice(faceno+1, dist+thick);
|
||||
p4 = get_poly_vertice(faceno, dist+thick);
|
||||
|
||||
SDL_Point points[4] = {to_screen_coords(g, p1),
|
||||
to_screen_coords(g, p2),
|
||||
|
@ -98,16 +89,13 @@ void
|
|||
draw_polygon(struct s_game *g) { //{{{
|
||||
int faces;
|
||||
|
||||
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++) {
|
||||
drawer(g, faces, 0, POLYGON_SIZE, 0);
|
||||
draw_polygon_side(g, faces, 0, POLYGON_SIZE, 0);
|
||||
}
|
||||
|
||||
|
||||
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
|
||||
drawer(g, faces, POLYGON_SIZE, POLYGON_THICK, g->color);
|
||||
draw_polygon_side(g, faces, POLYGON_SIZE, POLYGON_THICK, g->color);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
|
|
|
@ -11,13 +11,7 @@ void
|
|||
draw_polygon(struct s_game *g);
|
||||
|
||||
void
|
||||
draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col);
|
||||
|
||||
void
|
||||
draw_square_side(struct s_game *g, int faceno, int dist, int thick, int col);
|
||||
|
||||
void
|
||||
draw_triangle_side(struct s_game *g, int faceno, int dist, int thick, int col);
|
||||
draw_polygon_side(struct s_game *g, int faceno, int dist, int thick, int col);
|
||||
|
||||
#endif /* ndef POLYGONS_H */
|
||||
|
||||
|
|
Loading…
Reference in a new issue