示例#1
0
	void Emitter::update(F32 delta_time){
		if (!game_object->active) return;
		lambda_spawn(this);
		m_elapsed_time += delta_time;
		
		for (auto& p : m_particles){
		
			if (p.active){
				lambda_particle_update(this,&p, delta_time);
				p.lifetime += p.decay_rate * delta_time;
				if (p.lifetime >= 1.0f){
					remove_particle(&p);
				}
			}
		}
	}
示例#2
0
int delete_particle_of_type(int type) { 
	int *p_id, *index_id;
	p_id=(int *) malloc (sizeof(int));
	index_id=(int *) malloc (sizeof(int));
	if (find_particle_type_id(type, p_id, index_id) == ES_ERROR )
		return ES_ERROR;

	int in_type = Index.type[type];
	// maximal possible index id
	int max = type_array[in_type].max_entry - 1;
	if ( max < 0 ) 
		return ES_ERROR;

	if ( remove_particle(*p_id) == ES_ERROR ) {
		// takes also care of removing the index from the array
		return ES_ERROR;
	}
	return ES_OK;
}
示例#3
0
	void Emitter::disable(){
		for (auto& p : m_particles){
			if (p.active) remove_particle(&p);
		}
	}
int main(void) {
  t_gravity_particles gravity_particles;
  t_particle_system* particle_system;
  t_particle* p;
  int i;
  
  show_msgbox(
    "Ndless - Particle System Demo",
    "------------------------\n"
    "       Particle System Demo\n" \
    "© 2010-2011 by the Ndless Team\n"
    "------------------------\n"
    "+  Add a particle\n"
    "-  Remove a particle\n"
    "*  Increase gravity\n"
    "/  Decrease gravity\n"
    "C  Enable/Disable collision detection\n"
    "T  Enable/Disable trace mode\n"
    "S  Clear screen\n"
    "ESC - Exit"
  );

	if (is_classic) { // programs are started with the screen cleared on non-classic
		void *scrbuf = malloc(SCREEN_BYTES_SIZE);
		memcpy(scrbuf, SCREEN_BASE_ADDRESS, SCREEN_BYTES_SIZE);
	  for (i = 0; i < 0x0F; ++i) {
	    fade(scrbuf, 1);
	    sleep(70);
	    if (isKeyPressed(KEY_NSPIRE_ESC)) {
	    	free(scrbuf);
	    	return 0;
	    }
	  }
	  free(scrbuf);
	}
	
	clrscr();
	lcd_ingray();

  gravity_particles_construct(&gravity_particles, 0.00006672f, 100);
  particle_system = &(gravity_particles.particleSystem);
  particle_system->detectCol = false;
  particle_system->trace = false;
  particle_system_start(particle_system);

  p = particle_construct3(&(t_vector){0.f, 0.f, 0.f}, &(t_vector){0.f, 0.f, 0.f}, 1500.f, 4, BLACK);
  (void) particle_system_addParticle(particle_system, p);
  add_particle(&gravity_particles);

  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
    gravity_particles_draw(&gravity_particles);

    // Add a particule (+)
    if (isKeyPressed(KEY_NSPIRE_PLUS)) {
      if (particle_system->nParticles == 0) {
        p = particle_construct3(&(t_vector){0.f, 0.f, 0.f}, &(t_vector){0.f, 0.f, 0.f}, 1500.f, 4, BLACK);
        (void) particle_system_addParticle(particle_system, p);
      }
      add_particle(&gravity_particles);
      while (isKeyPressed(KEY_NSPIRE_PLUS));
    }

    // Remove a particle (-)
    if (isKeyPressed(KEY_NSPIRE_MINUS)) {
      remove_particle(&gravity_particles);
      while (isKeyPressed(KEY_NSPIRE_MINUS));
    }

    // High gravity (*)
    if (isKeyPressed(KEY_NSPIRE_MULTIPLY)) {
      gravity_particles.gravitationalConstant *= 10.f;
      while (isKeyPressed(KEY_NSPIRE_MULTIPLY));
    }

    // Low gravity (/)
    if (isKeyPressed(KEY_NSPIRE_DIVIDE)) {
      gravity_particles.gravitationalConstant /= 10.f;
      while (isKeyPressed(KEY_NSPIRE_DIVIDE));
    }

    // Collision (C)
    if (isKeyPressed(KEY_NSPIRE_C)) {
      particle_system->detectCol = !particle_system->detectCol;
      while (isKeyPressed(KEY_NSPIRE_C));
    }

    // Collision (T)
    if (isKeyPressed(KEY_NSPIRE_T)) {
      particle_system->trace = !particle_system->trace;
      while (isKeyPressed(KEY_NSPIRE_T));
    }

    // Collision (S)
    if (isKeyPressed(KEY_NSPIRE_S)) {
      clearScreen();
      while (isKeyPressed(KEY_NSPIRE_S));
    }
  }

  gravity_particles_destruct(&gravity_particles);

  return 0;
}