Menu
IDS - Rotation
Rotation & Forward
![Picture](/uploads/5/2/3/9/5239496/asteroids_orig.png)
Not all games use 4 directional buttons to move the character up/down/left/right.
Many games (including first-person-shooter games) require controls for rotation and moving forward. In the game asteroids (shown left), two buttons allow the ship to rotate clockwise and counter-clockwise, and one button allows it to thrust forward.
Many games (including first-person-shooter games) require controls for rotation and moving forward. In the game asteroids (shown left), two buttons allow the ship to rotate clockwise and counter-clockwise, and one button allows it to thrust forward.
On Start |
In previous examples we needed to store the current location and the vector of movement for each character.
However, if we are to control the rotation of a character on screen, we also need to keep track of the current angle of rotation. If the ship has multiple parts, then that may be stored as a separate coordinate. In this case, the nose is just the ships location plus the direction it faces. |
Forever |
The basic concept of the forever loop will
The only significant difference here is that we are also adjusting the nose of the ship. Notice that when we display the nose, we use a lower brightness value. |
On Thrust
When the thrust button is pressed, you want the direction of movement to be the same as the direction that the ship is facing.
|
On Rotate |
When the rotate button is pressed, you want to Increase the rotational angle first. In a game that only allows 4 angles (north, east, south, west) then the values can range from 0 to 3. If the value is greater than 3, then we reset it to zero.
If the game allows for rotation to a 45 degree angle, then there are 8 angles which range from 0 to 7. If the value of the angle is greater than 7, then we reset it to zero. Once the angle is established, we adjust the direction that the object is facing, depending on what the angle value is. If the direction = 1, then make the nose face UP... You will need to do this for each possible angle. For a game that allows 360 degree rotation, we need to use a different method involving trigonometry. |