ld hl, act_rt_collision_pos_y
add hl, de
ld a, [hl] ; load y offset
+ div16 a
; if y is at bottom of map go back up a tile...
cp a, MAP_H-1 ;
; hl = act_pos_y
ld a, [hl]
+ div16 a
cp a, 0 ; top
jp z, unit_exit_top
ld a, [hl+]
+ div16 a
cp a, MAP_H-1
jp z, unit_exit_bottom
ld a, [hl] ; hl = x pos
+ div16 a
cp a, 0
jp z, unit_exit_left
ld a, [hl]
+ div16 a
cp a, MAP_W-1
jp z, unit_exit_right
add hl, de
; move player down
- ld a, MAP_H-1
+ ld a, MAP_H-2
+ mul16 a
ld [hl], a
ld a, [player_map_cursor]
add hl, de
; move player up
- ld a, 0
+ ld a, 1
+ mul16 a
ld [hl], a
ld a, [player_map_cursor]
add hl, de
; move player left
- ld a, 0
+ ld a, 1
+ mul16 a
ld [hl], a
ld a, [player_map_cursor]
add hl, de
; move player right
- ld a, MAP_W-1
+ ld a, MAP_W-2
+ mul16 a
ld [hl], a
ld a, [player_map_cursor]
; before a move is attempted
; ret on nz
; inputs:
- ; $1: dec/inc instruction
- ; $2: collision mask for tile
+ ; $1: register containing coordinate
+ ; $2: change in register (e.g. +16/-16)
+ ; $3: collision mask for tile
; de: actor
; returns:
; unit_test_collision_cf_flags: 0 if not collided with a tile
; perform tile collision check
push de
call unit_get_pos
- $1
+
+ ld a, $1
+ add a, ($2 & 0xFF)
+ ld $1, a
; write y and x pos
ld hl, act_rt_collision_pos_y
; set flags result
pop hl
ld [hl], a ; store last cf
- and a, $2
+ and a, $3
pop bc
pop de
ret nz
; actor position
unit_try_move_up:
; y - 1
- unit_test_collision dec b, CF_COLLISION
+ unit_test_collision b, -16 & 0xFF, CF_COLLISION
push de
ld hl, act_pos_y
unit_try_move_down:
; y + 1
- unit_test_collision inc b, CF_COLLISION
+ unit_test_collision b, 16, CF_COLLISION
ld hl, act_pos_y
add hl, de
unit_try_move_left:
; x - 1
- unit_test_collision dec c, CF_COLLISION
+ unit_test_collision c, -16 & 0xFF, CF_COLLISION
ld hl, act_pos_x
add hl, de
unit_try_move_right:
; x + 1
- unit_test_collision inc c, CF_COLLISION
+ unit_test_collision c, 16, CF_COLLISION
ld hl, act_pos_x
add hl, de