Revision 220
gunner collisions
proj/include/ent.h | ||
---|---|---|
38 | 38 |
typedef struct map map_t; |
39 | 39 |
map_t* (map_ctor)(const char **background, const char **collide); |
40 | 40 |
void (map_dtor)(map_t *p); |
41 |
int (map_collides)(const map_t *p, double x, double y); |
|
41 |
int (map_collides_point)(const map_t *p, double x, double y); |
|
42 |
int (map_collides_gunner)(const map_t *p, gunner_t *gunner); |
|
43 |
int (map_collides_bullet)(const map_t *p, bullet_t *bullet); |
|
42 | 44 |
void (map_draw)(map_t *p); |
43 | 45 |
|
44 | 46 |
#endif //ENT_H_INCLUDED |
proj/src/ent.c | ||
---|---|---|
5 | 5 |
#include "graph.h" |
6 | 6 |
#include "sprite.h" |
7 | 7 |
|
8 |
#include <math.h> |
|
9 |
|
|
8 | 10 |
static double scale = 1.0; |
9 | 11 |
static int16_t x_origin = 0; |
10 | 12 |
static int16_t y_origin = 0; |
... | ... | |
133 | 135 |
} |
134 | 136 |
int16_t (map_get_x_screen)(const map_t *p){ return (-x_origin)*scale; } |
135 | 137 |
int16_t (map_get_y_screen)(const map_t *p){ return (-y_origin)*scale; } |
136 |
int (map_collides)(const map_t *p, double x, double y){ |
|
138 |
int (map_collides_point)(const map_t *p, double x, double y){
|
|
137 | 139 |
const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background); |
138 | 140 |
int16_t x_ = x, y_ = y; |
139 | 141 |
if(x_ < 0 || w <= x_ || y_ < 0 || h <= y_) return 0; |
140 | 142 |
uint32_t pos = x_ + y_*w; |
141 | 143 |
return p->collide[pos]; |
142 | 144 |
} |
145 |
|
|
146 |
int (map_collides_gunner)(const map_t *p, gunner_t *shooter) { |
|
147 |
double radius = sprite_get_w(shooter->dude)/2.0; |
|
148 |
double shooter_x = gunner_get_x(shooter); |
|
149 |
for (double x = shooter_x - radius; x < shooter_x + radius; x += 1) { |
|
150 |
double y1 = sqrt(1 - x*x); |
|
151 |
double y2 = -y1; |
|
152 |
if (map_collides_point(p, x, y1) || map_collides_point(p, x, y2)) return 1; |
|
153 |
} |
|
154 |
return 0; |
|
155 |
} |
|
156 |
|
|
157 |
int (map_collides_bullet)(const map_t *p, bullet_t *bullet) { |
|
158 |
return 0; |
|
159 |
} |
|
160 |
|
|
143 | 161 |
void (map_draw)(map_t *p){ |
144 | 162 |
const int16_t x_screen = map_get_x_screen(p); |
145 | 163 |
const int16_t y_screen = map_get_y_screen(p); |
proj/src/proj.c | ||
---|---|---|
155 | 155 |
if (no_interrupts % refresh_count_value == 0) { |
156 | 156 |
update_movement(shooter1); |
157 | 157 |
|
158 |
if(map_collides(map1, gunner_get_x(shooter1), gunner_get_y(shooter1))){
|
|
158 |
if(map_collides_gunner(map1, shooter1)){
|
|
159 | 159 |
printf("COLLIDING\n"); |
160 | 160 |
} |
161 | 161 |
|
... | ... | |
182 | 182 |
graph_draw(); |
183 | 183 |
} |
184 | 184 |
} |
185 |
if (i == 12) { |
|
186 |
if (counter_mouse_ih >= 3) { |
|
187 |
struct packet pp = mouse_parse_packet(packet_mouse_ih); |
|
188 |
update_mouse_position(&pp); |
|
189 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y()); |
|
190 |
counter_mouse_ih = 0; |
|
191 |
} |
|
192 |
} |
|
185 | 193 |
#endif |
186 | 194 |
} |
187 | 195 |
} |
188 |
#ifdef TELMO |
|
189 |
if (counter_mouse_ih >= 3) { |
|
190 |
struct packet pp = mouse_parse_packet(packet_mouse_ih); |
|
191 |
update_mouse_position(&pp); |
|
192 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y()); |
|
193 |
counter_mouse_ih = 0; |
|
194 |
} |
|
195 |
#endif |
|
196 | 196 |
|
197 | 197 |
break; |
198 | 198 |
default: |
Also available in: Unified diff