textpsys

diff 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 diff
     1.1 --- a/src/effect.cc	Wed Aug 19 09:17:20 2015 +0300
     1.2 +++ b/src/effect.cc	Thu Aug 20 04:52:30 2015 +0300
     1.3 @@ -8,12 +8,18 @@
     1.4  #include "hello2.h"
     1.5  #include "pimg.h"
     1.6  
     1.7 +#define HELLO_DURATION	4000
     1.8 +
     1.9  static PSysParam ppmain;
    1.10  static PSysParam ppexpl, ppflame;
    1.11  
    1.12  static ParticleSystem psys;
    1.13  static Image *pimg;
    1.14  static Image *simg[2];
    1.15 +static int cur_simg = -1;
    1.16 +static bool exploding;
    1.17 +
    1.18 +static void explode();
    1.19  
    1.20  bool fx_init()
    1.21  {
    1.22 @@ -55,6 +61,7 @@
    1.23  	ppmain.spawn_map = simg[0];
    1.24  	ppmain.spawn_map_speed = 0.8;
    1.25  	psys.pp = ppmain;
    1.26 +	psys.active = false;
    1.27  
    1.28  	// explosion parameters
    1.29  	ppexpl = ppmain;
    1.30 @@ -100,15 +107,33 @@
    1.31  
    1.32  void fx_draw(unsigned long msec)
    1.33  {
    1.34 -	static unsigned long prev_msec;
    1.35 +	static unsigned long prev_msec, ps_start_time;
    1.36  	float dt = (msec - prev_msec) / 1000.0;
    1.37  	prev_msec = msec;
    1.38  
    1.39 +	if(!psys.alive()) {
    1.40 +		cur_simg = (cur_simg + 1) & 1;
    1.41 +		printf("starting %d\n", cur_simg);
    1.42 +
    1.43 +		psys.reset();
    1.44 +		ppflame.spawn_map = simg[cur_simg];
    1.45 +		ppexpl.spawn_map = simg[cur_simg];
    1.46 +		ppmain.spawn_map = simg[cur_simg];
    1.47 +		psys.pp = ppmain;
    1.48 +		ps_start_time = msec;
    1.49 +		exploding = false;
    1.50 +	} else {
    1.51 +		if(msec - ps_start_time > HELLO_DURATION && psys.active && !exploding) {
    1.52 +			exploding = true;
    1.53 +			explode();
    1.54 +		}
    1.55 +	}
    1.56 +
    1.57  	psys.update(dt);
    1.58  	psys.draw();
    1.59  }
    1.60  
    1.61 -void fx_dbg()
    1.62 +static void explode()
    1.63  {
    1.64  	psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5);
    1.65  	psys.pp = ppflame;