89 lines
1.6 KiB
C
89 lines
1.6 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 "polygons.h"
|
|
#include "obs.h"
|
|
#include "SDL_prims.h"
|
|
#include "SDL/SDL.h"
|
|
|
|
|
|
int
|
|
get_face_from_cursor(struct s_game *g) {
|
|
return g->cursor_angle * g->polygon_type / ANGLE_MAX;
|
|
}
|
|
|
|
SDL_Point
|
|
get_circle_vertice(int angle, int dist) { //{{{
|
|
SDL_Point p;
|
|
|
|
p.x = cos((double)angle*2*M_PI/ANGLE_MAX) * dist;
|
|
p.y = sin((double)angle*2*M_PI/ANGLE_MAX) * dist;
|
|
|
|
OFFSET_POINT(p);
|
|
|
|
return p;
|
|
} //}}}
|
|
void
|
|
draw_cursor(struct s_game *g) { //{{{
|
|
SDL_Point p1, p2, p3;
|
|
|
|
p1 = get_circle_vertice(g->cursor_angle, CURSOR_DIST);
|
|
p2 = get_circle_vertice(g->cursor_angle-TO_DEG(8), CURSOR_DIST-10);
|
|
p3 = get_circle_vertice(g->cursor_angle+TO_DEG(8), CURSOR_DIST-10);
|
|
|
|
SDL_Point pts[3] = {p1, p2, p3};
|
|
|
|
SDL_FillPolygon(g->screen, pts, 3, g->color);
|
|
} //}}}
|
|
|
|
|
|
void
|
|
draw_game(struct s_game *g) {
|
|
switch(g->polygon_type) {
|
|
case SHAPE_HEXAGON:
|
|
draw_hexagon(g);
|
|
draw_obstacles(g, draw_hexagon_side);
|
|
break;
|
|
}
|
|
|
|
draw_cursor(g);
|
|
}
|
|
|
|
|
|
void
|
|
get_keys(struct s_game *g) { //{{{
|
|
SDL_PumpEvents();
|
|
if(g->keys[SDL_QUIT])
|
|
exit(0);
|
|
if(g->keys[SDLK_q])
|
|
exit(0);
|
|
|
|
if(g->keys[SDLK_LEFT])
|
|
g->cursor_angle -= TO_DEG(3);
|
|
if(g->keys[SDLK_RIGHT])
|
|
g->cursor_angle += TO_DEG(3);
|
|
|
|
g->cursor_angle %= ANGLE_MAX;
|
|
if(g->cursor_angle < 0)
|
|
g->cursor_angle += ANGLE_MAX;
|
|
} //}}}
|
|
void
|
|
init_game(struct s_game *g) { //{{{
|
|
g->polygon_type = SHAPE_HEXAGON;
|
|
g->cursor_angle = TO_DEG(90);
|
|
g->color = 128;
|
|
g->keys = SDL_GetKeyState(NULL);
|
|
|
|
g->num_obs = NUM_OBS;
|
|
|
|
g->counter = 0;
|
|
|
|
init_obs(g);
|
|
} //}}}
|