textpsys
diff src/effect.cc @ 1:57c6f7b70126
renamed to textpsys
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 19 Aug 2015 09:17:20 +0300 |
parents | src/tbomb.cc@a4ffd9e6984c |
children | 4b1360a5d54d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/effect.cc Wed Aug 19 09:17:20 2015 +0300 1.3 @@ -0,0 +1,117 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include "opengl.h" 1.7 +#include "effect.h" 1.8 +#include "psys.h" 1.9 + 1.10 +#include "hello1.h" 1.11 +#include "hello2.h" 1.12 +#include "pimg.h" 1.13 + 1.14 +static PSysParam ppmain; 1.15 +static PSysParam ppexpl, ppflame; 1.16 + 1.17 +static ParticleSystem psys; 1.18 +static Image *pimg; 1.19 +static Image *simg[2]; 1.20 + 1.21 +bool fx_init() 1.22 +{ 1.23 + ppmain.spawn_rate = 20000; 1.24 + ppmain.size = 0.06; 1.25 + ppmain.spawn_range = 0.01; 1.26 + ppmain.life = 0.4; 1.27 + ppmain.gravity = Vector3(0, 0.01, 0); 1.28 + 1.29 + ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6; 1.30 + ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6; 1.31 + ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5); 1.32 + 1.33 + ppmain.palpha_start = 1.0; 1.34 + ppmain.palpha_mid = 0.5; 1.35 + ppmain.palpha_end = 0.0; 1.36 + 1.37 + ppmain.pscale_start = 1.0; 1.38 + ppmain.pscale_mid = 1.0; 1.39 + ppmain.pscale_end = 7.0; 1.40 + 1.41 + pimg = new Image; 1.42 + pimg->pixels = (unsigned char*)img_particle.pixel_data; 1.43 + pimg->width = img_particle.width; 1.44 + pimg->height = img_particle.height; 1.45 + 1.46 + ppmain.pimg = pimg; 1.47 + 1.48 + simg[0] = new Image; 1.49 + simg[0]->pixels = (unsigned char*)img_hello1.pixel_data; 1.50 + simg[0]->width = img_hello1.width; 1.51 + simg[0]->height = img_hello1.height; 1.52 + 1.53 + simg[1] = new Image; 1.54 + simg[1]->pixels = (unsigned char*)img_hello2.pixel_data; 1.55 + simg[1]->width = img_hello2.width; 1.56 + simg[1]->height = img_hello2.height; 1.57 + 1.58 + ppmain.spawn_map = simg[0]; 1.59 + ppmain.spawn_map_speed = 0.8; 1.60 + psys.pp = ppmain; 1.61 + 1.62 + // explosion parameters 1.63 + ppexpl = ppmain; 1.64 + ppexpl.pcolor_start = ppmain.pcolor_mid; 1.65 + ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5); 1.66 + 1.67 + ppexpl.palpha_start = 1.0; 1.68 + ppexpl.palpha_mid = 0.5; 1.69 + ppexpl.palpha_end = 0.05; 1.70 + 1.71 + ppexpl.pscale_start = 1.0; 1.72 + ppexpl.pscale_mid = 3.0; 1.73 + ppexpl.pscale_end = 5.0; 1.74 + ppexpl.gravity = Vector3(0, -6, 0); 1.75 + 1.76 + // flame parameters 1.77 + ppflame = ppexpl; 1.78 + ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5; 1.79 + ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5; 1.80 + ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1); 1.81 + //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6); 1.82 + 1.83 + ppflame.life = 0.5; 1.84 + ppflame.life_range = 0.25; 1.85 + ppflame.size = 0.07; 1.86 + ppflame.size_range = 0.03; 1.87 + ppflame.spawn_rate = 18000; 1.88 + ppflame.gravity = Vector3(0, 2, 0); 1.89 + 1.90 + ppflame.palpha_start *= 0.7; 1.91 + ppflame.palpha_mid *= 0.7; 1.92 + ppflame.palpha_end *= 0.7; 1.93 + 1.94 + return true; 1.95 +} 1.96 + 1.97 +void fx_cleanup() 1.98 +{ 1.99 + delete pimg; 1.100 + delete simg[0]; 1.101 + delete simg[1]; 1.102 +} 1.103 + 1.104 +void fx_draw(unsigned long msec) 1.105 +{ 1.106 + static unsigned long prev_msec; 1.107 + float dt = (msec - prev_msec) / 1000.0; 1.108 + prev_msec = msec; 1.109 + 1.110 + psys.update(dt); 1.111 + psys.draw(); 1.112 +} 1.113 + 1.114 +void fx_dbg() 1.115 +{ 1.116 + psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5); 1.117 + psys.pp = ppflame; 1.118 + //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5); 1.119 + //psys.pp = ppexpl; 1.120 +}