Example #1
0
//------------------------------------------------------------------------------
void Actor::attack()
{
	Weapon w = getWeapon();
  if( w.canFire() )
  {
    Projectile* p = w.fire( getAimingDirection() ); 
    p->setPosition( getPosition() );
    mpEngine->addProjectile( p );
    
    setWeapon( w );
  }
}
Example #2
0
void Ship::fire(int weaponIndex)
{
	if (weaponIndex >= 0 && weaponIndex < (int)weapons_.size())
	{
		transform_->getMatrix(weaponTransformation_, false);

		//keeping weapon's local direction
		Weapon* weapon = weapons_[weaponIndex].first;
		weapon->currentDirection = weapon->direction;
		weapon->currentDirection.rotateVector(weaponTransformation_);

		//keeping weapon's local position
		Vector3 weaponPos = weapons_[weaponIndex].second;
		weaponPos.rotateVector(weaponTransformation_);
		weapon->position = transform_->getPosition() + weaponPos;

		weapon->fire();
	}
	else
		Logger::PrintWarning("Ship::fire - invalid argument\n");
}
Example #3
0
//---------------------------------------------------------------------------
void Avatar::fireWeaponGroup(int /*groupId*/)
{
	// for now, fire everything
	ComponentList list;
	findComponents(EquipmentSlotComponent::getClassDef(), list);
	for (ComponentList::iterator it = list.begin(); it != list.end(); ++it)
	{
		EquipmentSlotComponent* pSlot = static_cast<EquipmentSlotComponent*>(*it);
		if (pSlot)
		{
			size_t numEquipment = pSlot->getNumEquipment();
			for (size_t i=0; i<numEquipment; ++i)
			{
				Mountable* pMountable = pSlot->getEquipment(i);
				if (pMountable && pMountable->isOfType(Weapon::getClassDef()))
				{
					Weapon* pWeapon = static_cast<Weapon*>(pMountable);
					pWeapon->fire();
				}
			}
		}
	}
}
////////////////////////////////////////////////////////////
///Entrypoint of application 
//////////////////////////////////////////////////////////// 
void CheckForInput(float &x, float &y, bool & isSpace, bool &isLeft, bool &isRight, bool &isUp, bool &isDown, bool &isSwitch, Weapon& myWeapon)
{
	//simple input used for testing
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && !isSpace)
	{
		isSpace = true;
		myWeapon.fire(Vector2D(x, y), Vector2D(400, 300));
	}
	else
	{
		isSpace = false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && !isLeft)
	{
		isLeft = true;
		x -= 5;
	}
	else
	{
		isLeft = false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && !isRight)
	{
		isRight = true;
		x += 5;
	}
	else
	{
		isRight = false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && !isUp)
	{
		isUp = true;
		y += 5;
	}
	else
	{
		isUp = false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && !isDown)
	{
		isDown = true;
		y -= 5;
	}
	else
	{
		isDown = false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S) && !isSwitch)
	{
		isSwitch = true;
		myWeapon.switchWeapon();
		cout << "Switched weapon" << endl;
	}
	else
	{
		isSwitch = false;
	}

	cout << "XDir: " << x << endl;
	cout << "YDir: " << y << endl;
}