void ParticleManager::update(float dt)
{
	BBGE_PROF(ParticleManager_update);
	numActive = 0;
	for (int i = 0; i < particles.size(); i++)
	{
		if (particles[i].active)
		{
			updateParticle(&particles[i], dt);
		}
	}
}
Exemple #2
0
void Element::update(float dt)
{
	BBGE_PROF(Element_update);
	if (!core->particlesPaused)
	{
		updateLife(dt);
		updateEffects(dt);
		if (drawGrid)
			updateGrid(dt);
	}

//	updateCullVariables();
}
Particle *ParticleManager::getFreeParticle(Emitter *emitter)
{
	BBGE_PROF(ParticleManager_getFreeParticle);
	if (size == 0) return 0;

	Particle *p = 0;

	p = &particles[free];

	if (p->active)
	{
		p = stomp();
	}
	else
	{
		endParticle(p);
		p->index = free;
		nextFree(spread);
	}

	/*
	static int lpstep = 0;
	if (c > lpstep)
		lpstep = c;
	std::ostringstream os;
	os << "psteps: " << c << " largest: " << lpstep;
	debugLog(os.str());
	*/


	/*
	p = &particles[free];
	nextFree();
	*/



	if (emitter)
	{
		p->emitter = emitter;

		emitter->addParticle(p);
	}

	return p;
}
Exemple #4
0
void SchoolFish::onUpdate(float dt)
{
	BBGE_PROF(SchoolFish_onUpdate);
	/*
	Quad::onUpdate(dt);
	return;
	*/

	/*
	if (dsq->continuity.form == FORM_BEAST)
		this->activationType = ACT_CLICK;
	else
		this->activationType = ACT_NONE;
	*/


	/*
	if (burstDelay == 0)
	{
		maxSpeedLerp = 2;
		Vector v = getNormal();
		vel = 0;
		v *= -5000;
		vel += v;
		//float t = (100 + rand()%100)/100.0;
		float t = 2;
		maxSpeedLerp.interpolateTo(1, t);
		burstDelay = 10;// + (rand()%100)/100.0;
		//rotateToVec(v, 0, 90);
		//rotation.interpolateTo(0, 1);

		if (v.x > 0 && !isfh())
		{
			flipHorizontal();
			flipDelay = 0.5;
		}
		if (v.x < 0 && isfh())
		{
			flipHorizontal();
			flipDelay = 0.5;
		}
	}
	else
	*/

	{
		burstDelay -= dt;
		if (burstDelay < 0)
		{
			burstDelay = 0;
		}
	}

	if (stickToNaijasHead && alpha.x < 0.1)
		stickToNaijasHead = false;

	if (this->layer < LR_ENTITIES)
	{
		//debugLog("background fish!");
		/*
		setDamageTarget(DT_AVATAR_SHOCK, false);
		setDamageTarget(DT_AVATAR_BITE, false);
		setDamageTarget(DT_AVATAR_VOMIT, false);
		setDamageTarget(DT_AVATAR_ENERGYBLAST, false);
		*/
		setEntityType(ET_NEUTRAL);
		collideRadius = 0;
	}

	if (getState() == STATE_DEAD)
	{
		FlockEntity::onUpdate(dt);
		respawnTimer -= dt;
		if (!(dsq->game->avatar->position - this->position).isLength2DIn(2000))
		{
			if (respawnTimer < 0)
			{
				respawnTimer = 0;
				perform(STATE_IDLE);
			}
		}
	}
	else
	{
		/*
		if (layer == LR_ENTITIES || layer == LR_ENTITIES2)
		{
			rippleTimer -= dt;
			if (rippleTimer < 0)
			{
				if (core->afterEffectManager)
					core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),position,0.04,0.06,15,0.2f));
				rippleTimer = 0.5;
			}
		}
		*/

		FlockEntity::onUpdate(dt);

		if (dsq->game->isValidTarget(this, 0))
			dsq->game->handleShotCollisions(this);


		/*
		soundDelay -= dt;
		if (soundDelay <= 0)
		{
			//sound(swimSound, 1000 + rand()%100);
			soundDelay = 4+(rand()%50)/100.0;
		}
		*/
		/*
	1.    if distance_to(closest_boid) <= too_close then set direction away from closest_boid
	2.    speed_of_neighbors := average(speed(x), for all x where distance_to(x) <= neighborhood_size)
			direction_of_neighbors := avg(direction(x), for all x where distance_to(x) <= neighborhood_size)
			if speed < speed_of_neighbors then increase speed
			if speed > speed_of_neighbors then decrease speed
			turn towards direction_of_neighbors
	3.    position_of_neighbors := avg(position(x), for all x where distance_to(x) <= neighborhood_size)
			turn towards position_of_neighbors
		*/


		float seperation = 1;
		float alignment = 0;
		float cohesion = 0.75;
		/*
		FlockPiece flock;
		getFlockInRange(160, &flock);
		*/
		// if flock in 160 ?
		if (true)
		{
			VectorSet newDirection;

			if (avoidTime>0)
			{
				avoidTime -= dt;
				if (avoidTime<0)
					avoidTime=0;
			}

			Vector dir = getFlockHeading();

			Vector accumulator;


			applyCohesion(accumulator);
			applyAlignment(accumulator, dir);
			// alignment
			applySeparation(accumulator);
			applyAvoidance(accumulator);
			updateVelocity(accumulator);

			/*
			if (dsq->game->isValidTarget(this, 0))
				doSpellAvoidance(dt, 96, dodgeAbility);
			*/


			Vector lastPosition = position;
			Vector newPosition = position + (vel*velocityScale*dt) + vel2*dt;
			position = newPosition;

			if (dsq->game->isObstructed(position))
			{
				position = lastPosition;
				/*
				position = Vector(newPosition.x, lastPosition.y);
				if (dsq->game->isObstructed(position))
				{
					position = Vector(lastPosition.x, newPosition.y);
					if (dsq->game->isObstructed(position))
					{
						position = lastPosition;
					}
				}
				*/
			}

			//updateCurrents(dt);
			updateVel2(dt);


			/*
			if (flipDelay > 0)
			{
				flipDelay -= dt;
				if (flipDelay < 0)
				{
					flipDelay = 0;
				}
			}
			*/

			flipDelay = 0;

			//dir.normalize2D();
			if (flipDelay <= 0)
			{
				const float amt = 0;
				/*

				if (fabs(dir.x) > fabs(dir.y))
				{
					if (dir.x > amt && !isfh())
					{
						flipHorizontal();
						flipDelay = 0.5;
					}
					if (dir.x < -amt && isfh())
					{
						flipHorizontal();
						flipDelay = 0.5;
					}
				}
				*/
				if (vel.x > amt && !isfh())
				{
					flipHorizontal();
				}
				if (vel.x < -amt && isfh())
				{
					flipHorizontal();
				}
			}


			//rotateToVec(accumulator, 5, 90);

			float angle = atan(dir.y/dir.x);
			angle = ((angle*180)/3.14);

			if (angle > 45)
				angle = 45;
			if (angle < -45)
				angle = -45;
			

			rotation = Vector(0,0,angle);

			//rotation.interpolateTo(Vector(0, 0, angle), 0);
		}

	}
}