Revision 226
implemented double-linked list. implemented bullet collision with walls from gunner collision. implemented bullet position updating with certain speed
ent.c | ||
---|---|---|
4 | 4 |
|
5 | 5 |
#include "graph.h" |
6 | 6 |
#include "sprite.h" |
7 |
|
|
7 |
#include "utils.h" |
|
8 | 8 |
#include <math.h> |
9 | 9 |
|
10 | 10 |
static double scale = 1.0; |
... | ... | |
62 | 62 |
|
63 | 63 |
struct bullet{ |
64 | 64 |
double x, y; //real position |
65 |
double vx, vy; |
|
65 | 66 |
sprite_t *b; |
66 | 67 |
}; |
67 | 68 |
bullet_t* (bullet_ctor)(basic_sprite_t *b){ |
68 | 69 |
bullet_t *ret = malloc(sizeof(bullet_t)); |
69 | 70 |
if(ret == NULL) return NULL; |
70 |
ret->x = 0.0; |
|
71 |
ret->y = 0.0; |
|
71 |
ret-> x = 0.0; |
|
72 |
ret-> y = 0.0; |
|
73 |
ret->vx = 0.0; |
|
74 |
ret->vy = 0.0; |
|
72 | 75 |
ret->b = sprite_ctor(b); |
73 | 76 |
if(ret->b == NULL){ |
74 | 77 |
bullet_dtor(ret); |
... | ... | |
86 | 89 |
double (bullet_get_y) (const bullet_t *p){ return p->y; } |
87 | 90 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; } |
88 | 91 |
int16_t (bullet_get_y_screen)(const bullet_t *p){ return (p->y-y_origin)*scale; } |
92 |
void (bullet_update_movement)(bullet_t *p){ |
|
93 |
p->x += p->vx; |
|
94 |
p->y += p->vy; |
|
95 |
} |
|
89 | 96 |
void (bullet_draw)(bullet_t *p){ |
90 | 97 |
const int16_t x_screen = bullet_get_x_screen(p); |
91 | 98 |
const int16_t y_screen = bullet_get_y_screen(p); |
... | ... | |
143 | 150 |
return p->collide[pos]; |
144 | 151 |
} |
145 | 152 |
|
146 |
int (map_collides_gunner)(const map_t *p, gunner_t *shooter) { |
|
153 |
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) {
|
|
147 | 154 |
double radius = sprite_get_w(shooter->dude)/2.0; |
148 | 155 |
double shooter_x = gunner_get_x(shooter); |
149 | 156 |
double shooter_y = gunner_get_y(shooter); |
... | ... | |
155 | 162 |
return 0; |
156 | 163 |
} |
157 | 164 |
|
158 |
int (map_collides_bullet)(const map_t *p, bullet_t *bullet) { |
|
165 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bull){ |
|
166 |
double radius = max(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0; |
|
167 |
double bullet_x = bullet_get_x(bull); |
|
168 |
double bullet_y = bullet_get_y(bull); |
|
169 |
for (double x = -radius; x < radius; x += 1){ |
|
170 |
double y1 = sqrt(radius*radius - x*x); |
|
171 |
double y2 = -y1; |
|
172 |
if (map_collides_point(p, bullet_x + x, bullet_y + y1) || map_collides_point(p, bullet_x + x, bullet_y + y2)) return 1; |
|
173 |
} |
|
159 | 174 |
return 0; |
160 | 175 |
} |
161 | 176 |
|
Also available in: Unified diff