-
Notifications
You must be signed in to change notification settings - Fork 0
/
vfx.pde
65 lines (56 loc) · 1.76 KB
/
vfx.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ParticleSystem vfx;
PImage vfx_sprite;
float vfx_fade_time = 25.5f;
void setupVFX()
{
vfx = new ParticleSystem( 0, 0.0, -0.9, 0.05f );
vfx_sprite = loadImage("particle.png");
}
void updateVFX()
{
vfx.tick();
// remove particles that are too old
for ( int i = 0; i < vfx.numberOfParticles(); ++i )
{
if ( vfx.getParticle( i ).age() > vfx_fade_time )
{
vfx.removeParticle( vfx.getParticle(i) );
--i;
}
}
}
void drawVFX( GLGraphicsOffScreen surface )
{
surface.colorMode( HSB );
surface.noStroke();
surface.beginShape( QUADS );
// surface.texture( vfx_sprite );
// surface.textureMode( NORMAL );
surface.setBlendMode( ADD );
//surface.hint( DISABLE_DEPTH_TEST );
for ( int i = 0; i < vfx.numberOfParticles(); ++i )
{
Particle p = vfx.getParticle(i);
surface.fill( 57, 50, map( p.age(), vfx_fade_time*0.75f, vfx_fade_time, 100, 0 ) );
float sz = 4;
surface.vertex( p.position().x() - sz, p.position().y() - sz, p.position().z() );
surface.vertex( p.position().x() - sz, p.position().y() + sz, p.position().z() );
surface.vertex( p.position().x() + sz, p.position().y() + sz, p.position().z() );
surface.vertex( p.position().x() + sz, p.position().y() - sz, p.position().z() );
//surface.image( vfx_sprite, p.position().x(), p.position().y(), 128, 128 );
//surface.blend( vfx_sprite, 0, 0, 64, 64, (int)p.position().x() - 32, (int)p.position().y() - 32, 64, 64, ADD );
}
surface.endShape();
}
void playVFX( PVector pos )
{
int burst = 10;
float vel = 10;
for ( int i = 0; i < burst; ++i )
{
Particle p = vfx.makeParticle( 1, pos.x, pos.y, pos.z );
float xvel = random( -vel, vel );
float yvel = random( -vel, vel );
p.velocity().set( xvel, yvel, 5 );
}
}