From 21bf2b29c579c0b51ceef6c9931fd2a4e8730db2 Mon Sep 17 00:00:00 2001 From: Forest Belton Date: Mon, 19 Jul 2021 19:30:18 -0400 Subject: [PATCH] Add player inventory and item add routine --- src/player.s | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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