Revision 159
working
sprite.c | ||
---|---|---|
13 | 13 |
sprite_t* sprite_ctor(const xpm_map_t xpm){ |
14 | 14 |
sprite_t *ret = (sprite_t*)malloc(sizeof(sprite_t)); |
15 | 15 |
if(ret == NULL) return NULL; |
16 |
enum xpm_image_type type = XPM_INDEXED;
|
|
16 |
enum xpm_image_type type = XPM_8_8_8;
|
|
17 | 17 |
xpm_image_t img; |
18 | 18 |
ret->map = xpm_load(xpm, type, &img); |
19 | 19 |
if(ret->map == NULL){ |
20 | 20 |
free(ret); |
21 | 21 |
return NULL; |
22 | 22 |
} |
23 |
ret->x = 0; |
|
24 |
ret->y = 0; |
|
23 | 25 |
ret->w = img.width; |
24 | 26 |
ret->h = img.height; |
25 | 27 |
return ret; |
... | ... | |
42 | 44 |
int sprite_get_h(const sprite_t *p){ return p->h; } |
43 | 45 |
|
44 | 46 |
void sprite_draw(const sprite_t *p){ |
47 |
uint8_t *m = p->map; |
|
45 | 48 |
for (int i = 0; i < p->w; i++) { |
46 |
for (int j = 0; j < p->h; j++) { |
|
47 |
if (p->x + i < get_XRes() && p->y + j < get_YRes()) { |
|
48 |
set_pixel(p->x + i, p->y + j, p->map[i + j * p->w]); |
|
49 |
for (int j = 0; j < p->h; j++, m += 3) { |
|
50 |
if (p->x + i < get_XRes() && p->y + j < get_YRes()){ |
|
51 |
uint32_t color = SET_COLOR(*m,*(m+1),*(m+2)); |
|
52 |
set_pixel(p->x + i, p->y + j, color); |
|
49 | 53 |
} |
50 | 54 |
} |
51 | 55 |
} |
Also available in: Unified diff