Prev: 81F0 Up: Map Next: 8283
8209: Handle Weapon
Used by the routines at HandlerAxe and HandlerSword.
The movement code that is shared by the axe, the fireball and the sword. The weapon is removed if the player has left the room, if its lifetime (held in EAA7) has run out, or if it has hit something (bit 0 of the flags is set). Otherwise it moves by its velocity, bouncing off the walls of the room by reversing the velocity on the axis that was crossed.
Input
IX The weapon entity
Remove the weapon if the player is not in the same room.
HandlerWeapon 8209 LD DE,($5E1D) DE=*CurrentRoom_Width (E is the width of the room and D is the height).
820D LD A,($EA91) Fetch the room of the player.
8210 CP (IX+$01) Jump to HandlerWeapon_Remove if the weapon is not in the same room as the player.
8213 JR NZ,HandlerWeapon_Remove
Remove the weapon if it has run out of time, or it has hit something.
8215 DEC (IX+$0F) Decrease the lifetime of the weapon by one and jump to HandlerWeapon_Expire if it is zero.
8218 JR Z,HandlerWeapon_Expire
821A BIT 0,(IX+$02) Jump to HandlerWeapon_Expire if bit 0 of the flags of the weapon is set.
821E JR NZ,HandlerWeapon_Expire
Work out the new X position of the weapon and check it is inside the room.
8220 LD A,(IX+$03) Fetch the X position of the weapon.
8223 ADD A,(IX+$06) Add the X velocity of the weapon.
8226 LD C,A Keep the new X position in C.
8227 SUB $58 Subtract 58 (the centre of the room).
8229 JP P,HandlerWeapon_CheckX Jump to HandlerWeapon_CheckX if the result is positive, otherwise make it positive.
822C NEG
HandlerWeapon_CheckX 822E CP E Jump to HandlerWeapon_BounceX if the weapon has crossed the left or right wall of the room.
822F JR NC,HandlerWeapon_BounceX
Work out the new Y position of the weapon and check it is inside the room.
HandlerWeapon_CheckY 8231 LD A,(IX+$04) Fetch the Y position of the weapon.
8234 ADD A,(IX+$07) Add the Y velocity of the weapon.
8237 LD B,A Keep the new Y position in B.
8238 SUB $68 Subtract 68 (the centre of the room).
823A JP P,HandlerWeapon_CheckYLimit Jump to HandlerWeapon_CheckYLimit if the result is positive, otherwise make it positive.
823D NEG
HandlerWeapon_CheckYLimit 823F CP D Jump to HandlerWeapon_BounceY if the weapon has crossed the top or bottom wall of the room.
8240 JR NC,HandlerWeapon_BounceY
Move the weapon to its new position, and display it.
HandlerWeapon_Move 8242 LD (IX+$03),C Update the X position of the weapon.
8245 LD (IX+$04),B Update the Y position of the weapon.
8248 JP HandlerCharacter_Display Jump to HandlerCharacter_Display to display the weapon.
The weapon has hit the top or bottom wall, so bounce it back.
HandlerWeapon_BounceY 824B LD B,(IX+$04) Keep the current Y position in B.
824E LD A,(IX+$07) Fetch the Y velocity of the weapon.
8251 NEG Reverse the direction of the Y velocity.
8253 LD (IX+$07),A Update the Y velocity of the weapon.
8256 PUSH BC Stash the position on the stack.
8257 CALL SoundsBounce Call SoundsBounce to make the bounce sound.
825A POP BC Restore the position from the stack.
825B JR HandlerWeapon_Move Jump to HandlerWeapon_Move to move the weapon to its new position.
The weapon has hit the left or right wall, so bounce it back.
HandlerWeapon_BounceX 825D LD C,(IX+$03) Keep the current X position in C.
8260 LD A,(IX+$06) Fetch the X velocity of the weapon.
8263 NEG Reverse the direction of the X velocity.
8265 LD (IX+$06),A Update the X velocity of the weapon.
8268 PUSH BC Stash the position on the stack.
8269 CALL SoundsBounce Call SoundsBounce to make the bounce sound.
826C POP BC Restore the position from the stack.
826D JR HandlerWeapon_CheckY Jump to HandlerWeapon_CheckY to check the new Y position of the weapon.
This entry point is used by the routine at HandlerPop.
The weapon has finished, so remove it from the screen and restore the colour of the room.
HandlerWeapon_Expire 826F CALL RemoveEntity Call RemoveEntity to remove the weapon from the screen.
8272 CALL SoundsWeaponPop Call SoundsWeaponPop to make the pop sound.
8275 LD A,($5E1A) Fetch the room attribute.
8278 LD (IX+$05),A Set the attribute of the weapon to the room attribute.
827B CALL SetEntityAttributes_Moved Call SetEntityAttributes_Moved to set the attributes of the cells that the weapon covered.
This entry point is used by the routine at CountDownCreature.
The weapon is no longer in use.
HandlerWeapon_Remove 827E LD (IX+$00),$00 Clear the sprite ID of the weapon, which means it is no longer in use.
8282 RET Return.
Prev: 81F0 Up: Map Next: 8283