Revision 323
more stuff
ent.c | ||
---|---|---|
13 | 13 |
#define GREEN_HEALTH_COLOR 0x009900 |
14 | 14 |
|
15 | 15 |
static double scale = 1.0; |
16 |
static int16_t x_origin = 0;
|
|
17 |
static int16_t y_origin = 0;
|
|
16 |
static double x_origin = 0;
|
|
17 |
static double y_origin = 0;
|
|
18 | 18 |
|
19 | 19 |
void (ent_set_scale) (double n){ scale = n; } |
20 | 20 |
void (ent_set_origin)(double x, double y){ x_origin = x; y_origin = y; } |
... | ... | |
91 | 91 |
double (gunner_get_angle) (const gunner_t *p){ return sprite_get_angle(p->dude); } |
92 | 92 |
double (gunner_get_health) (const gunner_t *p){ return p->health; } |
93 | 93 |
double (gunner_get_curr_health) (const gunner_t *p){ return p->current_health; } |
94 |
int16_t (gunner_get_x_screen) (const gunner_t *p){ return (p->x-x_origin)*scale; }
|
|
95 |
int16_t (gunner_get_y_screen) (const gunner_t *p){ return (p->y-y_origin)*scale; }
|
|
94 |
int16_t (gunner_get_x_screen) (const gunner_t *p){ return (int16_t)((p->x-x_origin)*scale); }
|
|
95 |
int16_t (gunner_get_y_screen) (const gunner_t *p){ return (int16_t)((p->y-y_origin)*scale); }
|
|
96 | 96 |
uint16_t (gunner_get_type) (const gunner_t *p){ return p->type; } |
97 | 97 |
int (gunner_get_team) (const gunner_t *p){ return p->team; } |
98 | 98 |
void (gunner_draw)(gunner_t *p){ |
... | ... | |
107 | 107 |
gunner_draw_health(p); |
108 | 108 |
} |
109 | 109 |
void (gunner_draw_health)(const gunner_t *p) { |
110 |
int16_t w = sprite_get_w(p->dude); |
|
111 |
int16_t h = sprite_get_h(p->dude); |
|
112 |
double x = gunner_get_x_screen(p) - w/2;
|
|
113 |
double y = gunner_get_y_screen(p) - h/2 - 10;
|
|
110 |
const uint16_t w = sprite_get_w(p->dude);
|
|
111 |
const uint16_t h = sprite_get_h(p->dude);
|
|
112 |
int16_t x = gunner_get_x_screen(p) - w/2;
|
|
113 |
int16_t y = gunner_get_y_screen(p) - h/2 - 10;
|
|
114 | 114 |
double curr_health = gunner_get_curr_health(p); |
115 | 115 |
double health = gunner_get_health(p); |
116 | 116 |
double perc = curr_health/health; |
117 |
rectangle_set_pos(p->green_bar, x, y); rectangle_set_size(p->green_bar, (int16_t)(w*perc), 10); |
|
118 |
rectangle_set_pos(p->red_bar, x+(int16_t)(w*perc), y); rectangle_set_size(p->red_bar, (int16_t)(w*(1-perc)), 10);
|
|
117 |
rectangle_set_pos(p->green_bar, x, y); rectangle_set_size(p->green_bar, (uint16_t)(w*perc), 10);
|
|
118 |
rectangle_set_pos(p->red_bar, x+(int16_t)(w*perc), y); rectangle_set_size(p->red_bar, (uint16_t)(w*(1.0-perc)), 10);
|
|
119 | 119 |
char buf[20]; sprintf(buf, "%d/%d", (int)p->current_health, (int)p->health); |
120 | 120 |
text_set_string(p->txt, buf); |
121 | 121 |
text_set_pos(p->txt, x+w/2, y+10/2); |
... | ... | |
165 | 165 |
double (bullet_get_y) (const bullet_t *p){ return p->y; } |
166 | 166 |
double (bullet_get_vx) (const bullet_t *p){ return p->vx; } |
167 | 167 |
double (bullet_get_vy) (const bullet_t *p){ return p->vy; } |
168 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; }
|
|
169 |
int16_t (bullet_get_y_screen)(const bullet_t *p){ return (p->y-y_origin)*scale; }
|
|
168 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (int16_t)((p->x-x_origin)*scale); }
|
|
169 |
int16_t (bullet_get_y_screen)(const bullet_t *p){ return (int16_t)((p->y-y_origin)*scale); }
|
|
170 | 170 |
double (bullet_get_damage) (const bullet_t *p){ return p->damage; } |
171 | 171 |
void (bullet_set_damage) (bullet_t *p, double damage) { |
172 | 172 |
if (damage < 0) damage = 0; |
... | ... | |
262 | 262 |
ret->collide_gunner = malloc(W*H*sizeof(uint8_t)); |
263 | 263 |
if(ret->collide_gunner == NULL){ map_dtor(ret); return NULL; } |
264 | 264 |
for(size_t i = 0; i < W*H; ++i){ |
265 |
int16_t x = i%W, y = i/W;
|
|
265 |
uint16_t x = i%W, y = (uint16_t)(i/W);
|
|
266 | 266 |
ret->collide_gunner[i] = (map_collides_gunner_pos(ret, x, y, 36) ? 1 : 0); |
267 | 267 |
} |
268 | 268 |
|
... | ... | |
284 | 284 |
free(p->visited); |
285 | 285 |
free(p); |
286 | 286 |
} |
287 |
int16_t (map_get_x_screen)(const map_t *p){ return (-x_origin)*scale; }
|
|
288 |
int16_t (map_get_y_screen)(const map_t *p){ return (-y_origin)*scale; }
|
|
289 |
int16_t (map_get_width) (const map_t *p){ return sprite_get_w(p->background); } |
|
290 |
int16_t (map_get_height) (const map_t *p){ return sprite_get_h(p->background); } |
|
287 |
static int16_t (map_get_x_screen)(const map_t *p){ return (int16_t)((-x_origin)*scale); }
|
|
288 |
static int16_t (map_get_y_screen)(const map_t *p){ return (int16_t)((-y_origin)*scale); }
|
|
289 |
uint16_t (map_get_width) (const map_t *p){ return sprite_get_w(p->background); }
|
|
290 |
uint16_t (map_get_height) (const map_t *p){ return sprite_get_h(p->background); }
|
|
291 | 291 |
int (map_collides_point)(const map_t *p, double x, double y){ |
292 | 292 |
const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background); |
293 |
int16_t x_ = x, y_ = y;
|
|
293 |
int16_t x_ = (int16_t)x, y_ = (int16_t)y;
|
|
294 | 294 |
if(x_ < 0 || w <= x_ || y_ < 0 || h <= y_) return 0; |
295 |
uint32_t pos = x_ + y_*w; |
|
296 |
return p->collide[pos]; |
|
295 |
int32_t pos = x_ + y_*w; |
|
296 |
if(0 <= pos && pos < w*h) return p->collide[pos]; |
|
297 |
else return false; |
|
297 | 298 |
} |
298 | 299 |
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) { |
299 |
double radius = max(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0; |
|
300 |
double radius = dmax(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
|
|
300 | 301 |
return map_collides_gunner_pos(p, gunner_get_x(shooter), gunner_get_y(shooter), radius); |
301 | 302 |
} |
302 | 303 |
int (map_make_dijkstra)(map_t *p, double x_, double y_){ |
... | ... | |
347 | 348 |
} |
348 | 349 |
|
349 | 350 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bull){ |
350 |
double radius = max(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0; |
|
351 |
double radius = dmax(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
|
|
351 | 352 |
double bullet_x = bullet_get_x(bull); |
352 | 353 |
double bullet_y = bullet_get_y(bull); |
353 | 354 |
for (double x = -radius; x < radius; x += 1){ |
... | ... | |
361 | 362 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull){ |
362 | 363 |
if(bull->shooter == shooter) return false; |
363 | 364 |
|
364 |
double shooter_radius = max(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0; |
|
365 |
double shooter_radius = dmax(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
|
|
365 | 366 |
double shooter_x = gunner_get_x(shooter); |
366 | 367 |
double shooter_y = gunner_get_y(shooter); |
367 | 368 |
|
368 |
double bullet_radius = max(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0; |
|
369 |
double bullet_radius = dmax(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
|
|
369 | 370 |
double bullet_x = bullet_get_x(bull); |
370 | 371 |
double bullet_y = bullet_get_y(bull); |
371 | 372 |
|
... | ... | |
389 | 390 |
|
390 | 391 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) { |
391 | 392 |
if (shooter1 == shooter2) return false; |
392 |
double shooter1_radius = max(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0; |
|
393 |
double shooter2_radius = max(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0; |
|
393 |
double shooter1_radius = dmax(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0;
|
|
394 |
double shooter2_radius = dmax(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0;
|
|
394 | 395 |
double distance = distance_gunners(shooter1, shooter2); |
395 | 396 |
return distance <= shooter1_radius+shooter2_radius; |
396 | 397 |
} |
Also available in: Unified diff