Prev: 814B Up: Map Next: 81DB
817C: Set Weapon Velocity
Used by the routines at ThrowAxe, ThrowFireball and ThrowSword.
Gets a weapon ready to be launched. The lifetime of the weapon is set to 30 and its flags are cleared. The velocity is 04 pixels per frame in the direction that the player is moving, or if the player is standing still then in the direction that the player is facing.
Input
IX The player entity
Reset the weapon.
SetWeaponVelocity 817C LD HL,$EA9E Point HL at the X velocity of the weapon at PlayerWeapon_X_Velocity.
817F LD A,$30 Write 30 to EAA7 (the lifetime of the weapon).
8181 LD ($EAA7),A
8184 LD A,$00 Write 00 to EA9A (the flags of the weapon).
8186 LD ($EA9A),A
If the player is moving then the weapon follows the direction of the movement.
8189 LD A,(IX+$06) Fetch the X velocity of the player.
818C OR (IX+$07) Jump to SetWeaponVelocity_Facing if the player is not moving.
818F JR Z,SetWeaponVelocity_Facing
8191 LD A,(IX+$06) Fetch the X velocity of the player.
8194 AND A Jump to SetWeaponVelocity_StoreX if the player is not moving horizontally.
8195 JR Z,SetWeaponVelocity_StoreX
8197 JP M,SetWeaponVelocity_Left Jump to SetWeaponVelocity_Left if the player is moving left.
819A LD A,$04 A=04 (the velocity for moving right).
819C JR SetWeaponVelocity_StoreX Jump to SetWeaponVelocity_StoreX to store the X velocity of the weapon.
SetWeaponVelocity_Left 819E LD A,$FC A=FC (-04 the velocity for moving left).
SetWeaponVelocity_StoreX 81A0 LD (HL),A Update the X velocity of the weapon.
81A1 INC HL Move HL on to the Y velocity of the weapon.
81A2 LD A,(IX+$07) Fetch the Y velocity of the player.
81A5 AND A Jump to SetWeaponVelocity_StoreY if the player is not moving vertically.
81A6 JR Z,SetWeaponVelocity_StoreY
81A8 JP M,SetWeaponVelocity_Up Jump to SetWeaponVelocity_Up if the player is moving up.
81AB LD A,$04 A=04 (the velocity for moving down).
81AD JR SetWeaponVelocity_StoreY Jump to SetWeaponVelocity_StoreY to store the Y velocity of the weapon.
SetWeaponVelocity_Up 81AF LD A,$FC A=FC (-04 the velocity for moving up).
SetWeaponVelocity_StoreY 81B1 LD (HL),A Update the Y velocity of the weapon.
81B2 RET Return.
The player is standing still, so use the direction that the sprite is facing.
SetWeaponVelocity_Facing 81B3 LD A,(IX+$00) Fetch the sprite ID of the player.
81B6 DEC A Decrease A by one.
81B7 AND %00001100 Keep only bits 2-3, which is the direction.
81B9 JR Z,SetWeaponVelocity_FacingLeft Jump to SetWeaponVelocity_FacingLeft if the player is facing left.
81BB CP $04 Jump to SetWeaponVelocity_FacingRight if the player is facing right.
81BD JR Z,SetWeaponVelocity_FacingRight
81BF CP $08 Jump to SetWeaponVelocity_FacingDown if the player is not facing up.
81C1 JR NZ,SetWeaponVelocity_FacingDown
81C3 LD (HL),$00 Write 00 to the X velocity of the weapon.
81C5 INC HL Move HL on to the Y velocity of the weapon.
81C6 LD (HL),$FC Write FC (-04) to the Y velocity of the weapon.
81C8 RET Return.
SetWeaponVelocity_FacingLeft 81C9 LD (HL),$FC Write FC (-04) to the X velocity of the weapon.
81CB INC HL Move HL on to the Y velocity of the weapon.
81CC LD (HL),$00 Write 00 to the Y velocity of the weapon.
81CE RET Return.
SetWeaponVelocity_FacingRight 81CF LD (HL),$04 Write 04 to the X velocity of the weapon.
81D1 INC HL Move HL on to the Y velocity of the weapon.
81D2 LD (HL),$00 Write 00 to the Y velocity of the weapon.
81D4 RET Return.
SetWeaponVelocity_FacingDown 81D5 LD (HL),$00 Write 00 to the X velocity of the weapon.
81D7 INC HL Move HL on to the Y velocity of the weapon.
81D8 LD (HL),$04 Write 04 to the Y velocity of the weapon.
81DA RET Return.
Prev: 814B Up: Map Next: 81DB