nuclear@0: #include nuclear@0: #include nuclear@0: #include "opengl.h" nuclear@1: #include "effect.h" nuclear@0: #include "psys.h" nuclear@0: nuclear@0: #include "hello1.h" nuclear@0: #include "hello2.h" nuclear@0: #include "pimg.h" nuclear@0: nuclear@2: #define HELLO_DURATION 4000 nuclear@2: nuclear@0: static PSysParam ppmain; nuclear@0: static PSysParam ppexpl, ppflame; nuclear@0: nuclear@0: static ParticleSystem psys; nuclear@0: static Image *pimg; nuclear@0: static Image *simg[2]; nuclear@2: static int cur_simg = -1; nuclear@2: static bool exploding; nuclear@2: nuclear@2: static void explode(); nuclear@0: nuclear@1: bool fx_init() nuclear@0: { nuclear@0: ppmain.spawn_rate = 20000; nuclear@0: ppmain.size = 0.06; nuclear@0: ppmain.spawn_range = 0.01; nuclear@0: ppmain.life = 0.4; nuclear@0: ppmain.gravity = Vector3(0, 0.01, 0); nuclear@0: nuclear@0: ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6; nuclear@0: ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6; nuclear@0: ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5); nuclear@0: nuclear@0: ppmain.palpha_start = 1.0; nuclear@0: ppmain.palpha_mid = 0.5; nuclear@0: ppmain.palpha_end = 0.0; nuclear@0: nuclear@0: ppmain.pscale_start = 1.0; nuclear@0: ppmain.pscale_mid = 1.0; nuclear@0: ppmain.pscale_end = 7.0; nuclear@0: nuclear@0: pimg = new Image; nuclear@0: pimg->pixels = (unsigned char*)img_particle.pixel_data; nuclear@0: pimg->width = img_particle.width; nuclear@0: pimg->height = img_particle.height; nuclear@0: nuclear@0: ppmain.pimg = pimg; nuclear@0: nuclear@0: simg[0] = new Image; nuclear@0: simg[0]->pixels = (unsigned char*)img_hello1.pixel_data; nuclear@0: simg[0]->width = img_hello1.width; nuclear@0: simg[0]->height = img_hello1.height; nuclear@0: nuclear@0: simg[1] = new Image; nuclear@0: simg[1]->pixels = (unsigned char*)img_hello2.pixel_data; nuclear@0: simg[1]->width = img_hello2.width; nuclear@0: simg[1]->height = img_hello2.height; nuclear@0: nuclear@0: ppmain.spawn_map = simg[0]; nuclear@0: ppmain.spawn_map_speed = 0.8; nuclear@0: psys.pp = ppmain; nuclear@2: psys.active = false; nuclear@0: nuclear@0: // explosion parameters nuclear@0: ppexpl = ppmain; nuclear@0: ppexpl.pcolor_start = ppmain.pcolor_mid; nuclear@0: ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5); nuclear@0: nuclear@0: ppexpl.palpha_start = 1.0; nuclear@0: ppexpl.palpha_mid = 0.5; nuclear@0: ppexpl.palpha_end = 0.05; nuclear@0: nuclear@0: ppexpl.pscale_start = 1.0; nuclear@0: ppexpl.pscale_mid = 3.0; nuclear@0: ppexpl.pscale_end = 5.0; nuclear@0: ppexpl.gravity = Vector3(0, -6, 0); nuclear@0: nuclear@0: // flame parameters nuclear@0: ppflame = ppexpl; nuclear@0: ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5; nuclear@0: ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5; nuclear@0: ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1); nuclear@0: //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6); nuclear@0: nuclear@0: ppflame.life = 0.5; nuclear@0: ppflame.life_range = 0.25; nuclear@0: ppflame.size = 0.07; nuclear@0: ppflame.size_range = 0.03; nuclear@0: ppflame.spawn_rate = 18000; nuclear@0: ppflame.gravity = Vector3(0, 2, 0); nuclear@0: nuclear@0: ppflame.palpha_start *= 0.7; nuclear@0: ppflame.palpha_mid *= 0.7; nuclear@0: ppflame.palpha_end *= 0.7; nuclear@0: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@1: void fx_cleanup() nuclear@0: { nuclear@0: delete pimg; nuclear@0: delete simg[0]; nuclear@0: delete simg[1]; nuclear@0: } nuclear@0: nuclear@1: void fx_draw(unsigned long msec) nuclear@0: { nuclear@2: static unsigned long prev_msec, ps_start_time; nuclear@0: float dt = (msec - prev_msec) / 1000.0; nuclear@0: prev_msec = msec; nuclear@0: nuclear@2: if(!psys.alive()) { nuclear@2: cur_simg = (cur_simg + 1) & 1; nuclear@2: printf("starting %d\n", cur_simg); nuclear@2: nuclear@2: psys.reset(); nuclear@2: ppflame.spawn_map = simg[cur_simg]; nuclear@2: ppexpl.spawn_map = simg[cur_simg]; nuclear@2: ppmain.spawn_map = simg[cur_simg]; nuclear@2: psys.pp = ppmain; nuclear@2: ps_start_time = msec; nuclear@2: exploding = false; nuclear@2: } else { nuclear@2: if(msec - ps_start_time > HELLO_DURATION && psys.active && !exploding) { nuclear@2: exploding = true; nuclear@2: explode(); nuclear@2: } nuclear@2: } nuclear@2: nuclear@0: psys.update(dt); nuclear@0: psys.draw(); nuclear@0: } nuclear@0: nuclear@2: static void explode() nuclear@0: { nuclear@0: psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5); nuclear@0: psys.pp = ppflame; nuclear@0: //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5); nuclear@0: //psys.pp = ppexpl; nuclear@0: }