Prev: A4C3 Up: Map Next: A545
A4D7: Handler: Chasing Nastie
Handles the nastie types which chase the player: the bat (sprite IDs 68 to 6B), the lizard (74 to 77) and the snake (78 to 7B). Every time they are handled the velocity of the nastie is changed by 08 towards the position of the player, up to a maximum of 30 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 A4D7 LD A,($9703) Fetch the room of the player from 9703.
A4DA CP (IX+$01) Jump to ExpireActor if the nastie is in a different room to the player.
A4DD JR NZ,ExpireActor
A4DF LD A,$17 Set the width of the nastie in Actor_Width to 17.
A4E1 LD ($96AD),A
A4E4 CALL StoreEntity Remember the previous position of the nastie.
Blow up the nastie if the player is not alive.
A4E7 LD A,($9702) Fetch the sprite ID of the player from ImmortalData.
A4EA SUB $10 Subtract 10 (the first Sabreman sprite ID).
A4EC CP $20 Jump to BlowUpActor to blow up the nastie if the player is not alive.
A4EE JR NC,BlowUpActor
A4F0 LD BC,$3008 Set the maximum velocity in B to 30 and the amount to change the velocity by in C to 08.
Change the X velocity towards the player.
A4F3 LD A,($9705) Fetch the X position of the player from 9705.
A4F6 SUB (IX+$03) Subtract the X position of the nastie.
A4F9 JR Z,HandlerChasingNastie_StoreX Jump to HandlerChasingNastie_StoreX if the positions are the same, with a velocity of zero.
A4FB LD A,C Fetch the amount to change the velocity by.
A4FC JR NC,HandlerChasingNastie_AddX Jump to HandlerChasingNastie_AddX if the player is to the right of the nastie.
A4FE NEG Negate the amount to change the velocity by.
HandlerChasingNastie_AddX A500 ADD A,(IX+$06) Add the X velocity of the nastie.
A503 CALL LimitVelocity Limit the X velocity.
HandlerChasingNastie_StoreX A506 LD (IX+$06),A Set the X velocity of the nastie.
Change the Y velocity towards the player.
A509 LD A,($9706) Fetch the Y position of the player from 9706.
A50C CP (IX+$04) Compare with the Y position of the nastie.
A50F 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).
A511 LD A,C Fetch the amount to change the velocity by.
A512 JR NC,HandlerChasingNastie_AddY Jump to HandlerChasingNastie_AddY if the player is below the nastie.
A514 NEG Negate the amount to change the velocity by.
HandlerChasingNastie_AddY A516 ADD A,(IX+$07) Add the Y velocity of the nastie.
A519 CALL LimitVelocity Limit the Y velocity.
HandlerChasingNastie_StoreY A51C LD (IX+$07),A Set the Y velocity of the nastie.
Move the nastie, bouncing it off the edges of the screen.
A51F CALL FaceDirection Make the nastie face the way it is moving.
A522 CALL CalculateNewPosition Work out the new position of the nastie.
A525 BIT 0,B Jump to BounceNastieHorizontally if the nastie has hit the left or right edge of the screen.
A527 JR NZ,BounceNastieHorizontally
A529 BIT 1,B Jump to BounceNastieVertically if the nastie has hit the top or bottom edge of the screen.
A52B 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 A52D LD BC,$1717 Set the height and width of the nastie in B and C to 17.
A530 CALL SlideActorPastObjects Stop the nastie passing through objects in the room.
A533 LD (IX+$03),E Set the X position of the nastie.
A536 LD (IX+$04),D Set the Y position of the nastie.
Blow up the nastie if it touches the player, otherwise draw it.
A539 LD BC,$1313 Set the reach used to test whether the nastie is touching the player in BC to 1313.
A53C CALL TestActorHurtingPlayer Test whether the nastie is touching the player.
A53F JP NC,DisplayActor Jump to DisplayActor to display the nastie if it is not touching the player.
A542 JP BlowUpActor Jump to BlowUpActor to blow up the nastie.
Prev: A4C3 Up: Map Next: A545