From 80c523500f993184d34cae21fecd6666f3134b9d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 6 Oct 2024 18:12:56 +0200 Subject: [PATCH] Added ability to reduce hp using a debug input --- src/hw.inc | 4 ++-- src/input.s | 14 +++++++++++++- src/player.s | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/hw.inc b/src/hw.inc index 85df27a..b44febb 100644 --- a/src/hw.inc +++ b/src/hw.inc @@ -40,8 +40,8 @@ .def int BTNRIGHT = 0x10 .def int BTNSTART = 0x08 .def int BTNSELECT = 0x04 -.def int BTNA = 0x02 -.def int BTNB = 0x01 +.def int BTNA = 0x01 +.def int BTNB = 0x02 ; obj off-screen offsets #define OBJ_OFF_X 8 diff --git a/src/input.s b/src/input.s index bc13f07..b07239f 100644 --- a/src/input.s +++ b/src/input.s @@ -1,5 +1,17 @@ + ; checks if button was just pressed + ; inputs: + ; $1 BUTTON + ; returns: + ; a: button state #macro input_just - + ld a, [curr_inputs] + ld c, a ; c = current inputs + ld a, [prev_inputs] + xor a, c ; xor with prev + ld c, a ; c = current xor prev + ld a, [curr_inputs] + and a, c ; give precdence to current inputs + and a, $1 #endmacro ; checks for a button press diff --git a/src/player.s b/src/player.s index 51feb85..36f252c 100644 --- a/src/player.s +++ b/src/player.s @@ -101,7 +101,23 @@ player_update: inc a ld [hl], a @notright: - + + input_just BTNA + jr z, @nota REL + + ; reduce hp by 1 + 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_use_resource + ; call for UI redraw + ld a, UI_REDRAW_HP + ld [ui_flags], a + pop hl +@nota: ; drawing @@ -145,5 +161,38 @@ player_update: ld a, b ld [hl+], a + ret + + ; uses a resource such as + ; hp, mp, atk or def down to 0 + ; inputs: + ; [hl]: pointer to selected resource + ; a : the amount to subtract +player_use_resource: + ld b, a ; b = to sub + ld a, [hl] ; a = current resource + cp a, 0 + ; skip if already at 0! + jr z, @skip REL + + sub a, b + ; if not < 0 + ; do not clear a + jr nc, @no_underflow REL + + ; a = 0 + xor a, a + +@no_underflow: + ; store result + ld [hl], a +@skip: + ret + ; gains a resource such as + ; hp, mp, atk, or def up to max + ; inputs: + ; [hl]: pointer to selected resource + ; a : the amount to add +player_gain_resource: ret -- 2.30.2