/* * * This application has been modified from its original version, * by Timothy A. Graupmann. For any questions or comments send * email to tgraupmann@yahoo.com. * * Example program for the Allegro library, by Shawn Hargreaves. * * This program originally demonstrated... * * This program demonstrates how to write directly to video memory. * It implements a simple fire effect, first by calling getpixel() and * putpixel(), then by accessing video memory directly a byte at a * time, and finally using block memory copy operations. */ #include #include #ifdef DJGPP #include #include #include #endif #include "allegro.h" /* The fire is formed from several 'hotspots' which are moved randomly * across the bottom of the screen. */ #define FIRE_HOTSPOTS 75 int hotspot[FIRE_HOTSPOTS]; static int thotspot[FIRE_HOTSPOTS]; /* This function updates the bottom line of the screen with a pattern * of varying intensities which are then moved upwards and faded out * by the code in main(). */ void draw_bottom_line_of_fire() { int c, c2; unsigned char temp[320]; /* zero the buffer */ for (c=0; c= 0) && (c2 < SCREEN_W)) temp[c2] = MIN(temp[c2] + 20-ABS(hotspot[c]-c2), 192); /* move the hotspots */ hotspot[c] += thotspot[c]; if (hotspot[c] < 0) hotspot[c] += SCREEN_W; else if (hotspot[c] >= SCREEN_W) hotspot[c] -= SCREEN_W; } /* display the buffer */ for (c=0; c50; y--) { /* get an address for reading line y+1 */ address = bmp_read_line(screen, y+1); /* read the line */ movedata(screen->seg, address, _my_ds(), (unsigned)temp, SCREEN_W); /* adjust it */ for (x=0; x 0) temp[x]--; /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write the line */ movedata(_my_ds(), (unsigned)temp, screen->seg, address, SCREEN_W); } for (y=0; y<51; y++) { /* get an address for reading line y+1 */ address = bmp_read_line(screen, y+1); /* read the line */ movedata(screen->seg, address, _my_ds(), (unsigned)temp, SCREEN_W); /* adjust it */ for (x=0; x 0) temp[x]--; /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write the line */ movedata(_my_ds(), (unsigned)temp, screen->seg, address, SCREEN_W); } } return 0; }