Example: Bug Lite Animation Demo

Bug 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:

BUGBACK.PCX

background image

LAMP.PCX

bug zapper sprite

MFALL.PCX

mosquito falling (four frames)

MOSQ.PCX

mosquito flying (eight frames)

MTURN.PCX

mosquito turning around (four frames)

MZAP.PCX

mosquito getting zapped (three frames)

MZAPA.PCX

mosquito getting zapped (one frame)

RAIL.PCX

center of porch rail sprite

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:


// The DIRECTDRAW symbol must be defined if linking with FGW's DirectDraw
// libraries, and commented out if linking with FGW's native Win32 libraries.
#define DIRECTDRAW
// The WINDOWED symbol must be defined if creating a windowed program, and
// commented out if creating a full screen DirectDraw program.
#define WINDOWED
// The FULL_SCREEN_BLIT and FULL_SCREEN_FLIP symbols are mutually exclusive
// and apply only to full screen DirectDraw programs. Define FULL_SCREEN_BLIT
// to use DirectDraw blitting, or define FULL_SCREEN_FLIP to use DirectDraw
// page flipping. Comment out both symbols if WINDOWED is defined above.
#ifdef DIRECTDRAW
//#define FULL_SCREEN_BLIT
//#define FULL_SCREEN_FLIP
#endif

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.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.