Danbias/Code/Game/GameLogic/Player.cpp

138 lines
3.0 KiB
C++
Raw Normal View History

2013-11-19 11:07:14 +01:00
#include "Player.h"
2013-11-25 11:03:06 +01:00
#include "OysterMath.h"
#include "CollisionManager.h"
2013-12-05 11:50:39 +01:00
#include "Weapon.h"
2013-11-25 11:03:06 +01:00
2013-11-19 11:07:14 +01:00
using namespace GameLogic;
2013-11-25 11:03:06 +01:00
using namespace Oyster::Physics;
2013-11-19 11:07:14 +01:00
2013-12-05 11:50:39 +01:00
struct Player::PrivateData
2013-11-19 11:07:14 +01:00
{
2013-12-05 11:50:39 +01:00
PrivateData()
{
weapon = new Weapon();
life = 100;
playerState = PLAYER_STATE_IDLE;
2013-12-05 11:50:39 +01:00
}
2013-12-05 11:50:39 +01:00
~PrivateData()
{
if (weapon)
{
delete weapon;
}
}
2013-12-05 11:50:39 +01:00
int life;
Weapon *weapon;
PLAYER_STATE playerState;
Oyster::Math::Float3 lookDir;
2013-12-10 11:17:25 +01:00
2013-12-05 11:50:39 +01:00
}myData;
Player::Player()
:Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER)
2013-12-05 11:50:39 +01:00
{
myData = new PrivateData();
2013-11-19 11:07:14 +01:00
}
2013-11-19 11:07:14 +01:00
Player::~Player(void)
{
2013-12-05 11:50:39 +01:00
delete myData;
2013-11-21 12:05:39 +01:00
}
2013-11-29 09:05:01 +01:00
/********************************************************
* Updates the player(is this function needed?)
********************************************************/
2013-12-05 11:50:39 +01:00
void Player::Update()
2013-11-21 12:05:39 +01:00
{
2013-12-05 11:50:39 +01:00
2013-11-21 12:05:39 +01:00
}
/********************************************************
* Moves the player based on client input
* Uses the physics to move the player by adding a force in the chosen direction
* Uses the Jump() function if the player is to jump, this is becuase jumping requires additional logic compared to normal movement
********************************************************/
void Player::Move(const PLAYER_MOVEMENT &movement)
2013-11-21 12:05:39 +01:00
{
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
switch(movement)
{
case PLAYER_MOVEMENT_FORWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
break;
case PLAYER_MOVEMENT_BACKWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
break;
case PLAYER_MOVEMENT_LEFT:
break;
case PLAYER_MOVEMENT_RIGHT:
break;
case PLAYER_MOVEMENT_JUMP:
Jump();
break;
}
}
/********************************************************
* Uses the players weapon based on user input
********************************************************/
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
{
myData->weapon->Use(fireInput);
2013-11-21 12:05:39 +01:00
}
/********************************************************
* Jumps if the player is currently not in a state of jumping
* Applies a force upwards(current upwards)
********************************************************/
void Player::Jump()
{
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
}
bool Player::IsWalking()
{
return (myData->playerState == PLAYER_STATE_WALKING);
}
bool Player::IsJumping()
{
return (myData->playerState == PLAYER_STATE_JUMPING);
}
bool Player::IsIdle()
{
return (myData->playerState == PLAYER_STATE_IDLE);
}
2013-12-10 11:17:25 +01:00
Oyster::Math::Float3 Player::GetPos()
{
return rigidBody->GetCenter();
2013-12-10 11:17:25 +01:00
}
Oyster::Math::Float3 Player::GetLookDir()
{
return myData->lookDir;
}
/********************************************************
* Respawns the player on a new chosen position
* This resets a set of variables such as life, ammo etcetc
********************************************************/
void Player::Respawn()
2013-11-21 12:05:39 +01:00
{
2013-11-19 11:07:14 +01:00
}
void Player::DamageLife(int damage)
{
myData->life -= damage;
}