diff --git a/src/player.s b/src/player.s index f2043d9..a98dc1a 100644 --- a/src/player.s +++ b/src/player.s @@ -5,13 +5,15 @@ INCLUDE "util.inc" Section "Player Data", WRAM0 -; player data +DEF PLAYER_INV_SIZE EQU 32 + PLAYER_X:: db PLAYER_Y:: dw PLAYER_DIR:: db PLAYER_STATE:: db PLAYER_VY:: dw +PLAYER_INV:: DS (2 * PLAYER_INV_SIZE) Section "Player Code", ROM0 @@ -36,7 +38,7 @@ Player_Init:: ; Clear player data (X/Y initialized by map engine) ld hl, PLAYER_DIR xor a - REPT 7 + REPT (7 + 2 * PLAYER_INV_SIZE) ld [hl+], a ENDR @@ -322,3 +324,34 @@ Player_UpdateOAM:: .done: ret + +; Add item(s) to the player's inventory +; @param b Item ID +; @param c Item quantity +Player_AddInvItem:: + push de + + ld hl, PLAYER_INV + ld e, PLAYER_INV_SIZE + +.find_inv_slot: + ld a, [hl] + cp b + jr z, .update_item + + inc hl + dec e + jr nz, .find_inv_slot + +.update_item: + ; set item id + ld a, b + ld [hl+], a + + ; update item qty + ld a, [hl] + add c + ld [hl], a + + pop de + ret