Prev: 59076 Up: Map Next: 59311
59127: Process Player Tracking Enemy
Used by the routine at Process_Cluster_Entity.
Per-frame entity handler for the slow player-tracking enemy. Tests player contact via HitTestBounds8AtHL; triggers death via Strip_Attributes_And_Fade if touching. Computes the signed Y and X distance from the player at 50388 and 50389 halves it five times to derive a velocity nudge, and negates if the enemy is above or to the left of the player. Reads the entity facing byte; on a random 1-in-8192 chance sets it to 26 (freeze state). If the facing is 26 flips both velocity components and tests for a 1-in-256 chance to clear the freeze. Applies the computed Y and X nudge to the entity position, clamping to the play area, and draws the entity via Draw_Entity_Sprite.
Process_Player_Tracking_Enemy 59127 LD HL,50388 Set the player Y address in alternate HL and test player contact via HitTestBounds8AtHL; trigger death via Strip_Attributes_And_Fade if touching.
59130 EXX
59131 CALL HitTestBounds8AtHL
59134 JP NC,Strip_Attributes_And_Fade Step back three bytes to the entity Y position and load the player Y coordinate at 50388.
59137 DEC HL
59138 DEC HL
59139 DEC HL
59140 LD C,(HL)
59141 EX DE,HL
59142 LD A,(50388)
59145 LD L,A Compute the signed Y nudge: subtract the entity Y from the player Y, halve five times, and negate if the entity is above the player.
59146 LD H,0
59148 LD B,0
59150 AND A
59151 SBC HL,BC
59153 BIT 0,H
59155 LD A,L
59156 JP Z,Process_Player_Tracking_Enemy_Nudge_Y
59159 NEG
Process_Player_Tracking_Enemy_Nudge_Y 59161 SRL A Scale the Y nudge and restore its sign.
59163 SRL A
59165 SRL A
59167 SRL A
59169 SRL A
59171 BIT 0,H
59173 JP Z,Process_Player_Tracking_Enemy_Nudge_X
59176 NEG
Process_Player_Tracking_Enemy_Nudge_X 59178 EX AF,AF' Compute the signed X nudge from the player X coordinate at 50389 in the same way.
59179 LD A,(50389)
59182 LD L,A
59183 LD H,0
59185 INC DE
59186 LD A,(DE)
59187 LD C,A
59188 LD B,0
59190 AND A
59191 SBC HL,BC
59193 BIT 0,H
59195 LD A,L
59196 JP Z,Process_Player_Tracking_Enemy_0
59199 NEG
Process_Player_Tracking_Enemy_0 59201 SRL A
59203 SRL A
59205 SRL A
59207 SRL A
59209 SRL A
59211 BIT 0,H
59213 JP Z,Process_Player_Tracking_Enemy_Face
59216 NEG
Process_Player_Tracking_Enemy_Face 59218 LD B,A Store the scaled Y nudge in B and X nudge in C; step back to the entity facing byte.
59219 EX AF,AF'
59220 LD C,A
59221 EX DE,HL
59222 DEC HL
59223 DEC HL
59224 LD A,(HL)
59225 CP 26
59227 JP Z,Process_Player_Tracking_Enemy_Freeze Read the facing byte; if 26 jump to Process_Player_Tracking_Enemy_Freeze; otherwise test a 1-in-8192 random chance (Generate_Random_Byte twice, masked to 31 and 63) to set the facing to 26 (freeze).
59230 CALL Generate_Random_Byte
59233 AND 31
59235 JP NZ,Process_Player_Tracking_Enemy_Move
59238 CALL Generate_Random_Byte
59241 AND 63
59243 JP NZ,Process_Player_Tracking_Enemy_Move
59246 LD (HL),26
59248 JP Process_Player_Tracking_Enemy_Move
Process_Player_Tracking_Enemy_Freeze 59251 LD A,B Facing is 26 (frozen): negate both velocity components; test a 1-in-256 chance to promote the facing to 31 (thaw).
59252 NEG
59254 LD B,A
59255 LD A,C
59256 NEG
59258 LD C,A
59259 CALL Generate_Random_Byte
59262 CP 240
59264 JP NZ,Process_Player_Tracking_Enemy_Move
59267 LD (HL),31
Process_Player_Tracking_Enemy_Move 59269 INC HL Apply the Y nudge to the entity Y position; clamp to 16-173 and write back.
59270 LD A,C
59271 ADD A,(HL)
59272 CP 16
59274 JP C,Process_Player_Tracking_Enemy_Move_X
59277 CP 173
59279 JP NC,Process_Player_Tracking_Enemy_Move_X
59282 LD (HL),A
Process_Player_Tracking_Enemy_Move_X 59283 INC HL Apply the X nudge to the entity X position; clamp to 8-239 and write back.
59284 LD A,B
59285 ADD A,(HL)
59286 CP 8
59288 JP C,Process_Player_Tracking_Enemy_Draw
59291 CP 239
59293 JP NC,Process_Player_Tracking_Enemy_Draw
59296 LD (HL),A
Process_Player_Tracking_Enemy_Draw 59297 PUSH HL Stash HL, step back two bytes, set colour INK: CYAN, PAPER: BLACK (BRIGHT) in alternate B, draw the entity via Draw_Entity_Sprite, restore HL, and advance via Process_Cluster_Entity_Next.
59298 DEC HL
59299 DEC HL
59300 EXX
59301 LD B,69
59303 EXX
59304 CALL Draw_Entity_Sprite
59307 POP HL
59308 JP Process_Cluster_Entity_Next
Prev: 59076 Up: Map Next: 59311