コード例 #1
0
ファイル: ShipSystem.cpp プロジェクト: pokelege/GeometryWars
void ShipSystem::shot(BulletSystem& bullets, ParticleSystem& particles)
{
	for (unsigned int i = 0; i < numberofShips; i++)
	{
		for (unsigned int j = 0; j < bullets.getNumber(); j++)
		{
			if (shipList[i]->isShot(*(bullets.getlist()[j]), particles))
			{
				bullets.getlist()[j]->setLife(0);
			}
		}
	}
}
コード例 #2
0
	void BulletForceOperator::operateBulletEventSystem(Real timeElapsed)
	{
		BulletEventSystem::BulletSystemVecotor::iterator it =  m_parent->getActiveBulletSystem().begin();
		while(it != m_parent->getActiveBulletSystem().end())
		{
			BulletSystem* pBulletSystem = *it;
			if(pBulletSystem && pBulletSystem->getIsCreated() && !pBulletSystem->findBulletOperator(this))
			{

				Real fCumulateTime = pBulletSystem->getAge();

				TransformInfo info;
				info = pBulletSystem->getTransformInfo();

				Ogre::Vector3 vBulletPosition = info.mPosition;
				vBulletPosition += m_forceVector;

				info.mPosition = vBulletPosition;
				pBulletSystem->setTransformInfo(info);
				pBulletSystem->setPosition(info.mPosition);
				pBulletSystem->addBulletOperator(this);

			}
			it ++;
		}
	}
