Prev: 43779 Up: Map Next: 44080
43863: Move Robot
Used by the routine at MoveRobotHorizontally.
Moves the robot in the direction that it is heading, by the number of steps that is in B. The robot can only turn when it is at the start of a cell: if a turn key is being pressed then the robot turns and carries on in the new direction. When the robot is blocked by something in the map then HandleObstacle deals with it.
Input
B Number of steps to take
IX Robot
MoveRobot 43863 CALL GetPosition Fetch the position of the robot.
43866 LD (38483),DE Keep the X position...
43870 LD (38485),HL ...and the Y position, so that the move can be undone.
43873 LD A,(IX+0) Fetch the type of the robot...
43876 RRCA ...and turn it into the direction that it is heading in.
43877 RRCA
43878 AND 3 Jump to move in direction zero (X decreasing)...
43880 JP Z,MoveRobot_Left
43883 DEC A ...or direction one (Y increasing)...
43884 JP Z,MoveRobot_Up
43887 DEC A ...or direction two (X increasing)...
43888 JP Z,MoveRobot_Right
Direction three (Y decreasing). The four sections that follow all work in the same way. When the robot is at the start of a cell, and a key to turn is being pressed, the robot is turned and the routine carries on with the section for the new direction. Otherwise the robot moves, and if it was blocked then HandleObstacle is called to deal with the obstacle. This is repeated until there are no more steps.
MoveRobot_Down 43891 LD A,L Jump if the robot is not at the start of a cell.
43892 AND A
43893 JR NZ,MoveRobot_DownStep
43895 LD A,(38437) Fetch the controls.
43898 BIT 1,A Jump if the key to turn left is pressed.
43900 JR NZ,MoveRobot_Down_TurnLeft
43902 BIT 0,A Jump if the key to turn right is pressed.
43904 JR NZ,MoveRobot_Down_TurnRight
MoveRobot_DownStep 43906 CALL MoveDown Move the robot down using MoveDown.
43909 CALL NZ,HandleObstacle Deal with the obstacle using HandleObstacle if it was blocked.
43912 LD A,B Loop back if there are steps left.
43913 AND A
43914 JR NZ,MoveRobot_Down
43916 JP MoveRobot_Store Jump to MoveRobot_Store.
MoveRobot_Down_TurnLeft 43919 CALL TurnRobotLeft Turn the robot left using TurnRobotLeft...
43922 RES 7,(IX+0) ...and show the sprite without flipping it.
43926 JR MoveRobot_Right Jump to carry on heading right.
MoveRobot_Down_TurnRight 43928 CALL TurnRobotRight Turn the robot right using TurnRobotRight...
43931 SET 7,(IX+0) ...and show the sprite flipped.
43935 JR MoveRobot_Left Jump to carry on heading left.
MoveRobot_Right 43937 LD A,E Jump if the robot is not at the start of a cell.
43938 AND A
43939 JR NZ,MoveRobot_RightStep
43941 LD A,(38437) Fetch the controls.
43944 BIT 1,A Jump if the key to turn left is pressed.
43946 JR NZ,MoveRobot_Right_TurnLeft
43948 BIT 0,A Jump if the key to turn right is pressed.
43950 JR NZ,MoveRobot_Right_TurnRight
MoveRobot_RightStep 43952 CALL MoveRight Move the robot right using MoveRight.
43955 CALL NZ,HandleObstacle Deal with the obstacle using HandleObstacle if it was blocked.
43958 LD A,B Loop back if there are steps left.
43959 AND A
43960 JR NZ,MoveRobot_Right
43962 SET 7,(IX+0) Show the sprite flipped.
43966 JP MoveRobot_Store Jump to MoveRobot_Store.
MoveRobot_Right_TurnLeft 43969 CALL TurnRobotLeft Turn the robot left using TurnRobotLeft...
43972 SET 7,(IX+0) ...and show the sprite flipped.
43976 JR MoveRobot_Up Jump to carry on heading up.
MoveRobot_Right_TurnRight 43978 CALL TurnRobotRight Turn the robot right using TurnRobotRight...
43981 SET 7,(IX+0) ...and show the sprite flipped.
43985 JR MoveRobot_Down Jump to carry on heading down.
MoveRobot_Up 43987 LD A,L Jump if the robot is not at the start of a cell.
43988 AND A
43989 JR NZ,MoveRobot_UpStep
43991 LD A,(38437) Fetch the controls.
43994 BIT 1,A Jump if the key to turn left is pressed.
43996 JR NZ,MoveRobot_Up_TurnLeft
43998 BIT 0,A Jump if the key to turn right is pressed.
44000 JR NZ,MoveRobot_Up_TurnRight
MoveRobot_UpStep 44002 CALL MoveUp Move the robot up using MoveUp.
44005 CALL NZ,HandleObstacle Deal with the obstacle using HandleObstacle if it was blocked.
44008 LD A,B Loop back if there are steps left.
44009 AND A
44010 JR NZ,MoveRobot_Up
44012 JP MoveRobot_Store Jump to MoveRobot_Store.
MoveRobot_Up_TurnLeft 44015 CALL TurnRobotLeft Turn the robot left using TurnRobotLeft...
44018 RES 7,(IX+0) ...and show the sprite without flipping it.
44022 JR MoveRobot_Left Jump to carry on heading left.
MoveRobot_Up_TurnRight 44024 CALL TurnRobotRight Turn the robot right using TurnRobotRight...
44027 SET 7,(IX+0) ...and show the sprite flipped.
44031 JR MoveRobot_Right Jump to carry on heading right.
MoveRobot_Left 44033 LD A,E Jump if the robot is not at the start of a cell.
44034 AND A
44035 JR NZ,MoveRobot_LeftStep
44037 LD A,(38437) Fetch the controls.
44040 BIT 1,A Jump if the key to turn left is pressed.
44042 JR NZ,MoveRobot_Left_TurnLeft
44044 BIT 0,A Jump if the key to turn right is pressed.
44046 JR NZ,MoveRobot_Left_TurnRight
MoveRobot_LeftStep 44048 CALL MoveLeft Move the robot left using MoveLeft.
44051 CALL NZ,HandleObstacle Deal with the obstacle using HandleObstacle if it was blocked.
44054 LD A,B Loop back if there are steps left.
44055 AND A
44056 JR NZ,MoveRobot_Left
MoveRobot_Store 44058 JP SetPosition Jump to SetPosition.
MoveRobot_Left_TurnLeft 44061 CALL TurnRobotLeft Turn the robot left using TurnRobotLeft...
44064 RES 7,(IX+0) ...and show the sprite without flipping it.
44068 JP MoveRobot_Down Jump to carry on heading down.
MoveRobot_Left_TurnRight 44071 CALL TurnRobotRight Turn the robot right using TurnRobotRight...
44074 RES 7,(IX+0) ...and show the sprite without flipping it.
44078 JR MoveRobot_Up Jump to carry on heading up.
Prev: 43779 Up: Map Next: 44080