Danbias/Code/Game/GameLogic/Player.cpp

160 lines
3.8 KiB
C++
Raw Normal View History

#include "Player.h"
#include "Weapon.h"
2014-01-20 15:47:52 +01:00
#include "CollisionManager.h"
#include "Game.h"
using namespace GameLogic;
using namespace Oyster::Physics;
Player::Player()
:DynamicObject(Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
{
weapon = new Weapon();
life = 100;
teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
2014-01-16 12:26:14 +01:00
lookDir = Oyster::Math::Float4(0,0,-1,0);
2014-01-21 14:28:27 +01:00
setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1));
setState.SetReach(Oyster::Math::Float4(2,3.5,2,0));
2014-01-27 13:56:31 +01:00
//setState.SetRotation(Oyster::Math::Float4(0,0,0,0).Normalize());
2014-01-27 08:54:25 +01:00
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
2014-01-27 13:56:31 +01:00
:DynamicObject(rigidBody, collisionFunc, type)
2014-01-27 08:54:25 +01:00
{
2014-01-27 13:56:31 +01:00
}
Player::~Player(void)
{
delete weapon;
weapon = NULL;
}
void Player::Move(const PLAYER_MOVEMENT &movement)
{
switch(movement)
{
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
MoveForward();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD:
MoveBackwards();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT:
MoveLeft();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT:
MoveRight();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP:
Jump();
break;
}
}
void Player::MoveForward()
{
2014-01-21 14:28:27 +01:00
setState.ApplyLinearImpulse(this->lookDir * (20 * this->gameInstance->GetFrameTime()));
}
void Player::MoveBackwards()
{
2014-01-21 14:28:27 +01:00
setState.ApplyLinearImpulse(-this->lookDir * 20 * this->gameInstance->GetFrameTime());
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
2014-01-27 13:56:31 +01:00
// temp up vector
2014-01-16 12:26:14 +01:00
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
2014-01-21 14:28:27 +01:00
setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime());
2014-01-16 12:26:14 +01:00
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
2014-01-27 13:56:31 +01:00
// temp up vector
2014-01-16 12:26:14 +01:00
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
2014-01-20 15:47:52 +01:00
//Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero
2014-01-21 14:28:27 +01:00
setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime());
}
2014-01-16 11:17:19 +01:00
void Player::UseWeapon(const WEAPON_FIRE &usage)
{
this->weapon->Use(usage,gameInstance->GetFrameTime());
}
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
{
this->life = 100;
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
this->lookDir = Oyster::Math::Float4(1,0,0);
}
2014-01-27 13:56:31 +01:00
void Player::Rotate(const Oyster::Math3D::Float3 lookDir)
{
2014-01-27 13:56:31 +01:00
this->lookDir = lookDir;
Oyster::Math::Float4 up(0,1,0,0);//-setState.GetGravityNormal();
Oyster::Math::Float4 pos = setState.GetCenterPosition();
Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz);
// cant set rotation
//setState.SetOrientation(world);
//this->lookDir = lookDir - up.xyz;
2014-01-23 08:24:35 +01:00
//this->setState.AddRotation(Oyster::Math::Float4(x, y));
//this->setState.SetRotation();
}
void Player::Jump()
{
}
bool Player::IsWalking()
{
return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
}
bool Player::IsJumping()
{
return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
}
bool Player::IsIdle()
{
return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
}
Oyster::Math::Float3 Player::GetPosition() const
{
return (Oyster::Math::Float3)getState.GetCenterPosition();
}
2014-01-16 12:26:14 +01:00
Oyster::Math::Float4x4 Player::GetOrientation() const
{
return this->getState.GetOrientation();
}
Oyster::Math::Float3 Player::GetLookDir() const
{
return this->lookDir.xyz;
}
int Player::GetTeamID() const
{
return this->teamID;
}
PLAYER_STATE Player::GetState() const
{
return this->playerState;
}
void Player::DamageLife(int damage)
{
this->life -= damage;
}