Revision 227
implemented bullet movement and angle
ent.c | ||
---|---|---|
65 | 65 |
double vx, vy; |
66 | 66 |
sprite_t *b; |
67 | 67 |
}; |
68 |
bullet_t* (bullet_ctor)(basic_sprite_t *b){ |
|
68 |
bullet_t* (bullet_ctor)(basic_sprite_t *b, double x, double y, double vx, double vy){
|
|
69 | 69 |
bullet_t *ret = malloc(sizeof(bullet_t)); |
70 | 70 |
if(ret == NULL) return NULL; |
71 |
ret-> x = 0.0;
|
|
72 |
ret-> y = 0.0;
|
|
73 |
ret->vx = 0.0;
|
|
74 |
ret->vy = 0.0;
|
|
71 |
ret-> x = x;
|
|
72 |
ret-> y = y;
|
|
73 |
ret->vx = vx;
|
|
74 |
ret->vy = vy;
|
|
75 | 75 |
ret->b = sprite_ctor(b); |
76 | 76 |
if(ret->b == NULL){ |
77 | 77 |
bullet_dtor(ret); |
78 | 78 |
return NULL; |
79 |
}else return ret; |
|
79 |
} |
|
80 |
double angle = atan2(-ret->vy, ret->vx); |
|
81 |
sprite_set_angle(ret->b, angle-M_PI_2); |
|
82 |
return ret; |
|
80 | 83 |
} |
81 | 84 |
void (bullet_dtor)(bullet_t *p){ |
82 | 85 |
if(p == NULL) return; |
83 | 86 |
sprite_dtor(p->b); |
84 | 87 |
free(p); |
85 | 88 |
} |
86 |
void (bullet_set_pos) (bullet_t *p, double x, double y){ p->x = x; p->y = y; } |
|
87 |
void (bullet_set_angle)(bullet_t *p, double angle ){ sprite_set_angle(p->b, angle); } |
|
88 | 89 |
double (bullet_get_x) (const bullet_t *p){ return p->x; } |
89 | 90 |
double (bullet_get_y) (const bullet_t *p){ return p->y; } |
90 | 91 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; } |
Also available in: Unified diff