HORIZONTAL MOTION
The player should be able to move at least in three ways: forward,
backward, and turning. The player's position is defined by a coordinate
and a viewing angle. To allow motion, two more attributes are needed.
They are the player's movement speed, and the player's turning
speed. The player's movement speed defines how many units the player
should move when he/she is moving forward or backward. The player's
turning speed (measured in angle) defines how many angle to be added
or subtracted when the player is turning. We will discuss each how we
use these attributes to allow motion.
A. Moving forward and backward.
We define the player's movement speed to be 10 units. (Generally,
this can be any number, but the larger number, the less smooth the movement
will appear.) The process of finding the x and y displacement is illustrated
below. If the player is moving forward, we add the XDisplacement to
the current player's X coordinate; and add Ydisplacement to the current
player's Y coordinate. If the player is moving backward, we subtract
the XDisplacement to the current player's X coordinate; and subtract
Ydisplacement to the current player's Y coordinate. (Always check for
world/wall boundaries so that the player won't go outside the map or
walk through a wall.)
Figure 31: Finding the displacement based
on player's speed (in this case, the player's speed in 10 units).
B. Turning.
The process of turning is very simple to implement. All we need
to do is to add or subtract an angle increment (aI) to the current
player's viewing angle (wrap around whenever the turn goes to a full
circle). Again, larger angle increment will cause the movement appear
less smooth.
Figure 32.
|