From fc6a5e1e027196e3354a34106a4135c73d481936 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 25 Jun 2025 10:18:11 +0200 Subject: [PATCH] actors: Added sub-tile movement for up direction --- src/actortables.s | 2 +- src/defs.s | 7 ++--- src/player.s | 2 +- src/unit.s | 69 ++++++++++++++--------------------------------- src/unit_demo.s | 4 +-- 5 files changed, 28 insertions(+), 56 deletions(-) diff --git a/src/actortables.s b/src/actortables.s index e92921d..511da3d 100644 --- a/src/actortables.s +++ b/src/actortables.s @@ -1,7 +1,7 @@ #include "unit_demo.s" default_map_actor_table: -.db 0 ; 19 ; size +.db 19 ; size dw unit_demo_2 dw unit_demo_3 dw unit_demo_3 diff --git a/src/defs.s b/src/defs.s index 3cb754a..e53961f 100644 --- a/src/defs.s +++ b/src/defs.s @@ -199,11 +199,12 @@ .de act_rt_collided_with, 2 ; sub-tile position - ; nnnn0000: y subtile - ; 0000nnnn: x subtile + ; : y subtile + ; : x subtile ; if the subtile position overflows/underflows ; the actor may move on to the next tile -.de act_rt_subtile_pos, 1 +.de act_rt_subtile_y, 1 +.de act_rt_subtile_x, 1 .de act_size, 0 ; max bge queue size diff --git a/src/player.s b/src/player.s index df4cdc6..b33d7d5 100644 --- a/src/player.s +++ b/src/player.s @@ -41,7 +41,7 @@ unit_player: st_def 0x00, unit_player_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 2, 2, 0 act_stat_def1 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 48 act_skill_def_empty act_inventory_empty act_equipment_empty diff --git a/src/unit.s b/src/unit.s index 407ce3f..09cd213 100644 --- a/src/unit.s +++ b/src/unit.s @@ -306,31 +306,24 @@ unit_collides_with_any_other: ret #undefine scratch_loop_i -#define TMP_MOVEMENT_SPEED scratch ; calculates movement speed based un the current unit ; inputs: ; de: unit ; returns: - ; movement speed in sub-tiles in TMP_UNIT_MOVEMENT_SPEED + ; a: movement speed unit_calc_movement_speed: call stat_calc_speed - ; movement speed is simply speed / 16 - div16 a - cp a, 0 - jr nz, @not_zero_speed REL - inc a -@not_zero_speed: - ld [TMP_MOVEMENT_SPEED], a + sla a ; * 2 ret ; performs a sub tile move ; inputs: ; de: actor - ; $1: swap a/nop - ; $2: add/sub - ; $3: mask to apply to move speed (0xF0 or 0x0F) - ; returns if sub-tile movement does not - ; cause an over/underflow + ; hl: y/x position ptr + ; $1: subtile_y/x + ; $2: add/sub for sub tile calculation + ; $3: adc/sbc for tile calculation + ; carry bit is set if subtile position has a carry ; preserves: ; hl #macro unit_sub_tile_move @@ -338,39 +331,23 @@ unit_calc_movement_speed: push de call unit_calc_movement_speed + ; a = movement speed pop de - ld hl, act_rt_subtile_pos - add hl, de ; hl = subtile pos - - ld a, [TMP_MOVEMENT_SPEED] ld b, a ; b = movement speed - ld a, [hl] - $1 ; swap - and a, 0x0F ; mask bits we don't need - $2 a, b ; sub/add - ; test if overflow - ld c, a ; need value again in a bit - and a, 0xF0 - ; z flag is set if no overflow - push af ; push flag on to stack for now - - ld a, c ; now cut off value - and a, 0x0F ; mask it out in case of overflow - - $1 ; swap back - ld b, a ; b = new position - ld a, [hl] ; load value again - and a, $3 ; mask off - or a, b - ld [hl], a ; store new value - - ; if we did not over/underflow - ; exit now - pop af ; get back flag result + ld hl, $1 + add hl, de ; hl = subtile pos + + ld a, [hl] ; load position + $2 a, b ; add or sub position + ld [hl], a ; store new sub-tile position + pop hl - ret nz + ; now apply carry to real position + ld a, [hl] + sbc a, 0 + ld [hl], a #endmacro ; moves a unit up @@ -397,12 +374,7 @@ unit_try_move_up: pop de ret z - unit_sub_tile_move swap a, sub, 0xF0 - - ld a, [hl] - dec a - ld [hl], a - + unit_sub_tile_move act_rt_subtile_y, sub, sbc ret @@ -452,7 +424,6 @@ unit_try_move_right: ld [hl], a ret -#undefine TMP_MOVEMENT_SPEED ; centers the current scroll on the selected unit ; snaps to corners of the map diff --git a/src/unit_demo.s b/src/unit_demo.s index e7b502d..319999f 100644 --- a/src/unit_demo.s +++ b/src/unit_demo.s @@ -43,7 +43,7 @@ unit_demo_2: st_def 0x00, unit_demo_1_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 3, 3, 0 act_stat_def1 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 32 act_skill_def_empty act_inventory_empty act_equipment_empty @@ -56,7 +56,7 @@ unit_demo_3: st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update act_def ACT_T_DEMO_1, 0, 4, 4, 0 act_stat_def1 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 32 act_skill_def_empty act_inventory_empty act_equipment_empty -- 2.30.2