1. Standards Algorithm
The movement mode is actually the way to control the movement of roles. For example, you can create a circle, square, snake-like, curve, and other types of pattern.
The standard movement mode algorithm uses control commands to indicate the role controlled by the computer and how to move in each round of game loop.
The following uses a snake-like movement mode as an example to describe:
The following is a set of control commands:
(Turn_right, turn_left, step_forward, step_backward)
(0, 0, 2, 0)
(0, 0, 2, 0)
(10, 0, 0, 0)
(10, 0, 0, 0)
(0, 0, 2, 0)
(0, 0, 2, 0)
(0, 10, 0, 0)
With the preceding control commands, the role can be moved in a snake-like manner only by repeatedly calling these commands in turn.
Prepare multiple modes and use them to make the role smarter.
2. Moving Mode in the brick Environment
For the brick environment, you can specify the relative positions (relative to the start point) of a series of points to be moved ).
For example, a square moving mode can be represented:
(10, 3, 18, 3)
(18, 3, 18, 12)
(18, 12, 10, 12)
(10, 12, 10, 3)
For these four points, we can get the four line segments to be moved, and then use the line of sight movement method in Chapter 2 to calculate the path of the four line segments, these paths can control the movement of roles. The book provides a detailed example of how bresenham is used to calculate the path of the Mobile mode. Code .
Sometimes it is expected that the movement of a role is more unpredictable. Taking the Square movement mode as an example, you can either move clockwise or counterclockwise, which is too easy for players to find and create an array, set all the positions that can be moved to 1, and the others to 0. In this way, each time you go to a position, you can select a position where you can go, in this way, you may turn around a few times clockwise. It can also be more precisely controlled. For example, the restriction can only be selected at the corner, or when the player role and the control role are in a straight line (the role may see the player role at this time ), move to the player role.
3. Simulate the movement mode in the physical environment
This part mainly deals with the simulation physical engine, such as the forward and moving speed and maximum speed, the rotation angle and the maximum angle, and so on, and the setting of the Mobile mode, consider the simulation environment. By analyzing the situation of the physical engine, several commands are provided to complete a mode, which is similar to the situation in section 1.