void Blob::eventBlit(SDL_Surface* surface, const PG_Rect& scr, const PG_Rect& dst){ PG_ThemeWidget::eventBlit(explosion_surface, scr, dst); if ( vmem1 != (unsigned char *)explosion_surface->pixels ) { p1= vmem1=(unsigned char *)explosion_surface->pixels; for (int i=0;i<YSIZE;i++) { mul640[i]=i*explosion_surface->pitch+vmem1; memset(p1,0,XSIZE); p1+=explosion_surface->pitch; } } now++; if(!flash) { if(explodenum>96 && explodenum<160 && !(rand()&511)) flash=60; } else --flash; explodenum=(now>>4)+1; if(explodenum==320) now=0; if(explodenum>256) explodenum=256; if(!(rand()&31)) addblob(); moveblobs(); putblobs(); p1=vmem1; p2=vmem2; int k=explosion_surface->pitch; for(int i=0;i<YSIZE;i++) { memcpy(p2,p1,XSIZE); p2+=XSIZE; p1+=k; } fire(vmem2,vmem1,k,flash ? remap2 :remap); }
main(int argc, char *argv[]) { int i,k; char *remap,*remap2; unsigned char *p1, *p2; long frames; int flash; int whichmap; int key; int ispaused; unsigned long videoflags; int done; int now; SDL_Event event; long starttime; int buttonstate; srand(time(NULL)); if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } videoflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_HWPALETTE; thescreen = SDL_SetVideoMode(XSIZE, YSIZE, 8, videoflags); if ( thescreen == NULL ) { fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError()); SDL_Quit(); exit(5); } vmem1=NULL; vmem2=malloc(XSIZE*YSIZE); if(!vmem2) nomem(); mul640=malloc(YSIZE*sizeof(char *)); if(!mul640) nomem(); remap=malloc(16384); if(!remap) nomem(); remap2=malloc(16384); if(!remap2) nomem(); blobs=malloc(MAXBLOBS*sizeof(struct blob)); if(!blobs) nomem(); puts("Fire demo by David Ashley ([email protected])"); puts("1 = Change color map"); puts("2 = Randomly change color map"); puts("p = Pause"); puts("spc = Fire"); puts("esc = Exit"); puts("Left mouse button = paint"); puts("Right mouse button, CR = ignite atmosphere"); freeblobs=activeblobs=0; for(i=0;i<MAXBLOBS;i++) { blobs[i].blobnext=freeblobs; freeblobs=blobs+i; } normal(remap); bright(remap2); flash=0; whichmap=0; loadcolors(whichmap); frames=0; ispaused=0; addblob(); done = 0; now=0; starttime=SDL_GetTicks(); buttonstate=0; mousex=mousey=0; while(!done) { if ( scrlock() < 0 ) continue; frames++; if ( vmem1 != (unsigned char *)thescreen->pixels ) { p1=vmem1=thescreen->pixels; for (i=0;i<YSIZE;i++) { mul640[i]=i*thescreen->pitch+vmem1; memset(p1,0,XSIZE); p1+=thescreen->pitch; } } if(!ispaused) { now++; if(!flash) { if(explodenum>96 && explodenum<160 && !(rand()&511) || (buttonstate&8)) flash=60; } else --flash; explodenum=(now>>4)+1;if(explodenum==320) now=0; if(explodenum>256) explodenum=256; if(!(rand()&31)) addblob(); moveblobs(); putblobs(); if(buttonstate&2) trydisk(); p1=vmem1; p2=vmem2; k=thescreen->pitch; for(i=0;i<YSIZE;i++) { memcpy(p2,p1,XSIZE); p2+=XSIZE; p1+=k; } fire(vmem2,vmem1,k,flash ? remap2 :remap); } scrunlock(); while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if ( event.button.state == SDL_PRESSED ) buttonstate|=1<<event.button.button; else buttonstate&=~(1<<event.button.button); mousex=event.button.x; mousey=event.button.y; if(!ispaused && buttonstate&2) trydisk(); break; case SDL_MOUSEMOTION: mousex=event.motion.x; mousey=event.motion.y; if(!ispaused && buttonstate&2) trydisk(); break; case SDL_KEYDOWN: key=event.key.keysym.sym; if(key==SDLK_RETURN) {flash=60;break;} if(key==SDLK_1 || key==SDLK_2) { if(key==SDLK_1) ++whichmap; else whichmap=rand(); loadcolors(whichmap); break; } if(key==SDLK_ESCAPE) {done=1;break;} if(key==SDLK_SPACE && !ispaused) {addblob();break;} if(key==SDLK_p) {ispaused=!ispaused;break;} break; case SDL_QUIT: done = 1; break; default: break; } } }