forked from NotAShelf/rogged
player: correct item pickup order to copy before marking picked_up
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ie226b4a0ae6566ca77ab49b7d22f36726a6a6964
This commit is contained in:
parent
5fbe7c8c60
commit
c61e31f628
1 changed files with 11 additions and 9 deletions
10
src/player.c
10
src/player.c
|
|
@ -43,8 +43,7 @@ static Item *get_item_at(Item *items, int count, int x, int y) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int player_move(Player *p, int dx, int dy, Map *map, Enemy *enemies,
|
||||
int enemy_count, Item *items, int item_count) {
|
||||
int player_move(Player *p, int dx, int dy, Map *map, Enemy *enemies, int enemy_count, Item *items, int item_count) {
|
||||
int new_x = p->x + dx;
|
||||
int new_y = p->y + dy;
|
||||
|
||||
|
|
@ -98,9 +97,12 @@ void player_pickup(Player *p, Item *i) {
|
|||
return; // already picked up
|
||||
}
|
||||
|
||||
i->picked_up = 1;
|
||||
p->inventory[p->inventory_count] = *i; // copy item to inventory
|
||||
// Copy item to inventory
|
||||
p->inventory[p->inventory_count] = *i;
|
||||
p->inventory_count++;
|
||||
|
||||
// Mark original as picked up
|
||||
i->picked_up = 1;
|
||||
}
|
||||
|
||||
void player_use_item(Player *p, Item *i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue