Added function to gain resources
authorLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 16:45:57 +0000 (18:45 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 16:45:57 +0000 (18:45 +0200)
src/player.s

index 36f252c61c2101d2e560d252c1698e08b0def5d6..017bc3e4b27b2964b6ba0e4aa0c13ad6db747bfd 100644 (file)
@@ -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