Example #1
0
/// <summary>
/// This function process a activated power
/// </summary>
void Player::processPowerUps()
{
	// Temporary Pulsegun powerup (lasts 6 seconds)
	if (pulsateGun && pwrUpTime.asSeconds() < 6)
	{

		// Check if the clock  has elapsed 1 second
		if (pulseTime.asMilliseconds() > 1000)
		{

			// Creates a circular bullet pattern.
			for (int i = 1; i < 20; i += 1)
			{

				// Gets a bullet, sets the owner to this, sets the bullet rotation, sets the bullet position, pushes the bullet to the bullet list.
				std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::standardShot);
				b->setOwner(this->getType());
				b->setRotation(i, sf::Vector2f(150, 150));
				b->sprite->setPosition(this->sprite->getPosition().x, this->sprite->getPosition().y);
				getBullets().push_back(std::move(b));
			}

			pulseTime = sf::milliseconds(0);
		}
	}
	// Time is up! deactivate the pulse gun
	else
	{
		pulsateGun = false;
	}


}
Example #2
0
/// <summary>
/// Enemy shoot handler
/// </summary>
/// <param name="shoot">Which type of shot it is.</param>
void Enemy::shoot(int shoot)
{
	// SHOOT -1 = undefined (no shooting)
	// SHOOT 0 = undefined (no shooting)
	// SHOOT 3  = SPECIAL ATTACK
	// SHOOT 1 = Normal attack which differ depending on the enemy

	// Check if shooting is of.
	if (shoot != -1 && shoot != 0)
	{

		// Check if its a regular enemy
		if (getEnemyType() == Enemy::EnemyType::REGULAR)
		{
			// Gets a bullet and set the appropriate data, then push to the bulletlist
			std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::standardShot);
			b->setOwner(this->getType());
			b->sprite->setPosition(this->sprite->getPosition().x, this->sprite->getPosition().y - 10);
			getBullets().push_back(std::move(b));

		}

		// Check if its a Chubby enemy
		else if (getEnemyType() == Enemy::EnemyType::CHUBBY)
		{
			// Retrieve 3 bullets and defines a start position for the bullet.
			std::list<std::unique_ptr<Bullet>> bat = getBulletFactory().requestBatch(3, Bullet::Type::standardShot);
			int startX = (this->sprite->getPosition().x) - (this->sprite->getGlobalBounds().width / 2) + 10;

			// Iterate through the bullet request , set properties and push back to bullet list
			for (auto& i : bat)
			{
				std::unique_ptr<Bullet> bs = std::move(i);
				bs->setOwner(this->getType());
				bs->sprite->setPosition(startX, this->sprite->getPosition().y - 10);
				getBullets().push_back(std::move(bs));
				startX += this->sprite->getGlobalBounds().width / 4;
			}

		}

		// Check if its a BOSS enemy
		else if (getEnemyType() == Enemy::EnemyType::BOSS)
		{

			// Gets a bullet and set the appropriate data, then push to the bulletlist
			std::list<std::unique_ptr<Bullet>> bat = getBulletFactory().requestBatch(10, Bullet::Type::standardShot);
			int startX = (this->sprite->getPosition().x) - (this->sprite->getGlobalBounds().width / 2);

			// Iterate through the bullet request , set properties and push back to bullet list
			for (auto& i : bat)
			{
				std::unique_ptr<Bullet> bs = std::move(i);
				bs->setOwner(this->getType());
				bs->sprite->setPosition(startX, this->sprite->getPosition().y - 10);
				getBullets().push_back(std::move(bs));
				startX += this->sprite->getGlobalBounds().width / 10;
			}

		}

		// Check if its a DEATHSTAR enemy
		else if (getEnemyType() == Enemy::EnemyType::DEATHSTAR)
		{

			if (shoot == 3 || shoot == 5) // Special attack
			{
				std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::standardShot);
				b->setOwner(this->getType());

				// Rotational Lazor (Lol)
				if (shoot == 5)
				{
					secondRot += 0.004f * timeStep.asMilliseconds();
					b->setRotation(secondRot, sf::Vector2f(350.f, 350.0f));
					b->sprite->setFillColor(sf::Color::Red);
					b->sprite->setPosition(this->sprite->getPosition().x, this->sprite->getPosition().y);
				}
				else
				{
					b->setSpeed(sf::Vector2f(0.0f, 350.0f));
					b->sprite->setFillColor(sf::Color::Green);
					b->sprite->setPosition(this->sprite->getPosition().x, this->sprite->getPosition().y + this->sprite->getRadius());
				}
				getBullets().push_back(std::move(b));


			}

			// Circular shoot pattern
			if (shoot == 4)
			{
				for (float i = 0; i < 360; i += 2)
				{
					std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::standardShot);
					b->setOwner(this->getType());
					b->setRotation(i + secondRot, sf::Vector2f(150, 150));
					b->sprite->setPosition(this->sprite->getPosition().x, this->sprite->getPosition().y);
					getBullets().push_back(std::move(b));

				}

				// randomize 2nd degree rotation
				secondRot++;
			}
		}
	}
}
Example #3
0
/// <summary>
/// Inputs the specified event.
/// </summary>
/// <param name="event">The event.</param>
void Player::input(sf::Event& event)
{
	/*
	// IF COMMA is clicked
	if (event.key.code == sf::Keyboard::Comma && event.type == sf::Event::KeyReleased) // Sound mute button
	{
	std::cout << godMode << std::endl;
	godMode = !godMode;
	}*/

	// Player's left mouse click shoot handler
	if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && normalShotTime.asMilliseconds() > 150){

		// Request a standard bullet and sets the appropriate data
		std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::standardShot);
		b->setOwner(getType());
		b->sprite->setPosition(sprite->getPosition().x, sprite->getPosition().y - 10);

		// Play shoot sound
		resourceHandler->getSound(ResourceHandler::Sound::FX_STANDARD_SHOT).play();

		// Push the bullet to the bullet list
		getBullets().push_back(std::move(b));

		// Restart the clock
		normalShotTime = sf::milliseconds(0);
	}

	// Player's right mouse click shoot handler
	if (sf::Mouse::isButtonPressed(sf::Mouse::Right) && specialShotTime.asMilliseconds() > 1000){

		// Request a heavy shot bullet and set the appropriate data
		std::unique_ptr<Bullet> b = getBulletFactory().requestObject(Bullet::Type::heavyShot);
		b->setOwner(getType());
		b->sprite->setPosition(sprite->getPosition().x, sprite->getPosition().y - 10);

		// Play shoot sound
		resourceHandler->getSound(ResourceHandler::Sound::FX_HEAVY_SHOT).play();

		// Push the bullet to the bullet list
		getBullets().push_back(std::move(b));

		// Restart the clock
		specialShotTime = sf::milliseconds(0);
	}

	if (event.type == sf::Event::MouseMoved)
	{
		// Waiting for update: https://github.com/LaurentGomila/SFML/pull/396
		int current_x = sf::Mouse::getPosition(window).x, current_y = sf::Mouse::getPosition(window).y;
		int elapsed_x = (window.getView().getSize().x / 2) - current_x, elapsed_y = (window.getView().getSize().y / 2) - current_y;

		if (elapsed_x != 0 || elapsed_y != 0)
		{

			//###################################//
			//#####Mouse Movement Handleing######//
			//###################################//
			//## X axis
			if (sprite->getPosition().x > 0 && sprite->getPosition().x < window.getView().getSize().x)
			{
				sprite->move(-elapsed_x, 0);
			}

			// ## Y axis
			if (sprite->getPosition().y > 0 && sprite->getPosition().y < (window.getView().getSize().y + window.getView().getSize().y))
			{
				sprite->move(0, -elapsed_y);
			}

			sf::Mouse::setPosition(sf::Vector2i((window.getView().getSize().x / 2), (window.getView().getSize().y / 2)), window);
		}
	}
}