project2D/Player.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 Player::Update(float deltaTime)
{
	Input* input = Input::getInstance();
	Vector2 pos;
	Matrix3 temp;
	Matrix3 rottemp;
	float rot = 0;
	if (input->isKeyDown(INPUT_KEY_W))
		pos.y = 150 * deltaTime;
	if (input->isKeyDown(INPUT_KEY_S))
		pos.y = -150 * deltaTime;
	if (input->isKeyDown(INPUT_KEY_A))
		rot = rotSpeed * deltaTime;
	if (input->isKeyDown(INPUT_KEY_D))
		rot = -rotSpeed * deltaTime;
	rottemp.setRotateZ(rot);
	temp.setPostionv(pos);
	localTransform = localTransform * rottemp;
	localTransform = localTransform * temp;
	updateGlobalTransform();
	boundingBox.MoveTo(CastTo<Vector3>(GetPosition()));
	boundingBox.RotateBy(rottemp);
	Turret->Update(deltaTime);
	CollisionManager* pCollision = CollisionManager::GetInstance();
	Entity* colliding = pCollision->TestBoxBoxCollision(this);
	if (colliding != nullptr && colliding->GetType() == WALL)
	{
		cout << "HIT!" << endl;
	}
}
void Player :: Update ( float deltaTime ) { Input * input = Input :: getInstance ( ) ; Vector2 pos ; Matrix3 temp ; Matrix3 rottemp ; float rot = 0 ; if ( input -> isKeyDown ( INPUT_KEY_W ) ) pos . y = 150 * deltaTime ; if ( input -> isKeyDown ( INPUT_KEY_S ) ) pos . y = -150 * deltaTime ; if ( input -> isKeyDown ( INPUT_KEY_A ) ) rot = rotSpeed * deltaTime ; if ( input -> isKeyDown ( INPUT_KEY_D ) ) rot = - rotSpeed * deltaTime ; rottemp . setRotateZ ( rot ) ; temp . setPostionv ( pos ) ; localTransform = localTransform * rottemp ; localTransform = localTransform * temp ; updateGlobalTransform ( ) ; boundingBox . MoveTo ( CastTo < Vector3 > ( GetPosition ( ) ) ) ; boundingBox . RotateBy ( rottemp ) ; Turret -> Update ( deltaTime ) ; CollisionManager * pCollision = CollisionManager :: GetInstance ( ) ; Entity * colliding = pCollision -> TestBoxBoxCollision ( this ) ; if ( colliding != nullptr && colliding -> GetType ( ) == WALL ) { cout << " " << endl ; } }
Update: A virtual function from entity to update objects.
Update : A virtual function from entity to update objects .
// A new instance of Input. // Set temp varibles for position and rotation // Move the player with WASD // Set the position and rotation and update the local and global transform. // Bind the boundingbox with the player. (for SAT collision.) // Update Turret. // Test Collision // Check if the Player is colliding with a wall // Debug message for console if the player hits a wall