rotagon/obs.c
2015-01-01 06:19:10 +01:00

104 lines
1.7 KiB
C

/*
** obs.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
#include "col.h"
#include <math.h>
void
init_ob(struct s_obstacle *obs) { //{{{
obs->used = 0;
} //}}}
void
init_obs(struct s_game *g) { //{{{
int i;
for(i = 0; i < g->num_obs; i++) {
init_ob(&g->obs[i]);
}
} //}}}
void
add_obstacle(struct s_game *g, struct s_obstacle o) { //{{{
int i;
for(i = 0; i < g->num_obs; i++) {
if(!g->obs[i].used) {
g->obs[i] = o;
break;
}
}
} //}}}
struct s_obstacle
create_obstacle(int thick, int face, int speed) { //{{{
struct s_obstacle o;
o.used = 1;
o.thick = thick;
o.face = face;
o.distance = SCREEN_DIAGONAL;
o.speed = speed;
return o;
} //}}}
void
delete_obstacle(struct s_game *g, int obs) { //{{{
g->obs[obs].used = 0;
} //}}}
void
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);
}
}
} //}}}
void
update_obstacles(struct s_game *g) { //{{{
int i;
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
g->obs[i].distance -= g->obs[i].speed;
if(g->obs[i].distance <= POLYGON_SIZE)
g->obs[i].used = 0;
}
}
} //}}}
void
add_random_obstacle(struct s_game *g) {
struct s_obstacle o;
o = create_obstacle(SHAPE_THICK, rand()%g->polygon_type, 1);
add_obstacle(g, o);
}
int
check_collisions(struct s_game *g) {
int i;
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
if(has_collision(g, g->obs[i]))
return 1;
}
}
return 0;
}