Prev: 35547 Up: Map Next: 35690
35583: Handle Hunchback
The handler for the hunchback (sprite IDs 156 to 159). If he touches the player then TakeEnergyFromPlayer takes some energy. The velocities are set by SteerCreature, as the hunchback goes for the first item that is in his room (see FindItemInRoom). When he reaches it the item is removed. If there is nothing to go for he stays still, and if the player is not a character then he heads for a position in the room. The movement itself is done by MoveCreature.
Input
IX The hunchback entity
HandlerHunchback 35583 CALL StoreEntity Call StoreEntity to save the position of the hunchback.
35586 CALL CheckPlayerTouch Call CheckPlayerTouch to check whether the entity is touching the player.
35589 DEC E Call TakeEnergyFromPlayer if the hunchback touched the player.
35590 CALL Z,TakeEnergyFromPlayer
35593 XOR A A=0 (no velocity).
35594 LD (IX+9),A Set the Y velocity to zero.
35597 LD (IX+8),A Set the X velocity to zero.
35600 CALL FindItemInRoom Call FindItemInRoom to look for an item.
35603 DEC C Jump to HandlerHunchback_Move if there is no item.
35604 JP NZ,HandlerHunchback_Move
35607 CALL SteerCreature Call SteerCreature to head for the item.
35610 LD A,C Fetch which of the axes have been reached.
35611 CP 3 Jump to HandlerHunchback_SetSprite if the hunchback has not arrived.
35613 JR NZ,HandlerHunchback_SetSprite
The hunchback is at the item, so remove it.
35615 CALL FindItemInRoom Call FindItemInRoom to find the item again.
35618 LD DE,4 DE=0004 (the offset of the Y position within a record).
35621 AND A Reset the carry flag.
35622 SBC HL,DE Subtract DE from HL to get the address of the item.
35624 PUSH IX Stash the hunchback on the stack.
35626 LD IX,0 Make IX point at the item (copy HL to IX).
35630 EX DE,HL
35631 ADD IX,DE
35633 LD A,(60049) Fetch the room of the player from PlayerRoom.
35636 CP (IX+1) Compare it with the room of the item.
35639 JR NZ,HandlerHunchback_Remove Jump to HandlerHunchback_Remove if they are different.
35641 CALL DrawEntity Call DrawEntity to draw the item.
HandlerHunchback_Remove 35644 LD (IX+0),0 Write 0 to the sprite ID of the item.
35648 POP IX Restore the hunchback from the stack.
35650 JP HandlerHunchback_Move Jump to HandlerHunchback_Move to move the hunchback.
The hunchback is on the way, so choose the sprite.
HandlerHunchback_SetSprite 35653 LD A,(IX+0) Fetch the sprite ID of the hunchback.
35656 AND %11111100 Keep only bits 2-7.
35658 LD C,A Keep the base sprite ID in C.
35659 LD A,(24082) Fetch the counter from CounterLow.
35662 RRA Divide the counter by four.
35663 RRA
35664 AND %00000011 Keep only bits 0-1.
35666 ADD A,C Add the animation frame to the base sprite ID.
35667 LD (IX+0),A Update the sprite ID of the hunchback.
35670 LD DE,15420 DE=15420 (the area).
If the player is a character then the hunchback moves, otherwise he heads for a position in the room.
HandlerHunchback_Move 35673 LD A,(60048) Fetch the sprite ID of the player from Player.
35676 CP 49 Jump to MoveCreature if the player is a character.
35678 JP C,MoveCreature
35681 LD DE,14936 DE=14936 (the target position).
35684 CALL SteerCreature Call SteerCreature to steer the creature towards its target.
35687 JP MoveCreature Jump to MoveCreature to move the creature.
Prev: 35547 Up: Map Next: 35690