textpsys

view src/effect.cc @ 2:4b1360a5d54d

switch between messages, and non-interactive
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 20 Aug 2015 04:52:30 +0300
parents 57c6f7b70126
children b1c8d2784c72
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 #define HELLO_DURATION 4000
13 static PSysParam ppmain;
14 static PSysParam ppexpl, ppflame;
16 static ParticleSystem psys;
17 static Image *pimg;
18 static Image *simg[2];
19 static int cur_simg = -1;
20 static bool exploding;
22 static void explode();
24 bool fx_init()
25 {
26 ppmain.spawn_rate = 20000;
27 ppmain.size = 0.06;
28 ppmain.spawn_range = 0.01;
29 ppmain.life = 0.4;
30 ppmain.gravity = Vector3(0, 0.01, 0);
32 ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6;
33 ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6;
34 ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5);
36 ppmain.palpha_start = 1.0;
37 ppmain.palpha_mid = 0.5;
38 ppmain.palpha_end = 0.0;
40 ppmain.pscale_start = 1.0;
41 ppmain.pscale_mid = 1.0;
42 ppmain.pscale_end = 7.0;
44 pimg = new Image;
45 pimg->pixels = (unsigned char*)img_particle.pixel_data;
46 pimg->width = img_particle.width;
47 pimg->height = img_particle.height;
49 ppmain.pimg = pimg;
51 simg[0] = new Image;
52 simg[0]->pixels = (unsigned char*)img_hello1.pixel_data;
53 simg[0]->width = img_hello1.width;
54 simg[0]->height = img_hello1.height;
56 simg[1] = new Image;
57 simg[1]->pixels = (unsigned char*)img_hello2.pixel_data;
58 simg[1]->width = img_hello2.width;
59 simg[1]->height = img_hello2.height;
61 ppmain.spawn_map = simg[0];
62 ppmain.spawn_map_speed = 0.8;
63 psys.pp = ppmain;
64 psys.active = false;
66 // explosion parameters
67 ppexpl = ppmain;
68 ppexpl.pcolor_start = ppmain.pcolor_mid;
69 ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5);
71 ppexpl.palpha_start = 1.0;
72 ppexpl.palpha_mid = 0.5;
73 ppexpl.palpha_end = 0.05;
75 ppexpl.pscale_start = 1.0;
76 ppexpl.pscale_mid = 3.0;
77 ppexpl.pscale_end = 5.0;
78 ppexpl.gravity = Vector3(0, -6, 0);
80 // flame parameters
81 ppflame = ppexpl;
82 ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5;
83 ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5;
84 ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1);
85 //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6);
87 ppflame.life = 0.5;
88 ppflame.life_range = 0.25;
89 ppflame.size = 0.07;
90 ppflame.size_range = 0.03;
91 ppflame.spawn_rate = 18000;
92 ppflame.gravity = Vector3(0, 2, 0);
94 ppflame.palpha_start *= 0.7;
95 ppflame.palpha_mid *= 0.7;
96 ppflame.palpha_end *= 0.7;
98 return true;
99 }
101 void fx_cleanup()
102 {
103 delete pimg;
104 delete simg[0];
105 delete simg[1];
106 }
108 void fx_draw(unsigned long msec)
109 {
110 static unsigned long prev_msec, ps_start_time;
111 float dt = (msec - prev_msec) / 1000.0;
112 prev_msec = msec;
114 if(!psys.alive()) {
115 cur_simg = (cur_simg + 1) & 1;
116 printf("starting %d\n", cur_simg);
118 psys.reset();
119 ppflame.spawn_map = simg[cur_simg];
120 ppexpl.spawn_map = simg[cur_simg];
121 ppmain.spawn_map = simg[cur_simg];
122 psys.pp = ppmain;
123 ps_start_time = msec;
124 exploding = false;
125 } else {
126 if(msec - ps_start_time > HELLO_DURATION && psys.active && !exploding) {
127 exploding = true;
128 explode();
129 }
130 }
132 psys.update(dt);
133 psys.draw();
134 }
136 static void explode()
137 {
138 psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5);
139 psys.pp = ppflame;
140 //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5);
141 //psys.pp = ppexpl;
142 }