project2D/turret.cpp
//--------------------------------------------------------------------------------------
// Update: A virtual function from entity to update objects.
//
// Param:
//		deltaTime: Pass in deltaTime. A number that updates per second.
//--------------------------------------------------------------------------------------
A virtual function from entity to update objects.
Param:
deltaTime: Pass in deltaTime. A number that updates per second.
A virtual function from entity to update objects . Param : deltaTime : Pass in deltaTime . A number that updates per second .
void turret::Update(float deltaTime)
{
	Input* input = Input::getInstance();
	Matrix3 rottemp;
	float rot = 0;
	if (input->isKeyDown(INPUT_KEY_E))
		rot = rotSpeed * deltaTime;
	if (input->isKeyDown(INPUT_KEY_Q))
		rot = -rotSpeed * deltaTime;
	if (input->wasKeyPressed(INPUT_KEY_SPACE))
	{
		Vector3 dir1 = GlobalTrasform[1];
		bullets[bulletCount]->SetDir(CastTo<Vector2>(dir1));
		bullets[bulletCount]->SetPosition(GetPosition().x, GetPosition().y);
		++bulletCount;
		if (bulletCount >= 15)
		{
			bulletCount = 0;
		}
	}
	if (input->isKeyDown(INPUT_KEY_LEFT_SHIFT))
	{
		antenna->LocalToGlobal();
		antenna->setParent(nullptr);
	}
	if (input->isKeyDown(INPUT_KEY_RIGHT_SHIFT))
	{
		antenna->NewMatrix();
		antenna->setParent(this);
	}
	for (int i = 0; i < 15; i++)
	{
		bullets[i]->Update(deltaTime);
	}
	rottemp.setRotateZ(rot);
	localTransform = localTransform * rottemp;
	updateGlobalTransform();
	antenna->Update(deltaTime);
}
void turret :: Update ( float deltaTime ) { Input * input = Input :: getInstance ( ) ; Matrix3 rottemp ; float rot = 0 ; if ( input -> isKeyDown ( INPUT_KEY_E ) ) rot = rotSpeed * deltaTime ; if ( input -> isKeyDown ( INPUT_KEY_Q ) ) rot = - rotSpeed * deltaTime ; if ( input -> wasKeyPressed ( INPUT_KEY_SPACE ) ) { Vector3 dir1 = GlobalTrasform [ 1 ] ; bullets [ bulletCount ] -> SetDir ( CastTo < Vector2 > ( dir1 ) ) ; bullets [ bulletCount ] -> SetPosition ( GetPosition ( ) . x , GetPosition ( ) . y ) ; ++ bulletCount ; if ( bulletCount >= 15 ) { bulletCount = 0 ; } } if ( input -> isKeyDown ( INPUT_KEY_LEFT_SHIFT ) ) { antenna -> LocalToGlobal ( ) ; antenna -> setParent ( nullptr ) ; } if ( input -> isKeyDown ( INPUT_KEY_RIGHT_SHIFT ) ) { antenna -> NewMatrix ( ) ; antenna -> setParent ( this ) ; } for ( int i = 0 ; i < 15 ; i ++ ) { bullets [ i ] -> Update ( deltaTime ) ; } rottemp . setRotateZ ( rot ) ; localTransform = localTransform * rottemp ; updateGlobalTransform ( ) ; antenna -> Update ( deltaTime ) ; }
Update: A virtual function from entity to update objects.
Update : A virtual function from entity to update objects .
// A new instance of Input. // Create a temp rot float and Maxtrix. // Rotate the turret on these key presses. // Fire the turret. Fires Bullets. // Move the bullet. // If the bullket count get to 15 reset it. // Decouple the hierarchy  between turret and antenna. // Couple the hierarchy  between turret and antenna. // Update each bullet. // Set the rotation and update the local and global transform for turret. // Update the antenna.