From 0b1e7efd1ced04ba2f1ffda7743a6dc0d342fd7c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 6 Oct 2024 18:45:57 +0200 Subject: [PATCH] Added function to gain resources --- src/player.s | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/player.s b/src/player.s index 36f252c..017bc3e 100644 --- a/src/player.s +++ b/src/player.s @@ -119,6 +119,24 @@ player_update: pop hl @nota: + input_just BTNB + jr z, @notb REL + + ; gain 1 hp + ld a, 1 + ; make sure we do not mess with hl + push hl + ; hl = player_x right now + inc hl + inc hl ; hl = player_hp + call player_gain_resource + ; call for UI redraw + ld a, UI_REDRAW_HP + ld [ui_flags], a + pop hl + +@notb: + ; drawing ; sotre x in e @@ -195,4 +213,22 @@ player_use_resource: ; [hl]: pointer to selected resource ; a : the amount to add player_gain_resource: + ld b, a ; b = to add + ld a, [hl+] ; a = current resource. hl = max + cp a, [hl] ; a = max resource + ; skip if already at max + jp z, @skip + + ; add new value + add a, b + cp a, [hl] + jp c, @no_overflow + + ld a, [hl] ; a = amx + +@no_overflow: + ; store value + dec hl ; hl = current resource + ld [hl], a +@skip: ret -- 2.30.2