unit: Added unit scroll update
authorLukas Krickl <lukas@krickl.dev>
Mon, 12 May 2025 15:41:45 +0000 (17:41 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 12 May 2025 15:41:45 +0000 (17:41 +0200)
src/unit.s

index f5be36bd2e601102c2fb7e6fd4b7639d5d8ac087..78a9887764b94751809d52414ea268dea7f010f5 100644 (file)
@@ -54,7 +54,11 @@ unit_demo_1_update:
   push de
   call unit_handle_inputs
   pop de
-  
+  push de
+  call unit_scroll_center
+  pop de
+
   push bc
   call unit_demo_1_draw
   pop bc
@@ -173,6 +177,9 @@ unit_try_move_up:
   add hl, de
   ; hl = actor y
   ld a, [hl]
+  cp a, 0 ; upper bound
+  ret z
+
   dec a
   ld [hl], a
 
@@ -183,6 +190,9 @@ unit_try_move_down:
   add hl, de
   ; hl = actor y
   ld a, [hl]
+  cp a, MAP_H - 1 ; lower bound
+  ret z
+
   inc a
   ld [hl], a
   ret
@@ -192,6 +202,9 @@ unit_try_move_left:
   add hl, de
   ; hl = actor x
   ld a, [hl]
+  cp a, 0 ; left bound
+  ret z
+
   dec a
   ld [hl], a
   ret
@@ -201,6 +214,9 @@ unit_try_move_right:
   add hl, de
   ; hl = actor x
   ld a, [hl]
+  cp a, MAP_W - 1 ; right bound
+  ret z
+
   inc a
   ld [hl], a
   ret
@@ -210,6 +226,18 @@ unit_try_move_right:
   ; inputs:
   ;   de: actor
 unit_scroll_center:
+  ld hl, act_pos_y
+  add hl, de
+  ; hl = pos y
+  ld a, [hl+]
+  mul8 a
+  ld [scroll_y], a
+
+  ld a, [hl]
+  mul8 a
+  ld [scroll_x], a
+
+
   ret
   
   ; switches a unit to active state