Prev: 42179 Up: Map Next: 42309
42199: Handler: Chasing Nastie
Handles the nastie types which chase the player: the bat (sprite IDs 104 to 107), the lizard (116 to 119) and the snake (120 to 123). Every time they are handled the velocity of the nastie is changed by 8 towards the position of the player, up to a maximum of 48 in each direction (see LimitVelocity).
The nastie bounces off the edges of the screen, is stopped by objects in the room, and is blown up (by BlowUpActor) if it touches the player or if the player is not alive.
Input
IX Nastie record
Count off the nastie if it is not in the same room as the player.
HandlerChasingNastie 42199 LD A,(38659) Fetch the room of the player from 38659.
42202 CP (IX+1) Jump to ExpireActor if the nastie is in a different room to the player.
42205 JR NZ,ExpireActor
42207 LD A,23 Set the width of the nastie in Actor_Width to 23.
42209 LD (38573),A
42212 CALL StoreEntity Remember the previous position of the nastie.
Blow up the nastie if the player is not alive.
42215 LD A,(38658) Fetch the sprite ID of the player from ImmortalData.
42218 SUB 16 Subtract 16 (the first Sabreman sprite ID).
42220 CP 32 Jump to BlowUpActor to blow up the nastie if the player is not alive.
42222 JR NC,BlowUpActor
42224 LD BC,12296 Set the maximum velocity in B to 48 and the amount to change the velocity by in C to 8.
Change the X velocity towards the player.
42227 LD A,(38661) Fetch the X position of the player from 38661.
42230 SUB (IX+3) Subtract the X position of the nastie.
42233 JR Z,HandlerChasingNastie_StoreX Jump to HandlerChasingNastie_StoreX if the positions are the same, with a velocity of zero.
42235 LD A,C Fetch the amount to change the velocity by.
42236 JR NC,HandlerChasingNastie_AddX Jump to HandlerChasingNastie_AddX if the player is to the right of the nastie.
42238 NEG Negate the amount to change the velocity by.
HandlerChasingNastie_AddX 42240 ADD A,(IX+6) Add the X velocity of the nastie.
42243 CALL LimitVelocity Limit the X velocity.
HandlerChasingNastie_StoreX 42246 LD (IX+6),A Set the X velocity of the nastie.
Change the Y velocity towards the player.
42249 LD A,(38662) Fetch the Y position of the player from 38662.
42252 CP (IX+4) Compare with the Y position of the nastie.
42255 JR Z,HandlerChasingNastie_StoreY Jump to HandlerChasingNastie_StoreY if the positions are the same (A still holds the Y position of the player at this point, and this is what is used as the Y velocity).
42257 LD A,C Fetch the amount to change the velocity by.
42258 JR NC,HandlerChasingNastie_AddY Jump to HandlerChasingNastie_AddY if the player is below the nastie.
42260 NEG Negate the amount to change the velocity by.
HandlerChasingNastie_AddY 42262 ADD A,(IX+7) Add the Y velocity of the nastie.
42265 CALL LimitVelocity Limit the Y velocity.
HandlerChasingNastie_StoreY 42268 LD (IX+7),A Set the Y velocity of the nastie.
Move the nastie, bouncing it off the edges of the screen.
42271 CALL FaceDirection Make the nastie face the way it is moving.
42274 CALL CalculateNewPosition Work out the new position of the nastie.
42277 BIT 0,B Jump to BounceNastieHorizontally if the nastie has hit the left or right edge of the screen.
42279 JR NZ,BounceNastieHorizontally
42281 BIT 1,B Jump to BounceNastieVertically if the nastie has hit the top or bottom edge of the screen.
42283 JR NZ,BounceNastieVertically
This entry point is used by the routines at BounceNastieHorizontally and BounceNastieVertically.
Stop the nastie moving through objects in the room.
HandlerChasingNastie_Move 42285 LD BC,5911 Set the height and width of the nastie in B and C to 23.
42288 CALL SlideActorPastObjects Stop the nastie passing through objects in the room.
42291 LD (IX+3),E Set the X position of the nastie.
42294 LD (IX+4),D Set the Y position of the nastie.
Blow up the nastie if it touches the player, otherwise draw it.
42297 LD BC,4883 Set the reach used to test whether the nastie is touching the player in BC to 4883.
42300 CALL TestActorHurtingPlayer Test whether the nastie is touching the player.
42303 JP NC,DisplayActor Jump to DisplayActor to display the nastie if it is not touching the player.
42306 JP BlowUpActor Jump to BlowUpActor to blow up the nastie.
Prev: 42179 Up: Map Next: 42309