; bits:
; SYYYSXXX
act_dir_vector:
-.db 0x90 ; SOUTH
-.db 0x10 ; NORTH
-.db 0x09 ; WEST
-.db 0x01 ; EAST
+.db 0x10 ; SOUTH
+.db 0x90 ; NORTH
+.db 0x01 ; WEST
+.db 0x09 ; EAST
; reverse direction
act_dir_reverse:
ret
+ ; applies a direction vector to the current actor
+ ; inputs:
+ ; de: actor
+ ; b: direction vector (SYYYSXXX)
+act_apply_vec:
+ ld hl, act_pos_y
+ add hl, de
+
+ ld a, b
+ ; extract y direction
+ and a, 0xF0
+ swap a
+
+ ; a = y direction
+ push bc
+ push hl
+ call act_apply_pos
+ pop hl
+ pop bc
+
+ inc hl ; hl = x pos
+
+ ld a, b
+ and a, 0x0F
+ ; a = x direction
+ call act_apply_pos
+
+ ret
+
+ ; applies a single position based on its
+ ; sign bit
+ ; inputs:
+ ; hl: ptr to position
+ ; a: 0000SNNN -> vector value
+ ; preserves: de
+ ; uses hl, bc, af
+act_apply_pos:
+ ; check sign
+ bit 3, a
+ jr z, @nosign REL
+
+ and a, 0b00000111
+ ld b, a
+ ld a, [hl]
+
+ sub a, b
+ ld [hl], a
+
+ ret
+@nosign:
+ and a, 0b00000111
+ ld b, [hl]
+
+ add a, b
+ ld [hl], a
+
+ ret
+
+
; moves the actor forward
; does not perform collision checks
; inputs:
; de: actor
act_move_forward:
ld hl, act_dir
+ add hl, de ; hl = act_dir
ld a, [hl]
and a, ACT_DIR_MASK
ld b, 0
ld hl, act_dir_vector
add hl, bc ; hl = direction vector
+ ld b, [hl] ; b = direction
+
+ call act_apply_vec
+
ret
; moves the actor back
l1:
mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default, tile_id_table
.db 2, 0, 0, 0, 0, 0
- .db 0, 0, 0, 0, 0, 0
+ .db 3, 0, 0, 0, 0, 0
.db 0, 0, 0, 0, 0, 0
.db 0, 0, 0, 0, 0, 0
.db 0, 0, 0, 0, 0, 0