image Tutorial on Rotating Objects

There are two types of rotation. The first is the object rotating its own angle. The second type is an object rotating around another object. For the first type, we need to use an embedded variable attribute for the objects, which is angle. For the second type, the action is termed revolve. Consider the following example:

There is a rabbit and 5 pearls.
You control the rabbit.
When the left arrow is pressed, the angle of the rabbit decreases.
When the right arrow is pressed, the angle of the rabbit increases.
When the up arrow is pressed, the rabbit moves forward.
When the space bar is pressed, the rabbit shoots up.

The pearls revolve around the rabbit.

In addition, the direction forward will move the object along the trajectory of its angle. Likewise, shooting will also aim at the same angle.

What do the pearls do? What is 'revolve'?

Finally, non-player characters can point to another character. For example:

There is a rabbit controlled with the mouse.
There are 5 pointers and 5 diamonds.
When the pointer sees the rabbit, it points to the rabbit.
The diamonds chase the rabbit.
When a diamond is not dead, it points to the rabbit.


Try it yourself: If we change two of the sentences above to the following, what would happen?

When the left arrow is pressed, the angle of the rabbit decreases by 5.
When the right arrow is pressed, the angle of the rabbit increases by 5.


Complete Sample Games for Rotations

// Game #1. Pick Rabbits.

There are 5 rabbits and 6 diamonds.
There is a pearl controlled by the mouse.
The pearl is invisible.
When a rabbit that is not yellow is clicked, it becomes yellow.
When a rabbit is yellow, the position_x of the rabbit equals the position_x of the pearl and the position_y of the rabbit equals the position_y of the pearl.
When a yellow rabbit is clicked, it returns to original color.
When a rabbit is yellow, the angle of the rabbit increases.
When a diamond sees the yellow rabbit, it revolves around the rabbit.

// Game #2. Rabbit Dash.

Wide canvas with 5 frames.
There is a rabbit.
You control the rabbit.
The s1 of the rabbit is initially 1.

When space bar is pressed, the rabbit jumps.
When space bar is pressed, the rabbit becomes empowered.
When the rabbit is empowered, it becomes xyz.
When the rabbit is xyz, the angle of the rabbit increases by 1.2.
When the xyz rabbit lands on the wall, it becomes not xyz and the s1 of the rabbit increases.
When the s1 of the rabbit is greater than 3, the s1 of the rabbit becomes 0.
When the rabbit whose s1 equals 0 lands on a wall, the angle of the rabbit equals 0.
When the rabbit whose s1 equals 1 lands on a wall, the angle of the rabbit equals 90.
When the rabbit whose s1 equals 2 lands on a wall, the angle of the rabbit equals 180.
When the rabbit whose s1 equals 3 lands on a wall, the angle of the rabbit equals 270.
The walls move left at 4 pixels per frame.
The carrots move left at 4 pixels per frame.

When the rabbit touches a carrot, you win.
When the rabbit collides with a wall, game over.
When the rabbit touches a border, game over.


Map:

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-r--------w
wwwwwwwwwwwwwww---wwwwwwww---wwwwww---wwwww---wwwww---www---cccccccc


Next page

Tutorials Home