Most games are designed to be interactive. This means that the player must have some way to control what happens during the game. In the last chapter, you wrote code that displayed the robot and moved him across the screen. Now, you will control the robot!
This chapter will explain how to implement an input system to control the game's character, and interact with the game. Topics will include:
It's likely that at some point in your life, you have been part of a conversation that seemed one-sided. The other party was talking and talking, and it didn't seem you could get a word in. After a while, such a conversation becomes quite boring!
The same would happen with a computer game that didn't allow any input. Input is a set of techniques that allows you to control the game. There are many ways to implement an input system, and we will cover them here.
The most common form of input for most computers is the keyboard. Obviously, the keyboard can be used to enter text, but the keyboard can also be used to directly control the game.
Some examples of this include the following:
These are just a few examples. In fact, there are some games that seem to use every key on the keyboard!
The mouse has been around for a long time, so it makes sense that the mouse is used in many games. The mouse can be used in several ways:
More and more devices now respond to touch. Many input systems treat touch very similarly to the mouse:
However, there are many features of touch that cannot be easily equated to the mouse. For example, most touch interfaces allow several touches to be handled simultaneously. This feature is known as multitouch. This has led to many standard gestures, including:
Unfortunately, we won't be implementing touch in this game because the target device for this book is the PC.
The advent of mobile devices was followed by an explosion of input techniques. Some of the more common ones include:
There are many other input techniques, and there is a lot of overlap. For example, most PCs have a microphone. Again, while many games in the mobile market are taking advantage of these alternative input methods, our game will be limited to the keyboard and mouse.
3.145.100.40