Browse Source

Add player inventory and item add routine

master
Forest Belton 3 years ago
parent
commit
21bf2b29c5
1 changed files with 35 additions and 2 deletions
  1. +35
    -2
      src/player.s

+ 35
- 2
src/player.s View File

@ -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

Loading…
Cancel
Save