Revision 314
some changes in fonts and ent.c
ent.c | ||
---|---|---|
28 | 28 |
sprite_t *dude; |
29 | 29 |
sprite_t *weapon; |
30 | 30 |
double health, current_health; |
31 |
rectangle_t *green_bar, *red_bar; |
|
31 | 32 |
text_t *txt; |
32 | 33 |
gunner_type type; |
33 | 34 |
int team; |
... | ... | |
41 | 42 |
ret->y = 0.0; |
42 | 43 |
ret->health = 100; |
43 | 44 |
ret->current_health = ret->health; |
44 |
ret->txt = text_ctor(default_font, ""); |
|
45 |
ret->green_bar = rectangle_ctor(0,0,0,0); |
|
46 |
ret->red_bar = rectangle_ctor(0,0,0,0); |
|
47 |
ret->txt = text_ctor(font_get_default(), ""); |
|
45 | 48 |
ret->type = type; |
46 | 49 |
ret->team = team; |
47 | 50 |
ret->dude = sprite_ctor(dude ); |
48 | 51 |
ret->weapon = sprite_ctor(weapon); |
49 |
if(ret->dude == NULL || ret->weapon == NULL){
|
|
52 |
if(ret->txt == NULL || ret->dude == NULL || ret->weapon == NULL || ret->green_bar == NULL || ret->red_bar == NULL){
|
|
50 | 53 |
gunner_dtor(ret); |
51 | 54 |
return NULL; |
52 | 55 |
} |
56 |
rectangle_set_fill_color(ret->green_bar, GREEN_HEALTH_COLOR); |
|
57 |
rectangle_set_fill_color(ret->red_bar , GRAPH_RED ); |
|
53 | 58 |
text_set_size(ret->txt, 15); |
54 | 59 |
text_set_valign(ret->txt, text_valign_center); |
55 | 60 |
text_set_halign(ret->txt, text_halign_center); |
... | ... | |
60 | 65 |
if(p == NULL) return; |
61 | 66 |
sprite_dtor(p->dude); |
62 | 67 |
sprite_dtor(p->weapon); |
68 |
rectangle_dtor(p->green_bar); |
|
69 |
rectangle_dtor(p->red_bar); |
|
63 | 70 |
text_dtor(p->txt); |
64 | 71 |
free(p); |
65 | 72 |
} |
... | ... | |
99 | 106 |
sprite_draw (p->dude ); |
100 | 107 |
gunner_draw_health(p); |
101 | 108 |
} |
102 |
|
|
103 | 109 |
void (gunner_draw_health)(const gunner_t *p) { |
104 | 110 |
int16_t w = sprite_get_w(p->dude); |
105 | 111 |
int16_t h = sprite_get_h(p->dude); |
... | ... | |
108 | 114 |
double curr_health = gunner_get_curr_health(p); |
109 | 115 |
double health = gunner_get_health(p); |
110 | 116 |
double perc = curr_health/health; |
111 |
rectangle_t *green_bar = rectangle_ctor(x, y, (int16_t)(w*perc), 10); |
|
112 |
rectangle_set_fill_color(green_bar, GREEN_HEALTH_COLOR); |
|
113 |
rectangle_t *red_bar = rectangle_ctor(x+(int16_t)(w*perc), y, (int16_t)(w*(1-perc)), 10); |
|
114 |
rectangle_set_fill_color(red_bar, GRAPH_RED); |
|
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); |
|
115 | 119 |
char buf[20]; sprintf(buf, "%d/%d", (int)p->current_health, (int)p->health); |
116 |
text_set_text(p->txt, buf);
|
|
120 |
text_set_string(p->txt, buf);
|
|
117 | 121 |
text_set_pos(p->txt, x+w/2, y+10/2); |
118 |
rectangle_draw(green_bar); |
|
119 |
rectangle_draw(red_bar); |
|
122 |
rectangle_draw(p->green_bar);
|
|
123 |
rectangle_draw(p->red_bar);
|
|
120 | 124 |
text_draw(p->txt); |
121 |
rectangle_dtor(green_bar); |
|
122 |
rectangle_dtor(red_bar); |
|
123 |
|
|
124 | 125 |
} |
125 | 126 |
|
126 | 127 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2){ |
Also available in: Unified diff