rotagon/game.c
Frank Villaro-Dixon 7100267c41 oauaou
2015-01-01 04:04:34 +01:00

76 lines
1.3 KiB
C

/*
** game.c - The game
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "game.h"
#include "SDL_prims.h"
SDL_Point
get_hexagon_vertice(int faceno, int dist)
{
SDL_Point p1;
p1.x = dist * cos((M_PI/3)*faceno);
p1.y = dist * sin((M_PI/3)*faceno);
p1.x += SCREEN_WIDTH/2;
p1.y += SCREEN_HEIGHT/2;
return p1;
}
void
draw_hexagon_side(struct s_game *g, int faceno, int dist, 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+SHAPE_THICK);
p4 = get_hexagon_vertice(faceno, dist+SHAPE_THICK);
SDL_Point points[4] = {p1, p2, p3, p4} ;
SDL_FillPolygon(g->screen, points, 4, col);
}//}}}
void
draw_hexagon(struct s_game *g) {
int faces;
#define DFT_COLOR 128
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
draw_hexagon_side(g, faces, 30, DFT_COLOR);
}
}
void
init_game(struct s_game *g) {
g->polygon_type = SHAPE_HEXAGON;
g->cursor_angle = 0;
}
void
draw_game(struct s_game *g) {
switch(g->polygon_type) {
case SHAPE_HEXAGON:
draw_hexagon(g);
break;
}
/*
SDL_Point p1, p2, p3;
p1.x = 10; p1.y = 10;
p2.x = 10; p2.y = 20;
p3.x = 40; p3.y = 40;
SDL_Point points[3] = {p1, p2, p3} ;
SDL_FillPolygon(g->screen, points, 3, 0xffff0000);
*/
}