Prev: 42314 Up: Map Next: 42409
42319: Handler: Wandering Nastie
Handles the nastie types which wander about: the spider (sprite IDs 96 to 99), scorpion (100 to 103), parrot (108 to 111), monkey (112 to 115) and all of the nastie types which are only possible later in the game (152 to 159 and 176 to 195).
The nastie moves with a velocity chosen by ChooseVelocity, which also makes it pause for a while. It chooses a new velocity when the timer in IX+2 runs out or when it is blocked. It 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.
HandlerWanderingNastie 42319 LD A,(38659) Fetch the room of the player from 38659.
42322 CP (IX+1) Jump to ExpireActor if the nastie is in a different room to the player.
42325 JP NZ,ExpireActor
42328 LD A,23 Set the width of the nastie in Actor_Width to 23.
42330 LD (38573),A
42333 CALL StoreEntity Remember the previous position of the nastie.
Blow up the nastie if the player is not alive.
42336 LD A,(38658) Fetch the sprite ID of the player from ImmortalData.
42339 SUB 16 Subtract 16 (the first Sabreman sprite ID).
42341 CP 32 Jump to BlowUpActor to blow up the nastie if the player is not alive.
42343 JP NC,BlowUpActor
Choose a new velocity when the timer has run out.
42346 DEC (IX+2) Decrease the velocity timer by one and choose a new velocity if it has run out.
42349 CALL Z,ChooseVelocity
Skip the move if the nastie is not moving.
42352 LD A,(IX+6) Fetch the X velocity of the nastie.
42355 OR (IX+7) Combine it with the Y velocity.
42358 JR Z,HandlerWanderingNastie_Touch Jump to HandlerWanderingNastie_Touch if the nastie is not moving.
Move the nastie, bouncing it off the edges of the screen.
42360 CALL CalculateNewPosition Work out the new position of the nastie.
42363 BIT 0,B Jump to BounceWanderingNastieHorizontally if the nastie has hit the left or right edge of the screen.
42365 JR NZ,BounceWanderingNastieHorizontally
42367 BIT 1,B Jump to BounceWanderingNastieVertically if the nastie has hit the top or bottom edge of the screen.
42369 JR NZ,BounceWanderingNastieVertically
This entry point is used by the routines at BounceWanderingNastieHorizontally and BounceWanderingNastieVertically.
Stop the nastie moving through objects in the room. If it did not manage to move then choose a new velocity.
HandlerWanderingNastie_Move 42371 LD BC,5911 Set the height and width of the nastie in B and C to 23.
42374 CALL SlideActorPastObjects Stop the nastie passing through objects in the room.
42377 CALL TestPositionUnchanged Test whether the nastie has stayed where it was.
42380 CALL Z,ChooseVelocity Choose a new velocity if the nastie has stayed where it was.
Flip the animation frame and store the new position.
42383 LD A,(IX+0) Fetch the sprite ID of the nastie.
42386 XOR %00000001 Flip bit 0.
42388 LD (IX+0),A Set the new sprite ID of the nastie.
42391 LD (IX+3),E Set the X position of the nastie.
42394 LD (IX+4),D Set the Y position of the nastie.
Blow up the nastie if it touches the player, otherwise draw it.
HandlerWanderingNastie_Touch 42397 LD BC,4883 Set the reach used to test whether the nastie is touching the player in BC to 4883.
42400 CALL TestActorHurtingPlayer Test whether the nastie is touching the player.
42403 JP NC,DisplayActor Jump to DisplayActor to display the nastie if it is not touching the player.
42406 JP BlowUpActor Jump to BlowUpActor to blow up the nastie.
Prev: 42314 Up: Map Next: 42409