1
2 #include "pe_bubbles.h"
3 #include "resources.h"
4 #include "background.h"
5
6 extern Layouts *g_layouts;
7
PE_Bubbles(vec2 const & pos)8 PE_Bubbles::PE_Bubbles(vec2 const& pos) :
9 ParticleEffect(pos,50.0,150,3.0,&g_resources.texture_bubble)
10 {
11 }
12
update_single_particle(Particle & p,float delta_t,float p_time)13 void PE_Bubbles::update_single_particle(Particle& p,float delta_t,float p_time)
14 {
15 // add slight random deviation
16 p.cur_pos += (p.cur_speed + (RAND_0_1-0.5)*0.1) * delta_t;
17
18 // horizontal movement to sine wave, shifted by preset random factor in user data
19 p.cur_pos[0] += sin(p_time*10+p.user_data[0]*10)*0.06 * delta_t;
20
21 // increase the size with time
22 p.cur_size += 0.005 * delta_t;
23
24 // increase upwards speed with time
25 p.cur_speed[1] = -p_time*0.1;
26
27 // dampen alpha over time
28 if (p.cur_color[3]>0.0)
29 p.cur_color[3] -= 0.5 * delta_t;
30
31 if (p.cur_color[3]<=0.0)
32 p.alive = false;
33
34 // disable particles above sea level
35 float sea_y = Sea::sea_func(p.cur_pos[0]) + 0.263;
36 if (p.cur_pos[1]<sea_y)
37 p.alive = false;
38 }
39
emit_single_particle(Particle & p)40 void PE_Bubbles::emit_single_particle(Particle& p)
41 {
42 p.cur_pos = m_pos + vec2(RAND_0_1 * 0.01f,RAND_0_1 * 0.01f);
43 p.cur_speed = vec2((-0.01+RAND_0_1*0.02),-0.1);
44 // p.cur_size = 0.005;
45 p.cur_size = 0.003;
46 p.cur_color = vec4(1.0,1.0,1.0,1.0);
47 p.user_data = vec4(RAND_0_1,0,0,0);
48 }
49
50