From 48b0ea5993b7151651c2a60a0d90c6cc60faae07 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 26 Jun 2025 18:03:22 +0200 Subject: [PATCH] actor: Added movement speed-based delay This is simply done by having a writable version of unit_delay_to_active in wram. The timer can now be changed at will. Also added st_custom for entierly custom runtime states :^) --- BUGS.md | 5 ++--- src/actortables.s | 2 +- src/defs.s | 2 ++ src/mem.s | 8 +++++++- src/player.s | 2 +- src/unit.s | 45 ++++++++++++++++++++++++++++++++------------- src/wram.s | 10 ++++++++++ 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/BUGS.md b/BUGS.md index b81cd17..fa76b8e 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,6 @@ # Known Bugs -## When place a new building the game crashes eventually +## Movement in multiple directions slows donw movement to a crawl -It seems to be related to the jp to hl caused by a cell's update routine. -There seem to be writes to weird hw registers when placing buildings. +When pressing two direction buttons movement speed calculations slow down a lot. diff --git a/src/actortables.s b/src/actortables.s index 8220698..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 008a45a..7544a69 100644 --- a/src/defs.s +++ b/src/defs.s @@ -7,6 +7,8 @@ #define WRAM 0xC000 #define WRAMLEN 0xFFF +#define STAT_MAX 100 + #define NULL 0 #define UNITS_MAX 20 diff --git a/src/mem.s b/src/mem.s index 45d102b..cdad297 100644 --- a/src/mem.s +++ b/src/mem.s @@ -18,7 +18,13 @@ mem_init: call unit_load_default_player call game_init call mbc1_init - + + ; copy delay to active template to wram + ld de, st_unit_delay_to_active_template + ld hl, st_unit_delay_to_active + ld bc, st_size + call memcpy + ret game_init: diff --git a/src/player.s b/src/player.s index 0a186eb..c5d3169 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, 48 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 90 act_skill_def_empty act_inventory_empty act_equipment_empty diff --git a/src/unit.s b/src/unit.s index 503fd80..3a91495 100644 --- a/src/unit.s +++ b/src/unit.s @@ -305,18 +305,35 @@ unit_collides_with_any_other: ld a, CF_COLLISION ret #undefine scratch_loop_i - - ; transitions a unit - ; to a movement animation - ; the animation time is dependant on movement - ; speed (100-stat_calc_speed) - ; the end-state of the move_animation should - ; clear rt_sub_tile to 0 + + ; sets st_unit_delay_to_active speed to unit's move speed + ; (STAT_MAX-stat_calc_speed) ; inputs: ; de: actor ; a: mask for rt_sub_tile ; rt_subtile |= a -unit_transition_to_move_animation: +unit_set_delay_to_active_speed: + push de + ld hl, act_rt_sub_tile + add hl, de ; hl = ptr to sub_tile + + ld b, a + ld a, [hl] + or a, b ; apply the mask + ld [hl], a ; store new value + + ; get movement speed + pop de + call stat_calc_speed + ld de, st_unit_delay_to_active ; de == st_time + ; this overwrites the wait time + ; by calculating the movement speed + ; and subtracting it from STAT_MAX + ld b, a ; b = current speed + ld a, STAT_MAX + ; a - b + sub a, b + ld [de], a ; delay timer is now speed ret ; moves a unit up @@ -348,7 +365,7 @@ unit_try_move_up: ; not bits set ld a, 0b00000000 - call unit_transition_to_move_animation + call unit_set_delay_to_active_speed ret @@ -368,7 +385,7 @@ unit_try_move_down: ; set down bit ld a, 0b10000000 - call unit_transition_to_move_animation + call unit_set_delay_to_active_speed ret @@ -388,7 +405,7 @@ unit_try_move_left: ; no bits set ld a, 0b00000000 - call unit_transition_to_move_animation + call unit_set_delay_to_active_speed ret @@ -409,7 +426,7 @@ unit_try_move_right: ; set right bit ld a, 0b01000000 - call unit_transition_to_move_animation + call unit_set_delay_to_active_speed ret @@ -583,7 +600,9 @@ unit_get_equipment: st_unit_idle: st_def 0x00, unit_idle, st_unit_idle -st_unit_delay_to_active: + ; template for st_unit_delay_to_active + ; in wram +st_unit_delay_to_active_template: st_def 8, unit_delay_to_active, st_unit_switch_to_active st_unit_delay_to_active_fast: diff --git a/src/wram.s b/src/wram.s index a160117..30ed67f 100644 --- a/src/wram.s +++ b/src/wram.s @@ -40,6 +40,16 @@ empty_oam: .adv oamsize ; ptr to actor for next UI update ui_draw_actor: .adv 2 + ; can be used for custom state transtions + ; simple write state info to this location + ; and return st_custom +st_custom: .adv st_size + ; it is common for delay to active to have a custom + ; timer to simulate movement speed + ; this is a valid delay state and should only be written to + ; to change its timer +st_unit_delay_to_active: .adv st_size + ; game state ; this region holds the entire game state ; everything thats needed for a savme game should be -- 2.30.2