root / proj / src / ent.c @ 213
History | View | Annotate | Download (3.06 KB)
1 | 193 | up20180642 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include "ent.h" |
||
4 | |||
5 | #include "graph.h" |
||
6 | |||
7 | static double scale = 1.0; |
||
8 | static int16_t x_origin = 0; |
||
9 | static int16_t y_origin = 0; |
||
10 | |||
11 | void (ent_set_scale) (double n){ scale = n; } |
||
12 | void (ent_set_origin)(double x, double y){ x_origin = x; y_origin = y; } |
||
13 | 194 | up20180642 | double (ent_get_scale) (void){ return scale; } |
14 | 193 | up20180642 | double (ent_get_XLength)(void){ return graph_get_XRes()/scale; } |
15 | double (ent_get_YLength)(void){ return graph_get_YRes()/scale; } |
||
16 | |||
17 | 201 | up20180642 | struct gunner{
|
18 | 203 | up20180642 | double x, y; //real position |
19 | 193 | up20180642 | sprite_t *dude; |
20 | sprite_t *weapon; |
||
21 | }; |
||
22 | 201 | up20180642 | gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){ |
23 | gunner_t *ret = malloc(sizeof(gunner_t));
|
||
24 | 193 | up20180642 | if(ret == NULL) return NULL; |
25 | ret->x = 0.0; |
||
26 | ret->y = 0.0; |
||
27 | ret->dude = sprite_ctor(dude ); |
||
28 | ret->weapon = sprite_ctor(weapon); |
||
29 | if(ret->dude == NULL || ret->weapon == NULL){ |
||
30 | 201 | up20180642 | gunner_dtor(ret); |
31 | 193 | up20180642 | return NULL; |
32 | } else return ret; |
||
33 | } |
||
34 | 201 | up20180642 | void (gunner_dtor)(gunner_t *p){
|
35 | 193 | up20180642 | if(p == NULL) return; |
36 | sprite_dtor(p->dude); |
||
37 | sprite_dtor(p->weapon); |
||
38 | free(p); |
||
39 | } |
||
40 | 201 | up20180642 | void (gunner_set_pos) (gunner_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
|
41 | void (gunner_set_angle)(gunner_t *p, double angle ){ |
||
42 | 193 | up20180642 | sprite_set_angle(p->dude , angle); |
43 | sprite_set_angle(p->weapon, angle); |
||
44 | } |
||
45 | 201 | up20180642 | double (gunner_get_x) (const gunner_t *p){ return p->x; } |
46 | double (gunner_get_y) (const gunner_t *p){ return p->y; } |
||
47 | int16_t (gunner_get_x_screen)(const gunner_t *p){ return (p->x-x_origin)*scale; } |
||
48 | int16_t (gunner_get_y_screen)(const gunner_t *p){ return (p->y-y_origin)*scale; } |
||
49 | void (gunner_draw)(gunner_t *p){
|
||
50 | const int16_t x_screen = gunner_get_x_screen(p);
|
||
51 | const int16_t y_screen = gunner_get_y_screen(p);
|
||
52 | 193 | up20180642 | sprite_set_pos (p->dude , x_screen, y_screen); |
53 | sprite_set_pos (p->weapon, x_screen, y_screen); |
||
54 | sprite_set_scale(p->dude , scale); |
||
55 | sprite_set_scale(p->weapon, scale); |
||
56 | sprite_draw (p->weapon); |
||
57 | sprite_draw (p->dude ); |
||
58 | } |
||
59 | 203 | up20180642 | |
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 | } |