Building the UFO Program Example In order to
Building the UFO Program Example In order to really get a feel for how keyboard and mouse input works in games, it’s helpful to work through a complete example. The remainder of this hour focuses on a program example called UFO. Although this program isn’t technically a game, it’s by far the closest thing you’ve seen to a game yet. It involves a flying saucer that you control with the keyboard and mouse. You’re able to fly the flying saucer around a bitmap background image. Perhaps most important is the fact that the UFO program demonstrates how good of a feel you can create for game controls. More specifically, the arrow keys on the keyboard are surprisingly responsive in the UFO program. Although you haven’t really learned about animation yet, the UFO program example makes use of animation to allow you to fly the flying saucer. Fortunately, the program is simple enough that you can get by without knowing the specifics about animation. All you really need to know is that you can alter the position of a bitmap image to simulate movement on the screen. This occurs thanks to the game engine, which redraws the bitmap every game cycle. So, by altering the position of an image and redrawing it repeatedly, you create the effect of movement. The UFO program example reveals how this task is accomplished, as well as how the keyboard and mouse fit into the picture. You learn the details of how animation works in Hour 9, “A Crash Course in Game Animation.” Writing the Program Code The header file for the UFO program example lays the groundwork for the meat of the program, which carries out the details of the flying saucer animation and user input. Listing 6.1 contains the code for the UFO.h header file, which declares global variables used to control the flying saucer. Listing 6.1 The UFO.h Header File Declares Global Variables Used to Keep Track of the Flying Saucer 1: #pragma once 2: 3: //—————————————————————-4: // Include Files 5: //—————————————————————-6: #include
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services