rotagon/obs.c

123 lines
2 KiB
C
Raw Normal View History

2015-01-01 04:32:07 +00:00
/*
** obs.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
2015-01-01 04:57:59 +00:00
#include "col.h"
2015-01-02 13:28:11 +00:00
#include "polygons.h"
2015-01-01 04:32:07 +00:00
#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
2015-01-01 10:40:34 +00:00
create_obstacle(int thick, int face, int speed, int dist) { //{{{
2015-01-01 04:32:07 +00:00
struct s_obstacle o;
o.used = 1;
2015-01-01 12:46:13 +00:00
o.original_thick = thick;
o.thick = o.original_thick;
2015-01-01 04:32:07 +00:00
o.face = face;
2015-01-01 10:40:34 +00:00
if(dist != -1)
o.distance = dist;
else
o.distance = SCREEN_DIAGONAL;
2015-01-01 04:32:07 +00:00
o.speed = speed;
return o;
} //}}}
void
delete_obstacle(struct s_game *g, int obs) { //{{{
g->obs[obs].used = 0;
} //}}}
void
2015-01-01 05:19:10 +00:00
draw_obstacles(struct s_game *g) { //{{{
2015-01-01 04:32:07 +00:00
int i;
2015-01-01 05:19:10 +00:00
2015-01-01 04:32:07 +00:00
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
struct s_obstacle o = g->obs[i];
2015-01-02 13:28:11 +00:00
draw_polygon_side(g, o.face, o.distance, o.thick, g->color);
2015-01-01 04:32:07 +00:00
}
}
} //}}}
void
update_obstacles(struct s_game *g) { //{{{
int i;
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
2015-01-01 10:40:34 +00:00
g->obs[i].distance -= DFT_OBS_SPEED*g->obs[i].speed;
2015-01-01 12:46:13 +00:00
g->obs[i].thick = 1 * g->sexual_pulsation + g->obs[i].original_thick;
2015-01-01 04:32:07 +00:00
2015-01-01 06:37:18 +00:00
if(g->obs[i].distance <= 0)
2015-01-01 04:32:07 +00:00
g->obs[i].used = 0;
}
}
} //}}}
void
add_random_obstacle(struct s_game *g) {
struct s_obstacle o;
2015-01-01 10:40:34 +00:00
o = create_obstacle(SHAPE_THICK, rand()%g->polygon_type, 1, -1);
2015-01-01 04:32:07 +00:00
add_obstacle(g, o);
}
2015-01-01 04:57:59 +00:00
2015-01-01 10:40:34 +00:00
int
get_max_obs_dist(struct s_game *g) {
int i;
int d_max = 0;
for(i = 0; i < g->num_obs; i++) {
if(g->obs[i].used) {
d_max = MAX(d_max, g->obs[i].distance);
}
}
return d_max;
}
2015-01-01 04:57:59 +00:00
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;
}