ret
+ ; generic collision check code
+ ; loads ct_mask and actor position
+ ; and calls collision tile
+ ; inputs:
+ ; bc: actor ptr
+ ; de: y/x position offset
+ ; returns:
+ ; a/h: collision flags
+generic_collision_check:
+ ; load actor y/x into de
+ inc bc ; bc = actor y
+ ld a, [bc]
+ add a, d ; y + offset
+
+ ld d, a ; d = target y
+ inc bc ; bc = actor x
+ ld a, [bc]
+ add a, e ; x + offset
+ ld e, a ; e = target x
+
+ ; if any collision happens now
+ ; we stop the animation
+ call collision_tile
+ ld h, a ; store original a in h for now
+ ret
+
+ ; performs a simple collision check for actors
+ ; inputs:
+ ; bc: actor ptr
+ ; de: y/x position offset
+act_collision_check:
+ ; set collision mask
+ ld a, RF_WALL | RF_ACTOR | RF_DOOR
+ ld [ct_mask], a
+
+ call generic_collision_check
+
+ and a, RF_WALL | RF_ACTOR | RF_DOOR
+ jr z, @skip REL
+ ; abort walk state
+ call anim_abort_walk
+ jr @skip REL
+@skip:
+ ret
+
; advance to the next actor if end_turn != 0
; effectively ending the current actor's turn
who_next:
; bc: actor ptr
; de: y/x position offset
player_collision_check:
-
; set collision mask
ld a, RF_WALL | RF_DOOR | RF_ACTOR
ld [ct_mask], a
-
- ; load actor y/x into de
- inc bc ; bc = actor y
- ld a, [bc]
- add a, d ; y + offset
-
- ld d, a ; d = target y
- inc bc ; bc = actor x
- ld a, [bc]
- add a, e ; x + offset
- ld e, a ; e = target x
-
- ; if any collision happens now
- ; we stop the animation
- call collision_tile
- ld h, a ; store original a in h for now
+
+ call generic_collision_check
and a, RF_DOOR
jr z, @no_door_hit REL
ld a, [engine_flags]
or a, EG_FLOAD_ROOM
ld [engine_flags], a
-
@no_door_hit:
ld [hl+], a ; set next state
ld a, ANIM_PLAYER_WALK_FRAMES
ld [hl], a ; set param[0]
+
+ ; perform collision check
+ ld d, 0xFF & 0 - ANIM_TILE_SIZE
+ ld e, 0
+ call act_collision_check
@not_north:
cp a, SOUTH
ld a, ANIM_PLAYER_WALK_FRAMES
ld [hl], a ; set param[0]
+ ; perform collision check
+ ld d, ANIM_TILE_SIZE
+ ld e, 0
+ call act_collision_check
@not_south:
cp a, WEST
ld a, ANIM_PLAYER_WALK_FRAMES
ld [hl], a ; set param[0]
+ ; perform collision check
+ ld d, 0
+ ld e, 0xFF & 0 - ANIM_TILE_SIZE
+ call act_collision_check
@not_west:
cp a, EAST
ld a, ANIM_PLAYER_WALK_FRAMES
ld [hl], a ; set param[0]
+ ; perform collision check
+ ld d, 0
+ ld e, ANIM_TILE_SIZE
+ call act_collision_check
@not_east:
; verify collision