+ ; 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
+
+ ; test collision based on an actor
+ ; and a direction
+ ; inputs:
+ ; de: actor
+ ; a: direction
+ ; returns:
+ ; a: new direction
+ ; a: 0 if move should be aborted
+act_test_collision:
+ push af
+
+ ld hl, act_pos_y
+ add hl, de
+
+ call _act_test_col_y
+ call _act_test_col_x
+
+ ; b/c = y/x
+ call map_get_tile
+
+ ld de, t_flags
+ add hl, de
+ ld a, [hl]
+ and a, TF_WALL
+ jr nz, @collision REL
+
+ pop af
+ ret
+@collision:
+ pop af
+ ld a, 0
+ ret
+
; update routines for each actor
actor_map_update_table:
; tile flags
.se 1
+.de TF_WALL, 1
; tile struct
.se 0
@notright:
ret
@set:
+ ld de, player
+ call act_test_collision
+ cp a, 0
+ ret z
+
ld [player_direction], a
ld a, 16 ; tile size
ld [player_move_timer], a
tiledef TT_EMPTY, 0, GFX_GRASS
tile_wall:
- tiledef TT_WALL, 0, GFX_WALL
+ tiledef TT_WALL, TF_WALL, GFX_WALL