Controlling Games with the Keyboard and Mouse - Testing the Finished Product
(Page 8 of 8 )
The UFO example is the closest thing you've seen to a game thus far and is quite interesting in terms of allowing you to fly around an animated graphical object. Hopefully, you'll be pleasantly surprised by the responsiveness of the program's keyboard controls. Figure 5.2 shows the UFO program in action as the flying saucer does a flyby of some desert cacti.

Figure 5.2 -- The UFO example demonstrates how to control an animated graphical object with the keyboard and mouse.
If you guide the flying saucer to the edge of the game screen, it will stop, which is to be expected given the program code you just worked through. There are a variety of different ways to tweak this program and make it more intriguing, such as wrapping the flying saucer from one side of the screen to the other, which is why I hope you spend some time tinkering with the code.
Summary
The ability to effectively communicate with the people who play your games is a critical factor of game design and development. In one direction, a game communicates by displaying graphics and playing sounds and music, but in the other direction, the user responds by interacting with a physical input device of some sort. It's very important for game developers to master the fine art of responding to user input through a variety of different user input devices. The keyboard and mouse are the two fundamental user input devices that you can count on all people having. This chapter showed you how to handle and respond to keyboard and mouse input in an efficient manner specifically suited to games.
Beyond the keyboard and mouse, it's up to your resources and the specific needs of each game to determine whether you should support additional input devices. Chapter 7 tackles the subject of joystick input, which is the next most important input device for games. However, before you get to that, it's time to get down to business and create a real game; the next chapter guides you through the design and development of your first game.
Field Trip
Quick! Forget everything you just learned in this chapter! If you haven't already played it, beg, borrow, or maybe even consider purchasing the game LifeLine by Konami, which is billed as the world's first "voice action adventure." Although LifeLine might be old news to some gamers, it has charted new territory in the way of game user interfaces. LifeLine is very unique in that it relies solely on voice commands to play the game, which means that you don't really use any input device other than a microphone. Although this might sound strange at first, in the context of the game, it works very well because the storyline involves you being stuck in a room communicating with a robot via a microphone. If you already have the game, consider this field trip a day off. Otherwise, I encourage you to check out LifeLine and analyze how it turns traditional game input on its ear. Incidentally, I have no connection to Konami or the game LifeLine, so this isn't a deviously clever plug.
This chapter is from Beginning Game Programming, by Michael Morrison (Sams, ISBN: 0672326590). Check it out at your favorite bookstore today.
Buy this book now. |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
| Recommended by Dev Hardware |
|---|
|