void HealthBarComponent::update(GameObject* gameObject){
	if (!checkIfAlive(gameObject))
		return;
	setPosition(gameObject);
	updateHealthBar(gameObject);
	drawHealthBar(gameObject);
}
Beispiel #2
0
void Tank::update(float frameTime, int roadSpeed, std::vector<std::shared_ptr<Bullet>>& bullets, PlayerCar& player)
{
	Car::update(frameTime, roadSpeed);

	if (!_IsExploding) {
		if (driveToNextPosition(frameTime))
		{
			switch (_Movement) {
			case Movement::DRIVETODEFAULT:
				_Movement = Movement::LEFTRIGHT;
				_Speed = 200;
				_Attack = true;
				_PhaseClock.restart();
				break;
			case Movement::LEFTRIGHT:
				_MovementSwitch = !_MovementSwitch;
				if (_MovementSwitch) {
					_NextPosition = getPos() + sf::Vector2f((SCREENWIDTH - getPos().x - getWidth() / 2) * (std::rand() % 100) / 100.0f, 0.0f);
				}
				else {
					_NextPosition = getPos() - sf::Vector2f((getPos().x - getWidth() / 2) * (std::rand() % 100) / 100.0f, 0.0f);
				}
				break;
			default:
				break;
			}
		}

		if (_Attack)
		{
			float angle = getAngleFromVector(_GunOrientation);

			switch (_Pattern[_CurrentPhase].first) {
			case Phase::SIMPLESHOOT:
				_Event1Frequency = 4.25f + 1.25f * (float)_Difficulty;

				_GunOrientation = divideByLength(player.getPos() - getPos());

				if (getBossEvent() == 1) {
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
				}
				break;
			case Phase::SALVE:
				
				_Event1Frequency = 1.0f + 0.75f * (float)_Difficulty;
				_Event2Frequency = 10.0f + 1.0f * (float)_Difficulty;

				_GunOrientation = divideByLength(player.getPos() - getPos());

				if (_Event1Switch) {
					if (getBossEvent() == 2) {
						BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
						if (_Event1Counter + 1 < 3) {
							_Event1Counter += 1;
						}
						else {
							_Event1Switch = false;
							_Event1Counter = 0;
						}
					}
				}
				else {
					if (getBossEvent() == 1) {
						_Event1Switch = true;
					}
				}
				break;
			case Phase::SPIN:
				_Event1Frequency = 9.0f + 1.0f * (float)_Difficulty;
				if (_Event1Switch) {
					if (angle + frameTime * 100 > 180.0f) {
						_Event1Switch = false;
					}
					else {
						angle += frameTime * 100;
					}
				}
				else {
					if (angle - frameTime * 100 < 0.0f) {
						_Event1Switch = true;
				}
				else {
						angle -= frameTime * 100;
					}
				}
				_GunOrientation = divideByLength(sf::Vector2f(std::cos(angle * PI / 180), std::sin(angle * PI / 180)));

				if (getBossEvent() == 1) {
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation);
				}
				break;
			case Phase::HARDCORESPAM:
				_Event1Frequency = 40.0f + 15.0f * (float)_Difficulty;
				if (getBossEvent() == 1) {
					_Event1Counter++;
					_GunOrientation = divideByLength(sf::Vector2f(((float)(std::rand() - (float)(RAND_MAX) / 2) / (float)(RAND_MAX)), 
						((float)(std::rand() - (float)(RAND_MAX) / 2) / (float)(RAND_MAX))));
					BossCar::shootBullet(bullets, calcBulletPosition(), _GunOrientation, (float)(_Event1Counter % 5 < 2) * _Volume);
				}
				break;
			}

		}
		_GunSprite.setPosition(getPos() + _GunPosition);
		_GunSprite.setRotation(getAngleFromVector(_GunOrientation) - 90);

		updateHealthBar();
		checkPhase();
	}
	else {
		updateExplosions(frameTime);
	}
}