2014-01-09 12:51:17 +01:00
|
|
|
#include "Player.h"
|
|
|
|
#include "OysterMath.h"
|
|
|
|
#include "CollisionManager.h"
|
|
|
|
#include "Weapon.h"
|
|
|
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
using namespace Oyster::Physics;
|
|
|
|
|
|
|
|
struct Player::PrivateData
|
|
|
|
{
|
|
|
|
PrivateData()
|
|
|
|
{
|
|
|
|
weapon = new Weapon();
|
|
|
|
|
|
|
|
life = 100;
|
|
|
|
teamID = -1;
|
|
|
|
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
|
|
|
|
|
2014-01-10 10:08:42 +01:00
|
|
|
lookDir = Oyster::Math::Float4(1,0,0,0);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~PrivateData()
|
|
|
|
{
|
|
|
|
if (weapon)
|
|
|
|
{
|
|
|
|
delete weapon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int life;
|
|
|
|
int teamID;
|
|
|
|
Weapon *weapon;
|
|
|
|
PLAYER_STATE playerState;
|
2014-01-09 13:06:18 +01:00
|
|
|
Oyster::Math::Float4 lookDir;
|
2014-01-09 12:51:17 +01:00
|
|
|
|
|
|
|
}myData;
|
|
|
|
|
|
|
|
Player::Player()
|
|
|
|
:Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
|
|
|
|
{
|
|
|
|
myData = new PrivateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
Player::~Player(void)
|
|
|
|
{
|
|
|
|
delete myData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-10 10:08:42 +01:00
|
|
|
state.ApplyLinearImpulse(myData->lookDir * 100);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveBackwards()
|
|
|
|
{
|
2014-01-10 10:08:42 +01:00
|
|
|
state.ApplyLinearImpulse(-myData->lookDir * 100);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveRight()
|
|
|
|
{
|
|
|
|
//Do cross product with forward vector and negative gravity vector
|
2014-01-09 13:06:18 +01:00
|
|
|
Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir);
|
2014-01-10 10:08:42 +01:00
|
|
|
state.ApplyLinearImpulse(r * 100);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveLeft()
|
|
|
|
{
|
|
|
|
//Do cross product with forward vector and negative gravity vector
|
2014-01-09 13:06:18 +01:00
|
|
|
Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir);
|
2014-01-10 10:08:42 +01:00
|
|
|
state.ApplyLinearImpulse(-r * 100);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:33:04 +01:00
|
|
|
void Player::UseWeapon(const WEAPON_FIRE &Usage)
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-01-10 12:33:04 +01:00
|
|
|
myData->weapon->Use(Usage);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
|
|
|
|
{
|
2014-01-10 10:08:42 +01:00
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
myData->life = 100;
|
|
|
|
myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
|
2014-01-09 13:06:18 +01:00
|
|
|
myData->lookDir = Oyster::Math::Float4(1,0,0);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Jump()
|
|
|
|
{
|
2014-01-10 10:08:42 +01:00
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::IsWalking()
|
|
|
|
{
|
|
|
|
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
|
|
|
|
}
|
|
|
|
bool Player::IsJumping()
|
|
|
|
{
|
|
|
|
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
|
|
|
|
}
|
|
|
|
bool Player::IsIdle()
|
|
|
|
{
|
|
|
|
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Oyster::Math::Float3 Player::GetPos()
|
|
|
|
{
|
2014-01-10 10:08:42 +01:00
|
|
|
return (Oyster::Math::Float3)state.GetCenterPosition();
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Oyster::Math::Float3 Player::GetLookDir()
|
|
|
|
{
|
2014-01-13 12:44:33 +01:00
|
|
|
return myData->lookDir.xyz;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Player::GetTeamID()
|
|
|
|
{
|
|
|
|
return myData->teamID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::DamageLife(int damage)
|
|
|
|
{
|
|
|
|
myData->life -= damage;
|
|
|
|
}
|