Prev: 33264 Up: Map Next: 33411
33289: 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 60071) 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 33289 LD DE,(24093) DE=*CurrentRoom_Width (E is the width of the room and D is the height).
33293 LD A,(60049) Fetch the room of the player.
33296 CP (IX+1) Jump to HandlerWeapon_Remove if the weapon is not in the same room as the player.
33299 JR NZ,HandlerWeapon_Remove
Remove the weapon if it has run out of time, or it has hit something.
33301 DEC (IX+15) Decrease the lifetime of the weapon by one and jump to HandlerWeapon_Expire if it is zero.
33304 JR Z,HandlerWeapon_Expire
33306 BIT 0,(IX+2) Jump to HandlerWeapon_Expire if bit 0 of the flags of the weapon is set.
33310 JR NZ,HandlerWeapon_Expire
Work out the new X position of the weapon and check it is inside the room.
33312 LD A,(IX+3) Fetch the X position of the weapon.
33315 ADD A,(IX+6) Add the X velocity of the weapon.
33318 LD C,A Keep the new X position in C.
33319 SUB 88 Subtract 88 (the centre of the room).
33321 JP P,HandlerWeapon_CheckX Jump to HandlerWeapon_CheckX if the result is positive, otherwise make it positive.
33324 NEG
HandlerWeapon_CheckX 33326 CP E Jump to HandlerWeapon_BounceX if the weapon has crossed the left or right wall of the room.
33327 JR NC,HandlerWeapon_BounceX
Work out the new Y position of the weapon and check it is inside the room.
HandlerWeapon_CheckY 33329 LD A,(IX+4) Fetch the Y position of the weapon.
33332 ADD A,(IX+7) Add the Y velocity of the weapon.
33335 LD B,A Keep the new Y position in B.
33336 SUB 104 Subtract 104 (the centre of the room).
33338 JP P,HandlerWeapon_CheckYLimit Jump to HandlerWeapon_CheckYLimit if the result is positive, otherwise make it positive.
33341 NEG
HandlerWeapon_CheckYLimit 33343 CP D Jump to HandlerWeapon_BounceY if the weapon has crossed the top or bottom wall of the room.
33344 JR NC,HandlerWeapon_BounceY
Move the weapon to its new position, and display it.
HandlerWeapon_Move 33346 LD (IX+3),C Update the X position of the weapon.
33349 LD (IX+4),B Update the Y position of the weapon.
33352 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 33355 LD B,(IX+4) Keep the current Y position in B.
33358 LD A,(IX+7) Fetch the Y velocity of the weapon.
33361 NEG Reverse the direction of the Y velocity.
33363 LD (IX+7),A Update the Y velocity of the weapon.
33366 PUSH BC Stash the position on the stack.
33367 CALL SoundsBounce Call SoundsBounce to make the bounce sound.
33370 POP BC Restore the position from the stack.
33371 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 33373 LD C,(IX+3) Keep the current X position in C.
33376 LD A,(IX+6) Fetch the X velocity of the weapon.
33379 NEG Reverse the direction of the X velocity.
33381 LD (IX+6),A Update the X velocity of the weapon.
33384 PUSH BC Stash the position on the stack.
33385 CALL SoundsBounce Call SoundsBounce to make the bounce sound.
33388 POP BC Restore the position from the stack.
33389 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 33391 CALL RemoveEntity Call RemoveEntity to remove the weapon from the screen.
33394 CALL SoundsWeaponPop Call SoundsWeaponPop to make the pop sound.
33397 LD A,(24090) Fetch the room attribute.
33400 LD (IX+5),A Set the attribute of the weapon to the room attribute.
33403 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 33406 LD (IX+0),0 Clear the sprite ID of the weapon, which means it is no longer in use.
33410 RET Return.
Prev: 33264 Up: Map Next: 33411