Revision 162
each sprite should be loaded with the adequate function that sets its center correctly
sprite.c | ||
---|---|---|
13 | 13 |
uint8_t *map; |
14 | 14 |
}; |
15 | 15 |
|
16 |
sprite_t* sprite_ctor(const xpm_map_t xpm){
|
|
16 |
sprite_t* sprite_ctor(const char **xpm, int u0, int v0){
|
|
17 | 17 |
sprite_t *ret = (sprite_t*)malloc(sizeof(sprite_t)); |
18 | 18 |
if(ret == NULL) return NULL; |
19 | 19 |
enum xpm_image_type type = XPM_8_8_8_8; |
20 | 20 |
xpm_image_t img; |
21 |
ret->map = xpm_load(xpm, type, &img); |
|
21 |
ret->map = xpm_load((xpm_map_t)xpm, type, &img);
|
|
22 | 22 |
if(ret->map == NULL){ |
23 | 23 |
free(ret); |
24 | 24 |
return NULL; |
... | ... | |
27 | 27 |
ret->y = 0; |
28 | 28 |
ret->w = img.width; |
29 | 29 |
ret->h = img.height; |
30 |
ret->u0 = 0; |
|
31 |
ret->v0 = 0; |
|
30 |
ret->u0 = u0;
|
|
31 |
ret->v0 = u0;
|
|
32 | 32 |
ret->theta = 0; |
33 | 33 |
return ret; |
34 | 34 |
} |
35 |
|
|
36 | 35 |
void sprite_dtor(sprite_t *p){ |
37 | 36 |
if(p == NULL) return; |
38 | 37 |
if(p->map) free(p->map); |
... | ... | |
41 | 40 |
|
42 | 41 |
void sprite_set_x(sprite_t *p, int x){ p->x = x; } |
43 | 42 |
void sprite_set_y(sprite_t *p, int y){ p->y = y; } |
44 |
void sprite_set_pos(sprite_t *p, int x, int y){ |
|
45 |
sprite_set_x(p, x); |
|
46 |
sprite_set_y(p, y); |
|
47 |
} |
|
43 |
void sprite_set_pos(sprite_t *p, int x, int y){ sprite_set_x(p, x); sprite_set_y(p, y); } |
|
48 | 44 |
void sprite_set_angle(sprite_t *p, double angle){ p->theta = angle; } |
49 |
void sprite_set_center(sprite_t *p, int u0, int v0){ |
|
50 |
p->u0 = u0; |
|
51 |
p->v0 = v0; |
|
52 |
} |
|
45 |
void sprite_set_center(sprite_t *p, int u0, int v0){ p->u0 = u0; p->v0 = v0; } |
|
53 | 46 |
|
54 | 47 |
int sprite_get_w(const sprite_t *p){ return p->w; } |
55 | 48 |
int sprite_get_h(const sprite_t *p){ return p->h; } |
... | ... | |
57 | 50 |
void sprite_src2pic(const sprite_t *p, int x, int y, int *u, int *v){ |
58 | 51 |
int dx = x - p->x; |
59 | 52 |
int dy = y - p->y; |
60 |
int du = dx*cos(p->theta) - dy*sin(p->theta); |
|
61 |
int dv = dx*sin(p->theta) + dy*cos(p->theta); |
|
62 |
*u = du + p->u0; |
|
63 |
*v = dv + p->v0; |
|
53 |
//int du = dx*cos(p->theta) - dy*sin(p->theta); |
|
54 |
//int dv = dx*sin(p->theta) + dy*cos(p->theta); |
|
55 |
//*u = du + p->u0; |
|
56 |
//*v = dv + p->v0; |
|
57 |
//*u = dx*cos(p->theta) - dy*sin(p->theta) + p->u0; |
|
58 |
//*v = dx*sin(p->theta) + dy*cos(p->theta) + p->v0; |
|
59 |
double s = sin(p->theta); |
|
60 |
double c = cos(p->theta); |
|
61 |
*u = dx*c - dy*s + p->u0; |
|
62 |
*v = dx*s + dy*c + p->v0; |
|
64 | 63 |
} |
65 | 64 |
|
66 | 65 |
void sprite_draw(const sprite_t *p){ |
Also available in: Unified diff