textpsys

view 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 source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "opengl.h"
4 #include "effect.h"
5 #include "psys.h"
7 #include "hello1.h"
8 #include "hello2.h"
9 #include "pimg.h"
11 static PSysParam ppmain;
12 static PSysParam ppexpl, ppflame;
14 static ParticleSystem psys;
15 static Image *pimg;
16 static Image *simg[2];
18 bool fx_init()
19 {
20 ppmain.spawn_rate = 20000;
21 ppmain.size = 0.06;
22 ppmain.spawn_range = 0.01;
23 ppmain.life = 0.4;
24 ppmain.gravity = Vector3(0, 0.01, 0);
26 ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6;
27 ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6;
28 ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5);
30 ppmain.palpha_start = 1.0;
31 ppmain.palpha_mid = 0.5;
32 ppmain.palpha_end = 0.0;
34 ppmain.pscale_start = 1.0;
35 ppmain.pscale_mid = 1.0;
36 ppmain.pscale_end = 7.0;
38 pimg = new Image;
39 pimg->pixels = (unsigned char*)img_particle.pixel_data;
40 pimg->width = img_particle.width;
41 pimg->height = img_particle.height;
43 ppmain.pimg = pimg;
45 simg[0] = new Image;
46 simg[0]->pixels = (unsigned char*)img_hello1.pixel_data;
47 simg[0]->width = img_hello1.width;
48 simg[0]->height = img_hello1.height;
50 simg[1] = new Image;
51 simg[1]->pixels = (unsigned char*)img_hello2.pixel_data;
52 simg[1]->width = img_hello2.width;
53 simg[1]->height = img_hello2.height;
55 ppmain.spawn_map = simg[0];
56 ppmain.spawn_map_speed = 0.8;
57 psys.pp = ppmain;
59 // explosion parameters
60 ppexpl = ppmain;
61 ppexpl.pcolor_start = ppmain.pcolor_mid;
62 ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5);
64 ppexpl.palpha_start = 1.0;
65 ppexpl.palpha_mid = 0.5;
66 ppexpl.palpha_end = 0.05;
68 ppexpl.pscale_start = 1.0;
69 ppexpl.pscale_mid = 3.0;
70 ppexpl.pscale_end = 5.0;
71 ppexpl.gravity = Vector3(0, -6, 0);
73 // flame parameters
74 ppflame = ppexpl;
75 ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5;
76 ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5;
77 ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1);
78 //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6);
80 ppflame.life = 0.5;
81 ppflame.life_range = 0.25;
82 ppflame.size = 0.07;
83 ppflame.size_range = 0.03;
84 ppflame.spawn_rate = 18000;
85 ppflame.gravity = Vector3(0, 2, 0);
87 ppflame.palpha_start *= 0.7;
88 ppflame.palpha_mid *= 0.7;
89 ppflame.palpha_end *= 0.7;
91 return true;
92 }
94 void fx_cleanup()
95 {
96 delete pimg;
97 delete simg[0];
98 delete simg[1];
99 }
101 void fx_draw(unsigned long msec)
102 {
103 static unsigned long prev_msec;
104 float dt = (msec - prev_msec) / 1000.0;
105 prev_msec = msec;
107 psys.update(dt);
108 psys.draw();
109 }
111 void fx_dbg()
112 {
113 psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5);
114 psys.pp = ppflame;
115 //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5);
116 //psys.pp = ppexpl;
117 }