+ ; 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
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
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