コード例 #1
0
void GameAsteroid::CalculateParameters(bool moveToCenter, Vector3 direction, float randomMuliplier)
{
    Vector2 toCenter = Vector2Make(0, 0);
    Vector2 center = _delegate->FieldCenter();
    if (moveToCenter) {
        Vector2 position = GetPosition();
        toCenter = Vector2Subtract(center, position);
        toCenter = Vector2Normalize(toCenter);
    }
    Vector2 random = Vector2Make(cosf(_random), sinf(_random));
    
    
    _moveVector = Vector3Make(toCenter.x * 2.0 + random.x *randomMuliplier + direction.x  , toCenter.y * 2.0 + random.y * randomMuliplier + direction.y, 0);
    
    float timex = center.x / _moveVector.x;
    float timey = center.y / _moveVector.y;
    float time = ____max(timey, timex) / 7;
    _existTimer = new MAXAnimationWait(time);
    _existTimer->_delegate = this;
    MAXAnimationManager::SharedAnimationManager()->AddAnimation(_existTimer);
    
}
コード例 #2
0
ファイル: Vector2.cpp プロジェクト: Vincent7/CocoaSampleCode
Math::Vector2<float>  Math::norml(const  float &e,
								  const Math::Vector2<float>  &v)
{
    return Vector2Normalize(e, v);
} // norml
コード例 #3
0
ファイル: Vector2.cpp プロジェクト: Vincent7/CocoaSampleCode
Math::Vector2<float>  Math::norml(const Math::Vector2<float>  &v)
{
    return Vector2Normalize(float(1e-7), v);
} // Vector2Normalize
コード例 #4
0
ファイル: Vector2.cpp プロジェクト: Vincent7/CocoaSampleCode
Math::Vector2<double> Math::norml(const Math::Vector2<double> &v)
{
    return Vector2Normalize(1e-7, v);
} // norml
コード例 #5
0
ファイル: Vector2.cpp プロジェクト: Vincent7/CocoaSampleCode
Math::Vector2<double> Math::norml(const double &e,
								  const Math::Vector2<double> &v)
{
    return Vector2Normalize(e, v);
} // norml
コード例 #6
0
ファイル: Game.cpp プロジェクト: m1h4/Xetrix
bool UpdateGame(void)
{
	Matrix2 orientation(gameShip.m_orientation);

	Vector2 gravity(0.0f,-0.004f);

	//gameShip.AddBodyForce(gravity);

	float k = 0.001f;

	if(debugSpring1)
	{
		Vector2 force = gameSpring1 - (gameShip.m_position + orientation * gameAnchor1);
		gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor1);
	}
	
	if(debugSpring2)
	{
		Vector2 force = gameSpring2 - (gameShip.m_position + orientation * gameAnchor2);
		gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor2);
	}

	if(HIWORD(GetAsyncKeyState(VK_LEFT)))
	{
		gameShip.m_rearEngineOrientation += GetElapsedTime() / 50.0f;
		gameShip.m_frontEngineOrientation += GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState(VK_RIGHT)))
	{
		gameShip.m_rearEngineOrientation -= GetElapsedTime() / 50.0f;
		gameShip.m_frontEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('B')))
	{
		gameShip.m_mainEngineOrientation += GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('N')))
	{
		gameShip.m_mainEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_frontEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.002f),gameShip.m_position + orientation * gameShip.m_frontEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_frontEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_SPACE)))
	{
		Matrix2 rotation(gameShip.m_mainEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.004f),gameShip.m_position + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_rearEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.001f),gameShip.m_position + orientation * gameShip.m_rearEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_rearEnginePosition);
	}
	
	gameShip.UpdateBody();
	gameEmitter.UpdateParticles();

	for(unsigned long i = 0; i < gameMissles.GetSize(); ++i)
	{
		Matrix2 orientation(gameMissles[i]->m_orientation);

		gameMissles[i]->AddBodyForce(gravity);

		Vector2 target = Matrix2(-gameMissles[i]->m_orientation) * (gameMissles[i]->m_target - gameMissles[i]->m_position);

		bool left = false,right = false;

		if(gameMissles[i]->m_life > 50.0f)
		{
			if(target.x > -0.1f && target.x < 0.1f && target.y > 0)
				left = right = true;
			else if(target.x < 0)
				right = true;
			else
				left = true;
		}
		
		if(left)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
		}

		if(right)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[1]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]);
		}

		gameMissles[i]->UpdateBody();
		gameMissles[i]->m_life += GetElapsedTime();

		if(gameMissles[i]->m_spring)
		{
			Vector2 force = *gameMissles[i]->m_spring - gameMissles[i]->m_position;
			gameMissles[i]->AddBodyForce(force * k);
		}

		if(gameMissles[i]->m_life > 1500.0f || target.GetLength() < 0.4f)
		{
			for(unsigned long j = 0; j < 256; ++j)
				gameEmitter.AddParticle(Vector2Normalize(Vector2(randf(),randf())) * randf() / 6.0f,gameMissles[i]->m_position);

			delete gameMissles[i];
			gameMissles.Erase(i);

			--i;
		}
	}

	return true;
}