Moves item update to its own function

This commit is contained in:
Linus Probert 2019-02-28 21:53:30 +01:00
parent 7b47c6a6bf
commit 6542e4f1d0
3 changed files with 22 additions and 4 deletions

View File

@ -40,6 +40,18 @@ item_create(void)
return item;
}
void
item_update(Item *item)
{
LinkedList *subsprites = item->subsprites;
while (subsprites != NULL) {
Sprite *sprite = subsprites->data;
sprite->pos = item->sprite->pos;
sprite->pos.x += 15 - sprite->dim.width / 2;
subsprites = subsprites->next;
}
}
void
item_render(Item *item, Camera *cam)
{
@ -47,10 +59,7 @@ item_render(Item *item, Camera *cam)
LinkedList *subsprites = item->subsprites;
while (subsprites != NULL) {
Sprite *sprite = subsprites->data;
sprite->pos = item->sprite->pos;
sprite->pos.x + 15 - sprite->dim.width / 2;
sprite_render(sprite, cam);
sprite_render(subsprites->data, cam);
subsprites = subsprites->next;
}
}

View File

@ -46,6 +46,9 @@ item_create(void);
void
item_collected(Item*, Player*);
void
item_update(Item*);
void
item_render(Item*, Camera*);

View File

@ -295,6 +295,12 @@ map_update(UpdateData *data)
sprite_update(room->tiles[i][j]->sprite, data);
}
}
LinkedList *items = map->items;
while (items) {
item_update(items->data);
items = items->next;
}
}
void map_render(Map *map, Camera *cam)