actors: Added sub-tile movement for up direction
authorLukas Krickl <lukas@krickl.dev>
Wed, 25 Jun 2025 08:18:11 +0000 (10:18 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 25 Jun 2025 08:18:11 +0000 (10:18 +0200)
src/actortables.s
src/defs.s
src/player.s
src/unit.s
src/unit_demo.s

index e92921d29a860adb46e024b688cb4a8445001309..511da3df8f0be5062150465459f0aac3e23e022d 100644 (file)
@@ -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
index 3cb754a68ef90805d2cb2512340eca2bdb73b628..e53961fce5791cd813bc29fc1bea527d908d4ff9 100644 (file)
 .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
index df4cdc6af352d9ea9ec52afd5ffb7ac0c8932327..b33d7d51ee5968dcc8ccc781982ca9f943527fb7 100644 (file)
@@ -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
index 407ce3f1b6be139dc56201ec740a149aea1b89f6..09cd21390a6d3b5d13ced32fcd1bd414587e155a 100644 (file)
@@ -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
index e7b502d82548a52291eb9fe286cd61a4af40bc7c..319999ffbe8ff46348ffe86bd05ee2a6f50c6da2 100644 (file)
@@ -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, 
+  act_stat_def2 1, 1, 1, 1, 1, 1, 1, 32
   act_skill_def_empty
   act_inventory_empty
   act_equipment_empty