Revision 203
added bullet
ent.c | ||
---|---|---|
10 | 10 |
|
11 | 11 |
void (ent_set_scale) (double n){ scale = n; } |
12 | 12 |
void (ent_set_origin)(double x, double y){ x_origin = x; y_origin = y; } |
13 |
|
|
14 | 13 |
double (ent_get_scale) (void){ return scale; } |
15 | 14 |
double (ent_get_XLength)(void){ return graph_get_XRes()/scale; } |
16 | 15 |
double (ent_get_YLength)(void){ return graph_get_YRes()/scale; } |
17 | 16 |
|
18 | 17 |
struct gunner{ |
19 |
double x, y; //real position in meters
|
|
18 |
double x, y; //real position |
|
20 | 19 |
sprite_t *dude; |
21 | 20 |
sprite_t *weapon; |
22 | 21 |
}; |
23 |
|
|
24 | 22 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){ |
25 | 23 |
gunner_t *ret = malloc(sizeof(gunner_t)); |
26 | 24 |
if(ret == NULL) return NULL; |
... | ... | |
39 | 37 |
sprite_dtor(p->weapon); |
40 | 38 |
free(p); |
41 | 39 |
} |
42 |
|
|
43 | 40 |
void (gunner_set_pos) (gunner_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; } |
44 | 41 |
void (gunner_set_angle)(gunner_t *p, double angle ){ |
45 | 42 |
sprite_set_angle(p->dude , angle); |
46 | 43 |
sprite_set_angle(p->weapon, angle); |
47 | 44 |
} |
48 |
|
|
49 | 45 |
double (gunner_get_x) (const gunner_t *p){ return p->x; } |
50 | 46 |
double (gunner_get_y) (const gunner_t *p){ return p->y; } |
51 | 47 |
int16_t (gunner_get_x_screen)(const gunner_t *p){ return (p->x-x_origin)*scale; } |
52 | 48 |
int16_t (gunner_get_y_screen)(const gunner_t *p){ return (p->y-y_origin)*scale; } |
53 |
|
|
54 | 49 |
void (gunner_draw)(gunner_t *p){ |
55 | 50 |
const int16_t x_screen = gunner_get_x_screen(p); |
56 | 51 |
const int16_t y_screen = gunner_get_y_screen(p); |
... | ... | |
61 | 56 |
sprite_draw (p->weapon); |
62 | 57 |
sprite_draw (p->dude ); |
63 | 58 |
} |
59 |
|
|
60 |
struct bullet{ |
|
61 |
double x, y; //real position |
|
62 |
sprite_t *b; |
|
63 |
}; |
|
64 |
bullet_t* (bullet_ctor)(basic_sprite_t *b){ |
|
65 |
bullet_t *ret = malloc(sizeof(bullet_t)); |
|
66 |
if(ret == NULL) return NULL; |
|
67 |
ret->x = 0.0; |
|
68 |
ret->y = 0.0; |
|
69 |
ret->b = sprite_ctor(b); |
|
70 |
if(ret->b == NULL){ |
|
71 |
bullet_dtor(ret); |
|
72 |
return NULL; |
|
73 |
}else return ret; |
|
74 |
} |
|
75 |
void (bullet_dtor)(bullet_t *p){ |
|
76 |
if(p == NULL) return; |
|
77 |
sprite_dtor(p->b); |
|
78 |
free(p); |
|
79 |
} |
|
80 |
void (bullet_set_pos) (bullet_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; } |
|
81 |
void (bullet_set_angle)(bullet_t *p, double angle ){ sprite_set_angle(p->b, angle); } |
|
82 |
double (bullet_get_x) (const bullet_t *p){ return p->x; } |
|
83 |
double (bullet_get_y) (const bullet_t *p){ return p->y; } |
|
84 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; } |
|
85 |
int16_t (bullet_get_y_screen)(const bullet_t *p){ return (p->y-y_origin)*scale; } |
|
86 |
void (bullet_draw)(bullet_t *p){ |
|
87 |
const int16_t x_screen = bullet_get_x_screen(p); |
|
88 |
const int16_t y_screen = bullet_get_y_screen(p); |
|
89 |
sprite_set_pos (p->b, x_screen, y_screen); |
|
90 |
sprite_set_scale(p->b, scale); |
|
91 |
sprite_draw (p->b); |
|
92 |
} |
Also available in: Unified diff