Prev: B2CA Up: Map Next: B358
B2CF: Move Creature Horizontally
Moves a creature one step closer to Sabreman's room when it is in a different room x. It does not draw the creature. It is entered with the carry flag set if Sabreman's room x is less than the room x of the creature.
The creature is flagged so that it will be drawn without being erased when it arrives. It accelerates by two on each call in the direction of Sabreman's room, up to a speed of 30 and its x position changes by a sixteenth of the speed. When the x position goes past D0 (or below 18) it moves into the next room.
The y position is kept at 40 or more, and when it is 80 or more it moves up two pixels each time.
A creature cannot leave its room through a wall. If the wall is on the side that it is going to, it is removed when it is in the same room y as Sabreman, and otherwise Move_Creature_Vertically moves it up or down.
Input
IX Object record
E Flags of the room that the creature is in
Move_Creature_Horizontally B2CF LD (IX+$0F),$01 Set the redraw flags to 01 so that the creature is drawn without being erased when it arrives.
B2D3 LD (IX+$0B),$00 Clear the contact flags.
B2D7 JR C,Move_Creature_Horizontally_Move_Left Jump to Move_Creature_Horizontally_Move_Left if Sabreman is on the left of the creature.
B2D9 BIT 2,E Jump to Move_Creature_Horizontally_Blocked if the room has a right wall.
B2DB JR NZ,Move_Creature_Horizontally_Blocked
B2DD LD A,(IX+$08) Fetch the x velocity.
B2E0 ADD A,$02 Accelerate to the right by adding two.
B2E2 BIT 7,A Jump to Move_Creature_Horizontally_Store_Velocity if the x velocity is negative.
B2E4 JR NZ,Move_Creature_Horizontally_Store_Velocity
B2E6 CP $31 Jump to Move_Creature_Horizontally_Move_Right if the x velocity has reached 31.
B2E8 JR NC,Move_Creature_Horizontally_Move_Right
Move_Creature_Horizontally_Store_Velocity B2EA LD (IX+$08),A Store the x velocity.
Move_Creature_Horizontally_Move_Right B2ED LD A,(IX+$08) Fetch the x velocity.
B2F0 SRA A Divide it by sixteen, keeping the sign.
B2F2 SRA A
B2F4 SRA A
B2F6 SRA A
B2F8 ADD A,(IX+$01) Add the x position of the creature.
B2FB CP $D0 Jump to Move_Creature_Horizontally_Store_X if the x position is less than D0.
B2FD JR C,Move_Creature_Horizontally_Store_X
B2FF INC (IX+$02) Move the creature to the room on the right.
B302 LD A,$08 Set the x position to 08.
Move_Creature_Horizontally_Store_X B304 LD (IX+$01),A Store the x position.
Keep the y position between 40 and 80 and make it drift upwards when it is 80 or more.
Move_Creature_Horizontally_Adjust_Y B307 LD A,(IX+$03) Fetch the y position.
B30A CP $40 Jump to Move_Creature_Horizontally_Drift_Up if the y position is 40 or more.
B30C JR NC,Move_Creature_Horizontally_Drift_Up
B30E LD (IX+$03),$40 Set the y position to 40.
Move_Creature_Horizontally_Drift_Up B312 CP $80 Return if the y position is less than 80.
B314 RET C
B315 SUB $02 Subtract two.
B317 LD (IX+$03),A Store the y position.
B31A RET Return.
Sabreman is on the left of the creature.
Move_Creature_Horizontally_Move_Left B31B BIT 6,E Jump to Move_Creature_Horizontally_Blocked if the room has a left wall.
B31D JR NZ,Move_Creature_Horizontally_Blocked
B31F LD A,(IX+$08) Fetch the x velocity.
B322 SUB $02 Accelerate to the left by subtracting two.
B324 BIT 7,A Jump to Move_Creature_Horizontally_Store_Left_Velocity if the x velocity is positive.
B326 JR Z,Move_Creature_Horizontally_Store_Left_Velocity
B328 CP $D0 Jump to Move_Creature_Horizontally_Add_Left_Velocity if the x velocity is less than D0.
B32A JR C,Move_Creature_Horizontally_Add_Left_Velocity
Move_Creature_Horizontally_Store_Left_Velocity B32C LD (IX+$08),A Store the x velocity.
Move_Creature_Horizontally_Add_Left_Velocity B32F LD A,(IX+$08) Fetch the x velocity.
B332 SRA A Divide it by sixteen, keeping the sign.
B334 SRA A
B336 SRA A
B338 SRA A
B33A ADD A,(IX+$01) Add the x position of the creature.
B33D CP $18 Jump to Move_Creature_Horizontally_Store_Left_X if the x position is 18 or more.
B33F JR NC,Move_Creature_Horizontally_Store_Left_X
B341 DEC (IX+$02) Move the creature to the room on the left.
B344 LD A,$DF Set the x position to DF.
Move_Creature_Horizontally_Store_Left_X B346 LD (IX+$01),A Store the x position.
B349 JR Move_Creature_Horizontally_Adjust_Y Jump to Move_Creature_Horizontally_Adjust_Y.
The creature cannot go that way.
Move_Creature_Horizontally_Blocked B34B LD A,($8F1E) Fetch the room y of Sabreman.
B34E CP (IX+$04) Jump to Move_Creature_Vertically if the creature is in a different room y.
B351 JR NZ,Move_Creature_Vertically
This entry point is used by the routine at Move_Creature_Vertically.
Move_Creature_Horizontally_Remove_Creature B353 LD (IX+$00),$00 Remove the creature.
B357 RET Return.
Prev: B2CA Up: Map Next: B358