当前位置: 首页>>代码示例>>C++>>正文


C++ Projectile::calculateTrajectory方法代码示例

本文整理汇总了C++中Projectile::calculateTrajectory方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::calculateTrajectory方法的具体用法?C++ Projectile::calculateTrajectory怎么用?C++ Projectile::calculateTrajectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Projectile的用法示例。


在下文中一共展示了Projectile::calculateTrajectory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

void ProjectileFlyBState::init()
{
	_parent->setStateInterval(DEFAULT_BULLET_SPEED);
	_unit = _parent->getGame()->getSavedGame()->getBattleGame()->getSelectedUnit();
	// create a new projectile
	Projectile *projectile = new Projectile(_parent->getGame()->getResourcePack(),
									_parent->getGame()->getSavedGame()->getBattleGame(),
									_unit->getPosition(),
									_parent->getTarget(),
									_parent->getSelectedItem()->getRules()->getBulletSprite()
									);
	// add the projectile on the map
	_parent->getMap()->setProjectile(projectile);
	// let it calculate a trajectory
	if (projectile->calculateTrajectory())
	{
		// set the soldier in an aiming position
		_unit->aim(true);
		_parent->getMap()->cacheUnits();
		// and we have a lift-off
		_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_parent->getSelectedItem()->getRules()->getFireSound())->play();
	}
	else
	{
		// no line of fire
		delete projectile;
		_parent->getMap()->setProjectile(0);
		_parent->popState();
	}

}
开发者ID:gpin,项目名称:OpenXcom,代码行数:31,代码来源:ProjectileFlyBState.cpp

示例2: createNewProjectile

/**
 * - create a projectile sprite & add it to the map
 * - calculate it's trajectory
 * @return whether it succeeded
 */
bool ProjectileFlyBState::createNewProjectile()
{
	// create a new projectile
	Projectile *projectile = new Projectile(_parent->getResourcePack(), _parent->getSave(), _action, _origin);

	_autoshotCounter++;
	// add the projectile on the map
	_parent->getMap()->setProjectile(projectile);
	_parent->setStateInterval(Options::getInt("battleFireSpeed"));

	// let it calculate a trajectory
	_projectileImpact = -1;
	if (_action.type == BA_THROW)
	{
		if (projectile->calculateThrow(_unit->getThrowingAccuracy()))
		{
			_projectileItem->moveToOwner(0);
			_unit->setCache(0);
			_parent->getMap()->cacheUnit(_unit);
			_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(39)->play();
			_unit->addThrowingExp();
		}
		else
		{
			// unable to throw here
			delete projectile;
			_parent->getMap()->setProjectile(0);
			_action.result = "STR_UNABLE_TO_THROW_HERE";
			_parent->popState();
			return false;
		}
	}
	else if (_unit->getType() == "CELATID") // special code for the "spit" trajectory
	{
		if (projectile->calculateThrow(_unit->getFiringAccuracy(_action.type, _action.weapon)))
		{
			// set the soldier in an aiming position
			_unit->aim(true);
			_parent->getMap()->cacheUnit(_unit);
			// and we have a lift-off
			if (_action.weapon->getRules()->getFireSound() != -1)
				_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_action.weapon->getRules()->getFireSound())->play();
		}
		else
		{
			// no line of fire
			delete projectile;
			_parent->getMap()->setProjectile(0);
			_action.result = "STR_NO_LINE_OF_FIRE";
			_parent->popState();
			return false;
		}
	}
	else
	{
		_projectileImpact = projectile->calculateTrajectory(_unit->getFiringAccuracy(_action.type, _action.weapon));
		if (_projectileImpact != -1 || _action.type == BA_LAUNCH)
		{
				// set the soldier in an aiming position
				_unit->aim(true);
				_parent->getMap()->cacheUnit(_unit);
				// and we have a lift-off
				if (_action.weapon->getRules()->getFireSound() != -1)
					_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_action.weapon->getRules()->getFireSound())->play();
				if (!_parent->getSave()->getDebugMode() && _action.type != BA_LAUNCH && _ammo->spendBullet() == false)
				{
					_parent->getSave()->removeItem(_ammo);
					_action.weapon->setAmmoItem(0);
				}
		}
		else
		{
			// no line of fire
			delete projectile;
			_parent->getMap()->setProjectile(0);
			_action.result = "STR_NO_LINE_OF_FIRE";
			_parent->popState();
			return false;
		}
	}

	return true;
}
开发者ID:Shugyousha,项目名称:OpenXcom,代码行数:88,代码来源:ProjectileFlyBState.cpp


注:本文中的Projectile::calculateTrajectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。