コード例 #3
0
	void BulletSwayOperator::operateBulletEventSystem(Real timeElapsed)
	{
		BulletEventSystem::BulletSystemVecotor::iterator it =  m_parent->getActiveBulletSystem().begin();
		while(it != m_parent->getActiveBulletSystem().end())
		{
			BulletSystem* pBulletSystem = *it;
			if(pBulletSystem && pBulletSystem->getIsCreated())
			{
                // 步骤:[6/2/2010 陈军龙]
				//      1.计算朝向 
				//      2.计算摇摆方向(与朝向垂直,且与地面平行) 
				//      3.将时间映射到曲线函数Sin (映射公式: (2 * PI) / (1 / Frequency) = x / Age  )
				//      4.更新子弹位置
                static Ogre::Vector3 startpos = pBulletSystem->getCurrentPosition();
				Ogre::Vector3 direction = pBulletSystem->getTargetPosition() - startpos;
				direction.normalise();

				Real fCumulateTime = pBulletSystem->getAge();
				Ogre::Vector2 swaydir(direction.z, -direction.x);
				Real offset = m_amplitude * Ogre::Math::Sin(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
				Ogre::Vector2 absoffset = swaydir * offset;

				TransformInfo info;
				info = pBulletSystem->getTransformInfo();
				Ogre::Vector3 vBulletPosition = info.mPosition;
				vBulletPosition.x += absoffset.x;
				vBulletPosition.z += absoffset.y;

				info.mPosition = vBulletPosition;
				pBulletSystem->setTransformInfo(info);
				pBulletSystem->setPosition(info.mPosition);
			}
			it ++;
		}
	}
コード例 #4
0
	// 此函数调用BulletSystemManager::createBulletSystem函数,另外BulletSystem
	// 由单独的BulletSystemManager管理,而不在BulletFlowSystemManager里面管理[1/23/2008 JiangWei]
	BulletSystem* BulletFlowSystem::addBulletSystem(const String& name)
	{
		if(m_targetModel == NULL || m_casterModel == NULL)
			return NULL;
		BulletSystem* pBulletSystemTemplate = 
			BulletSystemManager::getSingleton().getBulletSystemTemplate(name);
		if(pBulletSystemTemplate)
		{
			BulletSystem* pNewBulletSystem = new BulletSystem(name,m_system);

			*pNewBulletSystem = *pBulletSystemTemplate;
			pNewBulletSystem->Initial(m_targetModel, m_casterModel,m_AttachPointName,m_TargetPointName,
				m_OffsetPos,m_OffsetRoation);
			m_bulletSystems.push_back(pNewBulletSystem);
			return pNewBulletSystem;
		}
		return NULL;
	}
コード例 #5
0
ファイル: Turret.cpp プロジェクト: pokelege/GeometryWars
void Turret::fire(const float& dt, BulletSystem& Bsystem, const Vector2& parentPosition)
{

	Bsystem.addBullet(
		new Bullet(parentPosition,
		Matrix2::rotation(rand.RandomRangedFloat(-accuracy, accuracy)) * (rotationNormal * (bulletVelocity * dt)),
		BULLETCOLOR,
		0.5,
		3));
	cool = coolDown;
}
コード例 #6
0
	void BulletFlowSystem::update(Real time)
	{

		BulletEventMap::iterator event_it = m_bulletEventSystemMap.begin();
		while( event_it != m_bulletEventSystemMap.end())
		{
			if(event_it->second)
				event_it->second->update(time);
			event_it++;
		}
		BulletSystemVector::iterator it = m_bulletSystems.begin();
		while( it != m_bulletSystems.end())
		{
			BulletSystem* pBulletSystem = *it;
			if(pBulletSystem)
			{
				pBulletSystem->update(time);
			}
			it++;
		}
		integrateBulletSystemTransform(time);
		m_age += time;
	}
コード例 #7
0
	void BulletSpeedOperator::operateBulletEventSystem(Real timeElapsed)
	{
		BulletEventSystem::BulletSystemVecotor::iterator it =  m_parent->getActiveBulletSystem().begin();
		while(it != m_parent->getActiveBulletSystem().end())
		{
			BulletSystem* pBulletSystem = *it;
			if(pBulletSystem && pBulletSystem->getIsCreated())
			{

				Real fCumulateTime = pBulletSystem->getAge();

				TransformInfo info;
				info = pBulletSystem->getTransformInfo();
				Ogre::Vector3 vDirection = m_direction.normalisedCopy();
				Ogre::Vector3 vBulletPosition = info.mPosition;
				vBulletPosition += vDirection*m_speed*pBulletSystem->getDelta();

				info.mPosition = vBulletPosition;
				pBulletSystem->setTransformInfo(info);
				pBulletSystem->setPosition(info.mPosition);
			}
			it ++;
		}
	}
コード例 #8
0
void BulletHelixOperator::operateBulletEventSystem(Real timeElapsed)
{
    BulletEventSystem::BulletSystemVecotor::iterator it =  m_parent->getActiveBulletSystem().begin();
    while(it != m_parent->getActiveBulletSystem().end())
    {
        BulletSystem* pBulletSystem = *it;
        if(pBulletSystem && pBulletSystem->getIsCreated())
        {
            // 步骤:[6/2/2010 陈军龙]
            //      1.计算朝向
            //      2.将时间映射到曲线函数Sin (映射公式: (2 * PI) / (1 / Frequency) = x / Age  )
            //      3.计算绕螺旋的旋转轴的旋转偏移量
            //        (绕任意轴旋转公式:v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
            //        其中的 。代表点乘 * 代表叉乘,v是要旋转的向量,n是旋转轴,x是旋转的角度)
            //      4.根据到目标的百分比设置振幅,更新子弹位置
            static Ogre::Vector3 startpos = pBulletSystem->getCurrentPosition();
            Ogre::Vector3 direction = pBulletSystem->getTargetPosition() - startpos;
            direction.normalise();

            Real fCumulateTime = pBulletSystem->getAge();
            Real sinvalue = Ogre::Math::Sin(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
            Real cosvalue = Ogre::Math::Cos(fCumulateTime * Ogre::Math::TWO_PI * m_frequency);
            Ogre::Vector3 absoffset, vdelta;
            vdelta = Ogre::Vector3::UNIT_Y;//此次设置为Y轴,也可以设置为其它
            // v' = (v - (v 。n) 。n) * cosx + (v * n) * sinx + (v 。n)。n
            absoffset = (vdelta - (vdelta.dotProduct(direction)) * direction) * cosvalue
                        + (vdelta.crossProduct(direction)) * sinvalue
                        + (vdelta.dotProduct(direction)) *direction;

            Real oridistance = startpos.distance(pBulletSystem->getTargetPosition());
            Real curdistance = pBulletSystem->getCurrentPosition().distance(pBulletSystem->getTargetPosition());
            Real percent = Ogre::Math::RealEqual(oridistance, 0) ? 1 : curdistance/oridistance;

            TransformInfo info;
            info = pBulletSystem->getTransformInfo();
            Ogre::Vector3 vBulletPosition = info.mPosition;
            vBulletPosition += (m_amplitude * absoffset * percent);

            info.mPosition = vBulletPosition;
            pBulletSystem->setTransformInfo(info);
            pBulletSystem->setPosition(info.mPosition);
        }
        it ++;
    }
}
コード例 #9
0
ファイル: Main.cpp プロジェクト: Petric837/geometryGame
int main()
{
	sf::Clock clock;
	sf::RenderWindow window(sf::VideoMode(1280, 720), "Game");
	window.setFramerateLimit(70);

	sf::Texture backgroundImg;
	backgroundImg.loadFromFile("pics/background.jpg");
	backgroundImg.setSmooth(true);
	sf::Sprite background;
	background.setTexture(backgroundImg);

	Player player;
	BulletSystem bulletSystem;
	EnemyControl enemyControl;
	ThrustAnim thrustAnimation;
	CollisionDetection collisionDetection;

	const float desiredFrametime = 1000 / 60;
	const int maxSteps = 6;

	sf::Time prevTicks = clock.getElapsedTime();

	while (window.isOpen())
	{
		sf::Time newTicks = clock.getElapsedTime();
		sf::Time frameTime = newTicks - prevTicks;
		prevTicks = newTicks;

		float totalDeltaTime = frameTime.asMilliseconds() / desiredFrametime;

		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}

		window.clear();

		window.draw(background);

		int i = 0;
		while (totalDeltaTime > 0.0f && i < maxSteps) {

			float deltaTime = std::min(totalDeltaTime, 1.0f);

			collisionDetection.detect(player, bulletSystem, enemyControl);
			bulletSystem.run(window, player, deltaTime);
			player.controlSystem(deltaTime);
			enemyControl.run(player, deltaTime);
			thrustAnimation.run(player, deltaTime);

			totalDeltaTime -= deltaTime;
			i++;
		}

		bulletSystem.draw(window);
		thrustAnimation.draw(window);
		player.draw(window);
		enemyControl.draw(window);

		window.display();
	}

	return 0;
}