Revision 229
kinda health bar
ent.c | ||
---|---|---|
5 | 5 |
#include "graph.h" |
6 | 6 |
#include "sprite.h" |
7 | 7 |
#include "utils.h" |
8 |
#include "rectangle.h" |
|
8 | 9 |
#include <math.h> |
9 | 10 |
|
10 | 11 |
static double scale = 1.0; |
... | ... | |
21 | 22 |
double x, y; //real position |
22 | 23 |
sprite_t *dude; |
23 | 24 |
sprite_t *weapon; |
25 |
int health, current_health; |
|
24 | 26 |
}; |
25 | 27 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){ |
26 | 28 |
gunner_t *ret = malloc(sizeof(gunner_t)); |
27 | 29 |
if(ret == NULL) return NULL; |
28 | 30 |
ret->x = 0.0; |
29 | 31 |
ret->y = 0.0; |
32 |
ret->health = 100; |
|
33 |
ret->current_health = ret->health*2/3; |
|
30 | 34 |
ret->dude = sprite_ctor(dude ); |
31 | 35 |
ret->weapon = sprite_ctor(weapon); |
32 | 36 |
if(ret->dude == NULL || ret->weapon == NULL){ |
... | ... | |
45 | 49 |
sprite_set_angle(p->dude , angle); |
46 | 50 |
sprite_set_angle(p->weapon, angle); |
47 | 51 |
} |
48 |
double (gunner_get_x) (const gunner_t *p){ return p->x; } |
|
49 |
double (gunner_get_y) (const gunner_t *p){ return p->y; } |
|
50 |
int16_t (gunner_get_x_screen)(const gunner_t *p){ return (p->x-x_origin)*scale; } |
|
51 |
int16_t (gunner_get_y_screen)(const gunner_t *p){ return (p->y-y_origin)*scale; } |
|
52 |
void (gunner_set_health) (gunner_t *p, int health) { p->health = health; } |
|
53 |
void (gunner_set_curr_health) (gunner_t *p, int health) { p->current_health = health; } |
|
54 |
double (gunner_get_x) (const gunner_t *p){ return p->x; } |
|
55 |
double (gunner_get_y) (const gunner_t *p){ return p->y; } |
|
56 |
int (gunner_get_health) (const gunner_t *p){ return p->health; } |
|
57 |
int (gunner_get_curr_health) (const gunner_t *p){ return p->current_health; } |
|
58 |
int16_t (gunner_get_x_screen) (const gunner_t *p){ return (p->x-x_origin)*scale; } |
|
59 |
int16_t (gunner_get_y_screen) (const gunner_t *p){ return (p->y-y_origin)*scale; } |
|
52 | 60 |
void (gunner_draw)(gunner_t *p){ |
53 | 61 |
const int16_t x_screen = gunner_get_x_screen(p); |
54 | 62 |
const int16_t y_screen = gunner_get_y_screen(p); |
... | ... | |
58 | 66 |
sprite_set_scale(p->weapon, scale); |
59 | 67 |
sprite_draw (p->weapon); |
60 | 68 |
sprite_draw (p->dude ); |
69 |
gunner_draw_health(p); |
|
61 | 70 |
} |
62 | 71 |
|
72 |
void (gunner_draw_health)(const gunner_t *p) { |
|
73 |
int16_t w = sprite_get_w(p->dude); |
|
74 |
int16_t h = sprite_get_h(p->dude); |
|
75 |
double x = gunner_get_x(p) - w/2; |
|
76 |
double y = gunner_get_y(p) - h/2 - 10; |
|
77 |
int curr_health = gunner_get_curr_health(p); |
|
78 |
int health = gunner_get_health(p); |
|
79 |
double perc = (double)curr_health/health; |
|
80 |
rectangle_t *green_bar = rectangle_ctor(x, y, (int16_t)(w*perc), 10); |
|
81 |
rectangle_set_fill_color(green_bar, 0x00FF00); |
|
82 |
rectangle_t *red_bar = rectangle_ctor(x+(int16_t)(w*perc), y, (int16_t)(w*(1-perc)), 10); |
|
83 |
rectangle_set_fill_color(red_bar, 0xFF0000); |
|
84 |
rectangle_draw(green_bar); |
|
85 |
rectangle_draw(red_bar); |
|
86 |
rectangle_dtor(green_bar); |
|
87 |
rectangle_dtor(red_bar); |
|
88 |
} |
|
89 |
|
|
63 | 90 |
struct bullet{ |
64 | 91 |
double x, y; //real position |
65 | 92 |
double vx, vy; |
Also available in: Unified diff