Game Development Reference
In-Depth Information
Building keyboard controls
Let's get that kart moving! In the previous project, we learned how to control a game
using the mouse. In this secion, we will control the game using the keyboard .
Prepare for lift off
The controls for this game will be divided between the kart sprite and a separate control
sprite . The kart sprite will be atached to this control sprite. The kart sprite will only concern
itself with displaying a prety and logical image. It tells the player where the kart is on the
track and in which direcion it is facing. The control sprite will manage all things "under the
hood", such as movement speed and collision checks.
Separaing these two funcions allows us to have the imagery behave somewhat
independently from the game rules and mechanics. It allows more room for animaion
and special efects without hindering the coninuaion of the game. It also allows easy
replacement of the graphics altogether. One controller could "wear" different sprite
costumes at any given ime; for example, to represent a diferent character in the game.
Engage thrusters
Let's first create the control object. This is a sprite just like any other:
1.
Create a new sprite with the Paintbrush icon.
2.
Name the sprite player1 .
3.
Draw a small red circle with the Ellipse tool. Remember to hold Shift for
a perfect circle.
We'll write a script for the control sprite next:
1. Start with a when <green lag> clicked block.
2. Atach a set size to () % block. Fill in the value 20 to make the circle very small.
We should barely be able to see it, as long as the computer can sill check
collisions with it later.
 
Search WWH ::




Custom Search