Example: Bug Lite Animation DemoBug Lite is conceptually similar to the Fishtank example, but it includes conditional compilation sequences to control what type of EXE we wish to build. By defining the appropriate symbols at the top of the file, we can build either a native Win32 version, a windowed DirectDraw version, a full screen DirectDraw version with blitting, or a full screen DirectDraw version with flipping. In the program, animated mosquitoes fly back and forth past a bug zapper, but then fall to their untimely death when they get too close. Bug Lite is a 256-color program; a screen shot is shown here:
Bug Lite uses a 640x480 PCX file for the background image, and seven 320x200 PCX files for the sprites:
All eight PCX files use the same 256-color palette. The mosquito PCX files contain the different "frames" used as the mosquito sprites animate within themselves. We retrieve the sprites from the PCX files when the program begins (specifically, in the program's LoadBugs() function), storing them in 256-color bitmaps with fg_getimage(). The program's PutBug() function displays the requested sprite when needed using either fg_clpimage() or fg_flpimage(). While the bug zapper and the porch rail do not move, they must be foreground objects because mosquitoes can fly or fall behind them. An easy way to implement foreground objects is just treat them as sprites that we draw after any objects that might be in back of them, and that's exactly what we do in Bug Lite. As mentioned earlier, Bug Lite uses conditional compilation to control what type of EXE is created. This is accomplished by defining or commenting out four symbols at the beginning of the source code file. For example, to create a windowed DirectDraw version, we define the DIRECTDRAW and WINDOWED symbols, but comment out the FULL_SCREEN_BLIT and FULL_SCREEN_FLIP symbols, as shown here:
Source code for Bug Lite will not be presented here, but its C source code is included in the BugLite subdirectory of the Fastgraph examples directory.
|
 
copyright 2001 Ted Gruber Software, Inc.