Prev: C99B Up: Map Next: CA65
C9F6: Check if Maroc is moving through an open doorway
Door has been identified as OPEN.
Because door positions vary when open depending on the wall section they sit in, the next routine adjusts the doorway exit point, based on the open door's graphic position.
After this adjustment has been made the collision detection routine at DFD5 is used to determine if Maroc is moving through the doorway.
C9F6 LD A,($EAAF) Door graphic's horizontal position offset
C9F9 CP $F8
C9FB JR Z,$CA05 The only door frame with this value offset is the back wall open door
C9FD CP $E8
C9FF JR Z,$CA09 The only door frame with this value offset is the right wall open door
CA01 LD A,$F8 Horizontal pixel offset for left wall open door left wall open door (-8 pixels)
CA03 JR $CA0B
CA05 LD A,$0C Horizontal pixel offset for the back wall open door (+12 pixels)
CA07 JR $CA0B
CA09 LD A,$08 Horizontal pixel offset for the right wall open door (+8 pixels)
Add the adjusted offset to door horizontal pixel position
CA0B LD B,A Get the pixel offset for this door's exit/entry point
CA0C LD A,($EAD3) Get the door's horizontal pixel position
CA0F ADD A,B Add the pixel offset
CA10 LD D,A Store in the D register - used for the horizontal 'hit box' for collision check in CALL at CA19 (to DFD5)
CA11 LD A,($EAD2) Get the door's vertical pixel position
CA14 SUB $08 Small (-8 pixel) vertical adjustment
CA16 LD E,A Store in E register - used for the vertical 'hit box' for collision check in CALL at CA19 (to DFD5)
CA17 LD C,$00 Collision type = 0 - this is the collision/event ID for checks against Maroc's position
CA19 CALL $DFD5 Check for collision
CA1C CP $00 A register returned with 1 = collision, 0 = no collision
CA1E JR NZ,$CA32 If there's a collision, skip the next few instructions
No collision detected on that check
CA20 LD A,E Retrieve previously adjusted horizontal pixel check position
CA21 SUB $04 Make a further small (-4 more pixels) horizontal adjustment
CA23 LD E,A Store back in E register (horizontal 'hit box' check)
CA24 LD A,($EAD3) Door vertical pixel position
CA27 LD D,A Retrieve vertical 'hit box' pixel position from D register
CA28 LD C,$00 Collision type = 0 - this is the collision/event ID for checks against Maroc's position
CA2A CALL $DFD5 Check for collision
CA2D CP $00
CA2F JP Z,$CAF6 No collision, can jump out of routine here
Collision detected - Maroc is within range of the open door. Check he's actually moving towards it.
CA32 LD A,($EAAF) Retrieve door graphic's horizontal pixel graphic offset
CA35 CP $F8 Offset for the back wall open door
CA37 JR Z,$CA4C
CA39 CP $E8 Offset for the right wall open door
CA3B LD A,($EB04) Get Maroc's horizontal movement speed as it'll need to be evaluated for left and right wall doors
CA3E JR Z,$CA5B
Door is a left wall open door. Check Maroc's horizontal movement:
CA40 CP $00 Is Maroc moving left or right?
CA42 JP Z,$CAF6 If not, skip out of this routine
CA45 CP $80
CA47 JP NC,$CAF6 Skip out of this routine if Maroc is moving right
CA4A JR $CA65 ...otherwise Maroc is moving left, so send him through the doorway
Door is a back wall open door. Check Maroc's vertical movement:
CA4C LD A,($EB05) Maroc's vertical movement speed
CA4F CP $00 Is Maroc moving up or down?
CA51 JP Z,$CAF6 If not, skip out of this routine
CA54 CP $80
CA56 JP NC,$CAF6 Skip out of this routine if Maroc is moving down
CA59 JR $CA65 ...otherwise Maroc is moving upwards, so send him through the doorway
Door is a right wall open door. Check Maroc's horizontal movement:
CA5B CP $00 Is Maroc moving left or right?
CA5D JP Z,$CAF6 If not, skip out of this routine
CA60 CP $80
CA62 JP C,$CAF6 Skip out of this routine if Maroc is moving left
...otherwise Maroc is moving right, so send him through the doorway (continue to the next routine)
Prev: C99B Up: Map Next: CA65