Added ability to reduce hp using a debug input
authorLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 16:12:56 +0000 (18:12 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 16:12:56 +0000 (18:12 +0200)
src/hw.inc
src/input.s
src/player.s

index 85df27a69fa1ee7d8dd72669acff17e05b009867..b44febb03b6383e36acda0ff666319db9b6d8532 100644 (file)
@@ -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
index bc13f071a7d7ee9bcf68601ba60f9657911b308f..b07239f74db753cd2db404c7216e673ac52468c0 100644 (file)
@@ -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
index 51feb8558d1db2d4c1a4f11eb088f131f60dd4a4..36f252c61c2101d2e560d252c1698e08b0def5d6 100644 (file)
@@ -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