Skip to content

Instantly share code, notes, and snippets.

@kokoscript
Created January 28, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kokoscript/67ae2597aabbd43cc654eba752913851 to your computer and use it in GitHub Desktop.
Save kokoscript/67ae2597aabbd43cc654eba752913851 to your computer and use it in GitHub Desktop.
// fullscreen PSX DOOM fire effect for DOS
// based on https://fabiensanglard.net/doom_fire_psx/
#include <stdio.h>
#include <allegro.h>
#define FIRE_HEIGHT 200
#define PALSIZE 70
BEGIN_GFX_DRIVER_LIST
GFX_DRIVER_VGA
END_GFX_DRIVER_LIST
BEGIN_COLOR_DEPTH_LIST
COLOR_DEPTH_8
END_COLOR_DEPTH_LIST
BEGIN_DIGI_DRIVER_LIST
END_DIGI_DRIVER_LIST
BEGIN_MIDI_DRIVER_LIST
END_MIDI_DRIVER_LIST
BEGIN_JOYSTICK_DRIVER_LIST
END_JOYSTICK_DRIVER_LIST
BITMAP *dblbuffer;
char firepix[320 * FIRE_HEIGHT] = {0};
RGB col[35] = {
{ 63 , 62 , 54 },
{ 63 , 60 , 44 },
{ 63 , 58 , 34 },
{ 63 , 57 , 25 },
{ 63 , 55 , 15 },
{ 63 , 53 , 15 },
{ 63 , 51 , 14 },
{ 63 , 49 , 14 },
{ 63 , 47 , 13 },
{ 63 , 45 , 12 },
{ 63 , 43 , 12 },
{ 63 , 41 , 11 },
{ 63 , 39 , 11 },
{ 63 , 37 , 10 },
{ 63 , 35 , 10 },
{ 63 , 33 , 9 },
{ 63 , 31 , 9 },
{ 63 , 29 , 8 },
{ 63 , 27 , 7 },
{ 63 , 25 , 7 },
{ 63 , 23 , 6 },
{ 63 , 21 , 6 },
{ 63 , 19 , 5 },
{ 63 , 17 , 5 },
{ 63 , 15 , 4 },
{ 63 , 13 , 3 },
{ 63 , 11 , 3 },
{ 55 , 8 , 2 },
{ 48 , 6 , 1 },
{ 42 , 4 , 1 },
{ 37 , 2 , 1 },
{ 24 , 1 , 0 },
{ 16 , 0 , 0 },
{ 10 , 0 , 0 },
{ 7 , 0 , 0 }
};
int exitState;
int i;
void spreadFire(int from) {
int random = (rand() % 4) - 2;
int to = from - 320 - (random + 1);
firepix[to] = firepix[from] - (random & 1);
}
void doFire() {
int x;
int y;
for (x = 0; x < 320; x++) {
for (y = 1; y < FIRE_HEIGHT; y++) {
spreadFire(y * 320 + x);
}
}
}
int main(void) {
allegro_init();
install_keyboard();
if (set_gfx_mode(GFX_VGA, 320, 200, 0, 0) < 0) {
printf("Video error! You need VGA 13h for this :<");
return 1;
}
srand(time(NULL));
exitState = 0;
dblbuffer = create_bitmap(320, 200);
RGB yea = (RGB){0, 0, 0};
for (i = 0; i < 255; i++) {
set_color(i, &yea);
}
// Palette gen
for (i = 0; i < 35; i++) {
set_color(255 - i*2, &col[i]);
set_color(255 - (i*2)+1, &col[i]);
}
yea = (RGB){63, 63, 63};
set_color(0, &yea);
clear_to_color(dblbuffer, 1);
do {
doFire();
for (i = 0; i < 320 * FIRE_HEIGHT; i++) {
putpixel(dblbuffer, i % 320, (i / 320) + (200 - FIRE_HEIGHT), firepix[i]);
}
vsync();
blit(dblbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
if (key[KEY_ESC]) {
exitState = 1;
}
} while (exitState == 0);
destroy_bitmap(dblbuffer);
return 0;
}
END_OF_MAIN()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment