WIP: working on aborting moves when they would wrap map
authorLukas Krickl <lukas@krickl.dev>
Sat, 22 Mar 2025 17:36:30 +0000 (18:36 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 22 Mar 2025 17:36:30 +0000 (18:36 +0100)
src/defs.s
src/player.s
src/video.s

index 87c53dd6f48bcb4346cde729ab0524b5b4c1b5d1..5b79f6554a2375ae1cba2d07bafa5d22cbd56b42 100644 (file)
@@ -63,3 +63,9 @@
 .de CT_NONE, 1
 .de CT_GROUND, 1
 .de CT_WATER, 1
+
+  ; defines end of scroll location
+#define CURSOR_MIN_X 0
+#define CURSOR_MAX_X 0
+#define CURSOR_MIN_Y 0 
+#define CURSOR_MAX_Y 0
index bdb5f2a43ff66df29e6a6150a6705a485cd7c1b2..b06eff986d71c8e904e8eb37fefe81ab07360e7f 100644 (file)
@@ -122,6 +122,8 @@ cursor_move:
 
   ; if timer is 0 apply movement 
   ; and jump to next tile
+    call try_abort_move
+
     ld a, [cursor_y]
     ld b, a
 
@@ -141,3 +143,33 @@ cursor_move:
   pop af
   ret
 
+try_abort_move:
+  ld b, CURSOR_MIN_X
+  ld c, CURSOR_MOVE_SPEED * NEGATE
+  ld hl, cursor_x
+  ld de, cursor_move_x
+  call try_abort_move_at
+
+  ret
+
+  ; aborts a move direciton  
+  ; inputs: 
+  ;   b: compare variable (e.g. min or max value)
+  ;   c: move direction compare value (e.g. move + or -)
+  ;  hl: position ptr
+  ;  de: move variable to set to 0
+try_abort_move_at:
+  ; do not abort if position is wrong
+  ld a, [hl]
+  cp a, b
+  ret nz
+
+  ; do not abort if direction is wrong
+  ld a, [de]
+  cp a, c
+  ret nz
+  xor a, a
+  ld [de], a
+
+  ret
index 94019ffb7371c949a38e17216dc3e963a308aa33..a7c1e624d4efd9861261c2d6f425209515074102 100644 (file)
@@ -28,6 +28,7 @@ vblank:
   ret
 
   ; updates scroll based on scroll_move_y/x
+  ; do nothing if scroll would move oob
 scroll_update:
   ld a, [cursor_move_timer]
   cp a, 0