From: Lukas Krickl Date: Mon, 12 May 2025 15:41:45 +0000 (+0200) Subject: unit: Added unit scroll update X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=95f487fde0f196e3de376fed11215a4b0c6fd5db;p=gbrg%2F.git unit: Added unit scroll update --- diff --git a/src/unit.s b/src/unit.s index f5be36b..78a9887 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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