- ; fixes y position
- ; inputs:
- ; a: direction
- ; hl: ptr to y pos
- ; returns:
- ; fixed y pos
- ; a is unchanged
- ; hl: += 1
- ; b: y pos adjusted / 16
-_act_test_col_y:
- push af
- and a, DIRUP
- jr nz, @up REL
-
- pop af
- push af
- and a, DIRDOWN
- jr nz, @down REL
-
- ; no change
- ld a, [hl+]
- div16 a
- ld b, a
-
- pop af
- ret
-@up:
- ld a, [hl+]
- div16 a
- dec a
- ld b, a
-
- pop af
- ret
-@down:
- ld a, [hl+]
- div16 a
- inc a
- ld b, a
-
- pop af
- ret
-
- ; fixes x positions
- ; inputs:
- ; a: direction
- ; hl: ptr to x pos
- ; returns:
- ; fixed x pos
- ; a is unchanged
- ; c: x pos adjusted / 16
-_act_test_col_x:
- push af
-
- and a, DIRLEFT
- jr nz, @left REL
-
- pop af
- push af
- and a, DIRRIGHT
- jr nz, @right REL
-
- ; no change
- ld a, [hl]
- div16 a
-
- ld c, a
- pop af
- ret
-@left:
- ld a, [hl]
- div16 a
- dec a
- ld c, a
-
- pop af
- ret
-@right:
- ld a, [hl]
- div16 a
- inc a
- ld c, a
-
- pop af
- ret
- ; stores current position in tmp_prev_pos
+ ; stores current position in col_prev_pos
; inputs:
; de: actor
act_backup_pos:
ld hl, act_pos_y
add hl, de
ld a, [hl+]
- ld [tmp_prev_pos], a ; y
+ ld [col_prev_pos], a ; y
ld a, [hl]
- ld [tmp_prev_pos+1], a ; x
+ ld [col_prev_pos+1], a ; x
ret
; restores prev x pos
; inputs:
; de: actor
act_rollback_pos_x:
+ ld hl, act_pos_x
+ add hl, de
+ ld a, [col_prev_pos+1]
+ ld [hl], a
ret
; restores prev y pos
; inputs:
; de: actor
act_rollback_pos_y:
+ ld hl, act_pos_y
+ add hl, de
+ ld a, [col_prev_pos]
+ ld [hl], a
ret
; test collision based on an actor
; inputs:
; de: actor
; col_point_xx: collision points
+ ; col_direction: set to direction moved in
+ ; col_prev_pos: set to previous positions
; if collision occures rolls back to
; previous position
act_test_tile_collision:
+ ld a, [col_direction]
+ and a, DIRUP
+ call nz, _act_test_tile_up_collision
+
+ ld a, [col_direction]
+ and a, DIRDOWN
+ call nz, _act_test_tile_down_collision
+
+ ld a, [col_direction]
+ and a, DIRLEFT
+ call nz, _act_test_tile_left_collision
+
+ ld a, [col_direction]
+ and a, DIRRIGHT
+ call nz, _act_test_tile_right_collision
+
ld hl, act_pos_y
add hl, de
and a, TF_WALL
ret
+
+ ; loads a collision point into bc
+ ; inputs:
+ ; $1: point name
+ ; returns:
+ ; b/c: y/x tile position
+#macro _act_tile_col_load_pt
+ ld a, [$1]
+ div16 a
+ ld b, a
+ ld a, [$1+1]
+ div16 a
+ ld c, a
+#endmacro
+
+ ; test direction routines:
+ ; preserve: de
+_act_test_tile_left_collision:
+ push de
+
+ ; top left point
+ _act_tile_col_load_pt col_point_tl
+
+ call map_get_tile
+ ld de, t_flags
+ add hl, de
+ ld a, [hl]
+ and a, TF_WALL
+ jr nz, @collision REL
+
+ ; bottom left point
+ _act_tile_col_load_pt col_point_bl
+
+ call map_get_tile
+ ld de, t_flags
+ add hl, de
+ ld a, [hl]
+ and a, TF_WALL
+ jr nz, @collision REL
+
+ pop de
+ ret
+@collision:
+ pop de
+ call act_rollback_pos_x
+ ret
+
+_act_test_tile_right_collision:
+ push de
+
+ pop de
+ ret
+
+_act_test_tile_up_collision:
+ push de
+ pop de
+ ret
+
+_act_test_tile_down_collision:
+ push de
+ pop de
+ ret
; update routines for each actor
act_map_update_table: