Пример #1
0
bool BattleHazard::updateInner(GameState &state, unsigned int ticks)
{
	nextUpdateTicksAccumulated += ticks;
	while (nextUpdateTicksAccumulated >= TICKS_PER_HAZARD_UPDATE)
	{
		nextUpdateTicksAccumulated -= TICKS_PER_HAZARD_UPDATE;
		if (hazardType->fire)
		{
			// Explanation for how fire works is at the end of battlehazard.h
			if (power > 0)
			{
				age -= 6;
				if (age <= 10)
				{
					power = -power;
				}
			}
			else
			{
				age += 10;
			}
			power += power / std::abs(power);
			if (power % 2)
			{
				applyEffect(state);
				if (age < 130)
				{
					grow(state);
				}
			}
			if (age >= 130)
			{
				die(state, true);
				return true;
			}
		}
		else
		{
			age++;
			if (age % 2)
			{
				applyEffect(state);
				updateTileVisionBlock(state);
				if (age < lifetime)
				{
					grow(state);
				}
			}
			if (age >= lifetime)
			{
				die(state, true);
				return true;
			}
		}
	}
	return false;
}
Пример #2
0
void BattleHazard::update(GameState &state, unsigned int ticks)
{
	if (ticksUntilVisible > 0)
	{
		if (ticksUntilVisible > ticks)
		{
			ticksUntilVisible -= ticks;
		}
		else
		{
			ticksUntilVisible = 0;
		}
	}

	ticksUntilNextFrameChange -= ticks;
	if (ticksUntilNextFrameChange <= 0)
	{
		ticksUntilNextFrameChange += TICKS_PER_HAZARD_EFFECT;
		frame++;
		frame %= HAZARD_FRAME_COUNT;
	}

	ticksUntilNextEffect -= ticks;
	if (ticksUntilNextEffect <= 0)
	{
		ticksUntilNextEffect += TICKS_PER_HAZARD_EFFECT;
		applyEffect(state);
		age++;
		updateTileVisionBlock(state);
		if (age >= lifetime)
		{
			die(state);
		}
		else
		{
			grow(state);
		}
	}
}