rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@0
|
3 #include "opengl.h"
|
nuclear@1
|
4 #include "effect.h"
|
nuclear@0
|
5 #include "psys.h"
|
nuclear@0
|
6
|
nuclear@0
|
7 #include "hello1.h"
|
nuclear@0
|
8 #include "hello2.h"
|
nuclear@0
|
9 #include "pimg.h"
|
nuclear@0
|
10
|
nuclear@2
|
11 #define HELLO_DURATION 4000
|
nuclear@2
|
12
|
nuclear@0
|
13 static PSysParam ppmain;
|
nuclear@0
|
14 static PSysParam ppexpl, ppflame;
|
nuclear@0
|
15
|
nuclear@0
|
16 static ParticleSystem psys;
|
nuclear@0
|
17 static Image *pimg;
|
nuclear@0
|
18 static Image *simg[2];
|
nuclear@2
|
19 static int cur_simg = -1;
|
nuclear@2
|
20 static bool exploding;
|
nuclear@2
|
21
|
nuclear@2
|
22 static void explode();
|
nuclear@0
|
23
|
nuclear@1
|
24 bool fx_init()
|
nuclear@0
|
25 {
|
nuclear@0
|
26 ppmain.spawn_rate = 20000;
|
nuclear@0
|
27 ppmain.size = 0.06;
|
nuclear@0
|
28 ppmain.spawn_range = 0.01;
|
nuclear@0
|
29 ppmain.life = 0.4;
|
nuclear@0
|
30 ppmain.gravity = Vector3(0, 0.01, 0);
|
nuclear@0
|
31
|
nuclear@0
|
32 ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6;
|
nuclear@0
|
33 ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6;
|
nuclear@0
|
34 ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5);
|
nuclear@0
|
35
|
nuclear@0
|
36 ppmain.palpha_start = 1.0;
|
nuclear@0
|
37 ppmain.palpha_mid = 0.5;
|
nuclear@0
|
38 ppmain.palpha_end = 0.0;
|
nuclear@0
|
39
|
nuclear@0
|
40 ppmain.pscale_start = 1.0;
|
nuclear@0
|
41 ppmain.pscale_mid = 1.0;
|
nuclear@0
|
42 ppmain.pscale_end = 7.0;
|
nuclear@0
|
43
|
nuclear@0
|
44 pimg = new Image;
|
nuclear@0
|
45 pimg->pixels = (unsigned char*)img_particle.pixel_data;
|
nuclear@0
|
46 pimg->width = img_particle.width;
|
nuclear@0
|
47 pimg->height = img_particle.height;
|
nuclear@0
|
48
|
nuclear@0
|
49 ppmain.pimg = pimg;
|
nuclear@0
|
50
|
nuclear@0
|
51 simg[0] = new Image;
|
nuclear@0
|
52 simg[0]->pixels = (unsigned char*)img_hello1.pixel_data;
|
nuclear@0
|
53 simg[0]->width = img_hello1.width;
|
nuclear@0
|
54 simg[0]->height = img_hello1.height;
|
nuclear@0
|
55
|
nuclear@0
|
56 simg[1] = new Image;
|
nuclear@0
|
57 simg[1]->pixels = (unsigned char*)img_hello2.pixel_data;
|
nuclear@0
|
58 simg[1]->width = img_hello2.width;
|
nuclear@0
|
59 simg[1]->height = img_hello2.height;
|
nuclear@0
|
60
|
nuclear@0
|
61 ppmain.spawn_map = simg[0];
|
nuclear@0
|
62 ppmain.spawn_map_speed = 0.8;
|
nuclear@0
|
63 psys.pp = ppmain;
|
nuclear@2
|
64 psys.active = false;
|
nuclear@0
|
65
|
nuclear@0
|
66 // explosion parameters
|
nuclear@0
|
67 ppexpl = ppmain;
|
nuclear@0
|
68 ppexpl.pcolor_start = ppmain.pcolor_mid;
|
nuclear@0
|
69 ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5);
|
nuclear@0
|
70
|
nuclear@0
|
71 ppexpl.palpha_start = 1.0;
|
nuclear@0
|
72 ppexpl.palpha_mid = 0.5;
|
nuclear@0
|
73 ppexpl.palpha_end = 0.05;
|
nuclear@0
|
74
|
nuclear@0
|
75 ppexpl.pscale_start = 1.0;
|
nuclear@0
|
76 ppexpl.pscale_mid = 3.0;
|
nuclear@0
|
77 ppexpl.pscale_end = 5.0;
|
nuclear@0
|
78 ppexpl.gravity = Vector3(0, -6, 0);
|
nuclear@0
|
79
|
nuclear@0
|
80 // flame parameters
|
nuclear@0
|
81 ppflame = ppexpl;
|
nuclear@0
|
82 ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5;
|
nuclear@0
|
83 ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5;
|
nuclear@0
|
84 ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1);
|
nuclear@0
|
85 //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6);
|
nuclear@0
|
86
|
nuclear@0
|
87 ppflame.life = 0.5;
|
nuclear@0
|
88 ppflame.life_range = 0.25;
|
nuclear@0
|
89 ppflame.size = 0.07;
|
nuclear@0
|
90 ppflame.size_range = 0.03;
|
nuclear@0
|
91 ppflame.spawn_rate = 18000;
|
nuclear@0
|
92 ppflame.gravity = Vector3(0, 2, 0);
|
nuclear@0
|
93
|
nuclear@0
|
94 ppflame.palpha_start *= 0.7;
|
nuclear@0
|
95 ppflame.palpha_mid *= 0.7;
|
nuclear@0
|
96 ppflame.palpha_end *= 0.7;
|
nuclear@0
|
97
|
nuclear@0
|
98 return true;
|
nuclear@0
|
99 }
|
nuclear@0
|
100
|
nuclear@1
|
101 void fx_cleanup()
|
nuclear@0
|
102 {
|
nuclear@0
|
103 delete pimg;
|
nuclear@0
|
104 delete simg[0];
|
nuclear@0
|
105 delete simg[1];
|
nuclear@0
|
106 }
|
nuclear@0
|
107
|
nuclear@1
|
108 void fx_draw(unsigned long msec)
|
nuclear@0
|
109 {
|
nuclear@2
|
110 static unsigned long prev_msec, ps_start_time;
|
nuclear@0
|
111 float dt = (msec - prev_msec) / 1000.0;
|
nuclear@0
|
112 prev_msec = msec;
|
nuclear@0
|
113
|
nuclear@2
|
114 if(!psys.alive()) {
|
nuclear@2
|
115 cur_simg = (cur_simg + 1) & 1;
|
nuclear@2
|
116 printf("starting %d\n", cur_simg);
|
nuclear@2
|
117
|
nuclear@2
|
118 psys.reset();
|
nuclear@2
|
119 ppflame.spawn_map = simg[cur_simg];
|
nuclear@2
|
120 ppexpl.spawn_map = simg[cur_simg];
|
nuclear@2
|
121 ppmain.spawn_map = simg[cur_simg];
|
nuclear@2
|
122 psys.pp = ppmain;
|
nuclear@2
|
123 ps_start_time = msec;
|
nuclear@2
|
124 exploding = false;
|
nuclear@2
|
125 } else {
|
nuclear@2
|
126 if(msec - ps_start_time > HELLO_DURATION && psys.active && !exploding) {
|
nuclear@2
|
127 exploding = true;
|
nuclear@2
|
128 explode();
|
nuclear@2
|
129 }
|
nuclear@2
|
130 }
|
nuclear@2
|
131
|
nuclear@0
|
132 psys.update(dt);
|
nuclear@0
|
133 psys.draw();
|
nuclear@0
|
134 }
|
nuclear@0
|
135
|
nuclear@2
|
136 static void explode()
|
nuclear@0
|
137 {
|
nuclear@0
|
138 psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5);
|
nuclear@0
|
139 psys.pp = ppflame;
|
nuclear@0
|
140 //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5);
|
nuclear@0
|
141 //psys.pp = ppexpl;
|
nuclear@0
|
142 }
|