2014-01-15 11:03:25 +01:00
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
#include "Player.h"
|
|
|
|
#include "Weapon.h"
|
2014-01-20 15:47:52 +01:00
|
|
|
#include "CollisionManager.h"
|
|
|
|
#include "Game.h"
|
2014-01-09 12:51:17 +01:00
|
|
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
using namespace Oyster::Physics;
|
2014-02-27 15:13:08 +01:00
|
|
|
using namespace Oyster::Math;
|
|
|
|
|
2014-02-14 10:09:03 +01:00
|
|
|
const float MOVE_FORCE = 30;
|
2014-02-12 13:11:35 +01:00
|
|
|
const float KEY_TIMER = 0.03f;
|
2014-02-26 12:00:30 +01:00
|
|
|
const float AFFECTED_TIMER = 1.0f;
|
2014-01-09 12:51:17 +01:00
|
|
|
Player::Player()
|
2014-01-29 14:33:21 +01:00
|
|
|
:DynamicObject()
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-02-25 11:46:05 +01:00
|
|
|
Player::initPlayerData();
|
2014-02-25 12:12:24 +01:00
|
|
|
this->weapon = NULL;
|
2014-02-25 11:46:05 +01:00
|
|
|
this->teamID = -1;
|
2014-02-26 14:55:29 +01:00
|
|
|
this->playerScore.killScore = 0;
|
|
|
|
this->playerScore.deathScore = 0;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-02-12 14:48:58 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID)
|
|
|
|
:DynamicObject(rigidBody, EventOnCollision, type, objectID)
|
2014-01-29 14:33:21 +01:00
|
|
|
{
|
2014-02-25 12:12:24 +01:00
|
|
|
this->weapon = new Weapon(2,this);
|
2014-02-25 11:46:05 +01:00
|
|
|
Player::initPlayerData();
|
2014-02-14 12:03:29 +01:00
|
|
|
this->teamID = teamID;
|
2014-02-26 14:55:29 +01:00
|
|
|
this->playerScore.killScore = 0;
|
|
|
|
this->playerScore.deathScore = 0;
|
2014-01-27 08:54:25 +01:00
|
|
|
}
|
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID)
|
|
|
|
:DynamicObject(rigidBody, EventOnCollision, type, objectID)
|
2014-01-27 08:54:25 +01:00
|
|
|
{
|
2014-02-25 12:12:24 +01:00
|
|
|
this->weapon = new Weapon(2,this);
|
2014-02-25 11:46:05 +01:00
|
|
|
Player::initPlayerData();
|
2014-02-14 09:53:02 +01:00
|
|
|
this->teamID = teamID;
|
2014-02-26 14:55:29 +01:00
|
|
|
this->playerScore.killScore = 0;
|
|
|
|
this->playerScore.deathScore = 0;
|
2014-01-27 13:56:31 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
|
|
|
|
Player::~Player(void)
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
if(this->weapon)
|
2014-01-27 13:54:57 +01:00
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
delete this->weapon;
|
|
|
|
this->weapon = NULL;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
2014-02-25 11:46:05 +01:00
|
|
|
void Player::initPlayerData()
|
|
|
|
{
|
|
|
|
this->playerStats.hp = MAX_HP;
|
|
|
|
this->playerStats.movementSpeed = BASIC_SPEED;
|
|
|
|
this->playerState = PLAYER_STATE_IDLE;
|
|
|
|
this->lookDir = Oyster::Math::Float3(0,0,-1);
|
|
|
|
|
|
|
|
this->key_forward = 0;
|
|
|
|
this->key_backward = 0;
|
|
|
|
this->key_strafeRight = 0;
|
|
|
|
this->key_strafeLeft = 0;
|
|
|
|
this->key_jump = 0;
|
2014-02-26 12:00:30 +01:00
|
|
|
this->RecentlyAffected = 0;
|
2014-02-25 11:46:05 +01:00
|
|
|
this->deathTimer = 0;
|
|
|
|
|
|
|
|
this->rotationUp = 0;
|
2014-02-27 15:13:08 +01:00
|
|
|
|
|
|
|
ICustomBody::State state;
|
|
|
|
this->rigidBody->GetState( state );
|
|
|
|
state.staticFrictionCoeff = 0.0f;
|
|
|
|
state.dynamicFrictionCoeff = 0.0f;
|
|
|
|
this->rigidBody->SetState( state );
|
2014-02-25 11:46:05 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
void Player::BeginFrame()
|
|
|
|
{
|
2014-02-27 15:13:08 +01:00
|
|
|
if( !(this->playerState & (PLAYER_STATE_DEAD || PLAYER_STATE_DIED)) )
|
2014-02-21 15:42:09 +01:00
|
|
|
{
|
2014-02-27 15:13:08 +01:00
|
|
|
static const Float maxSpeed = 30;
|
2014-02-26 12:00:30 +01:00
|
|
|
weapon->Update(0.002f);
|
|
|
|
|
2014-02-21 15:42:09 +01:00
|
|
|
// Rotate player accordingly
|
2014-02-26 10:05:18 +01:00
|
|
|
this->rigidBody->AddRotationAroundY(this->rotationUp);
|
2014-02-21 15:42:09 +01:00
|
|
|
this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized());
|
2014-02-26 10:25:39 +01:00
|
|
|
this->rotationUp = 0;
|
2014-02-21 15:42:09 +01:00
|
|
|
// Direction data
|
|
|
|
Oyster::Math::Float4x4 xform;
|
|
|
|
xform = this->rigidBody->GetState().GetOrientation();
|
|
|
|
|
2014-02-27 15:13:08 +01:00
|
|
|
Oyster::Math::Float3 &forwardDir = xform.v[2].xyz;
|
|
|
|
Oyster::Math::Float3 &upDir = xform.v[1].xyz;
|
|
|
|
Oyster::Math::Float3 &rightDir = xform.v[0].xyz;
|
2014-02-21 15:42:09 +01:00
|
|
|
forwardDir.Normalize();
|
|
|
|
upDir.Normalize();
|
|
|
|
rightDir.Normalize();
|
|
|
|
|
|
|
|
// Previous velocities data
|
|
|
|
Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity();
|
|
|
|
Oyster::Math::Float3 forwardVelocity = linearVelocity*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z));
|
|
|
|
Oyster::Math::Float forwardSpeed = (linearVelocity*forwardDir).GetLength();
|
|
|
|
Oyster::Math::Float3 rightVelocity = linearVelocity*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z));
|
|
|
|
Oyster::Math::Float rightSpeed = (linearVelocity*rightDir).GetLength();
|
|
|
|
Oyster::Math::Float3 upVelocity = linearVelocity*Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z));
|
|
|
|
|
|
|
|
// Walking data
|
|
|
|
Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0);
|
2014-02-27 15:13:08 +01:00
|
|
|
Oyster::Math::Float &walkSpeed = this->playerStats.movementSpeed;
|
2014-02-21 15:42:09 +01:00
|
|
|
|
|
|
|
// Check for input
|
|
|
|
if(key_forward > 0.001)
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
key_forward -= gameInstance->GetFrameTime();
|
|
|
|
walkDirection += forwardDir;
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
if(key_backward > 0.001)
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
key_backward -= gameInstance->GetFrameTime();
|
|
|
|
walkDirection -= forwardDir;
|
|
|
|
}
|
|
|
|
if(key_strafeRight > 0.001)
|
|
|
|
{
|
|
|
|
key_strafeRight -= gameInstance->GetFrameTime();
|
|
|
|
walkDirection += rightDir;
|
|
|
|
}
|
|
|
|
if(key_strafeLeft > 0.001)
|
|
|
|
{
|
|
|
|
key_strafeLeft -= gameInstance->GetFrameTime();
|
|
|
|
walkDirection -= rightDir;
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 15:42:09 +01:00
|
|
|
// Dampen velocity if certain keys are not pressed
|
2014-02-26 10:05:18 +01:00
|
|
|
if(key_jump <= 0.001 && IsWalking())
|
2014-02-20 09:21:38 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
if(key_forward <= 0.001 && key_backward <= 0.001)
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
forwardVelocity *= Oyster::Math::Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z));
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
if(key_strafeRight <= 0.001 && key_strafeLeft <= 0.001)
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z));
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
2014-02-20 09:21:38 +01:00
|
|
|
}
|
2014-02-27 14:11:03 +01:00
|
|
|
if(IsIdle())
|
2014-02-25 16:08:45 +01:00
|
|
|
{
|
2014-02-27 14:11:03 +01:00
|
|
|
if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE)
|
|
|
|
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle);
|
|
|
|
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
|
2014-02-25 16:08:45 +01:00
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
// Walk if walkdirection is something
|
|
|
|
if(walkDirection != Oyster::Math::Float3::null)
|
2014-02-20 09:21:38 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
walkDirection.Normalize();
|
|
|
|
|
|
|
|
// If on the ground, accelerate normally
|
2014-02-26 10:05:18 +01:00
|
|
|
if(IsWalking())
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
if(forwardSpeed < maxSpeed)
|
|
|
|
{
|
|
|
|
forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed;
|
|
|
|
}
|
|
|
|
if(rightSpeed < maxSpeed)
|
|
|
|
{
|
|
|
|
rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), abs(rightDir.y), fabs(rightDir.z)) * walkSpeed;
|
|
|
|
}
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
// If in the air, accelerate slower
|
2014-02-26 10:05:18 +01:00
|
|
|
if(IsJumping())
|
2014-02-20 15:13:52 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
if(forwardSpeed < maxSpeed)
|
|
|
|
{
|
|
|
|
forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed*0.2f;
|
|
|
|
}
|
|
|
|
if(rightSpeed < maxSpeed)
|
|
|
|
{
|
|
|
|
rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f;
|
|
|
|
}
|
2014-02-20 15:13:52 +01:00
|
|
|
}
|
2014-02-27 14:11:03 +01:00
|
|
|
// TODO not suer if we want to keep jump animation while jumping
|
|
|
|
//if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
|
|
|
|
//{
|
2014-02-25 16:08:45 +01:00
|
|
|
if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING)
|
2014-02-26 09:11:45 +01:00
|
|
|
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk);
|
2014-02-25 16:08:45 +01:00
|
|
|
this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
|
2014-02-27 14:11:03 +01:00
|
|
|
//}
|
2014-02-20 09:21:38 +01:00
|
|
|
}
|
2014-02-12 13:12:51 +01:00
|
|
|
|
2014-02-21 15:42:09 +01:00
|
|
|
// Adjust velocities so no squaring occurs
|
|
|
|
forwardVelocity *= Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z));
|
|
|
|
rightVelocity *= Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z));
|
|
|
|
upVelocity *= Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z));
|
2014-02-20 15:13:52 +01:00
|
|
|
|
2014-02-21 15:42:09 +01:00
|
|
|
this->rigidBody->SetLinearVelocity(forwardVelocity+rightVelocity+upVelocity);
|
2014-02-20 15:13:52 +01:00
|
|
|
|
2014-02-21 15:42:09 +01:00
|
|
|
//Jump
|
|
|
|
if(key_jump > 0.001)
|
|
|
|
{
|
2014-02-26 10:25:39 +01:00
|
|
|
this->key_jump -= this->gameInstance->GetFrameTime();
|
|
|
|
if(IsWalking())
|
2014-02-21 15:42:09 +01:00
|
|
|
{
|
|
|
|
Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized();
|
2014-02-25 11:46:05 +01:00
|
|
|
this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20);
|
2014-02-25 16:08:45 +01:00
|
|
|
|
|
|
|
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
|
2014-02-26 09:11:45 +01:00
|
|
|
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Jump);
|
2014-02-21 15:42:09 +01:00
|
|
|
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::EndFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
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-02-12 12:16:16 +01:00
|
|
|
key_forward = KEY_TIMER;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveBackwards()
|
|
|
|
{
|
2014-02-12 12:16:16 +01:00
|
|
|
key_backward = KEY_TIMER;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveRight()
|
|
|
|
{
|
2014-02-12 12:16:16 +01:00
|
|
|
key_strafeRight = KEY_TIMER;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveLeft()
|
|
|
|
{
|
2014-02-12 12:16:16 +01:00
|
|
|
key_strafeLeft = KEY_TIMER;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-01-16 11:17:19 +01:00
|
|
|
void Player::UseWeapon(const WEAPON_FIRE &usage)
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
this->weapon->Use(usage,gameInstance->GetFrameTime());
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
|
2014-02-14 10:09:03 +01:00
|
|
|
{
|
2014-02-21 15:42:09 +01:00
|
|
|
if( this->playerState == PLAYER_STATE_DEAD)
|
|
|
|
{
|
2014-02-25 11:46:05 +01:00
|
|
|
Player::initPlayerData();
|
2014-02-21 15:42:09 +01:00
|
|
|
this->rigidBody->SetPosition(spawnPoint);
|
|
|
|
this->gameInstance->onRespawnFnc( this, spawnPoint);
|
2014-02-25 11:46:05 +01:00
|
|
|
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
|
2014-02-21 15:42:09 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:10:47 +01:00
|
|
|
void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir)
|
2014-01-21 09:52:48 +01:00
|
|
|
{
|
2014-02-12 11:36:08 +01:00
|
|
|
// this is the camera right vector
|
2014-02-21 11:10:47 +01:00
|
|
|
this->lookDir = -lookDir;
|
2014-02-11 11:46:06 +01:00
|
|
|
|
2014-01-21 09:52:48 +01:00
|
|
|
}
|
2014-02-19 13:47:49 +01:00
|
|
|
void Player::TurnLeft(Oyster::Math3D::Float deltaRadians)
|
|
|
|
{
|
2014-02-19 13:59:59 +01:00
|
|
|
this->rotationUp += deltaRadians;
|
2014-02-19 13:47:49 +01:00
|
|
|
}
|
2014-01-21 09:52:48 +01:00
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
void Player::Jump()
|
|
|
|
{
|
2014-02-17 06:44:29 +01:00
|
|
|
this->key_jump = KEY_TIMER;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::IsWalking()
|
|
|
|
{
|
2014-02-26 14:06:02 +01:00
|
|
|
return (this->rigidBody->GetLambdaUp() < 0.99f);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
bool Player::IsJumping()
|
|
|
|
{
|
2014-02-26 14:06:02 +01:00
|
|
|
return (this->rigidBody->GetLambdaUp() == 1.0f);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
bool Player::IsIdle()
|
|
|
|
{
|
2014-02-27 14:11:03 +01:00
|
|
|
return (this->rigidBody->GetLambdaUp() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.1f);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 16:52:36 +01:00
|
|
|
void Player::Inactivate()
|
|
|
|
{
|
|
|
|
//this->
|
|
|
|
}
|
2014-02-26 14:55:29 +01:00
|
|
|
void Player::ResetPlayer( Oyster::Math::Float3 spawnPos)
|
|
|
|
{
|
|
|
|
Player::initPlayerData();
|
|
|
|
this->rigidBody->SetPosition(spawnPos);
|
|
|
|
this->playerScore.killScore = 0;
|
|
|
|
this->playerScore.deathScore = 0;
|
|
|
|
}
|
2014-01-15 11:03:25 +01:00
|
|
|
Oyster::Math::Float3 Player::GetPosition() const
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-02-11 10:11:38 +01:00
|
|
|
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
2014-01-16 12:26:14 +01:00
|
|
|
Oyster::Math::Float4x4 Player::GetOrientation() const
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-02-11 10:11:38 +01:00
|
|
|
return this->rigidBody->GetState().GetOrientation();
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
2014-01-15 11:03:25 +01:00
|
|
|
Oyster::Math::Float3 Player::GetLookDir() const
|
|
|
|
{
|
2014-01-28 15:44:32 +01:00
|
|
|
return this->lookDir;
|
2014-01-15 11:03:25 +01:00
|
|
|
}
|
|
|
|
int Player::GetTeamID() const
|
|
|
|
{
|
|
|
|
return this->teamID;
|
|
|
|
}
|
|
|
|
PLAYER_STATE Player::GetState() const
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
return this->playerState;
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
2014-02-27 11:35:32 +01:00
|
|
|
void Player::AddKill()
|
|
|
|
{
|
|
|
|
this->playerScore.killScore++;
|
|
|
|
}
|
|
|
|
void Player::AddDeath()
|
|
|
|
{
|
|
|
|
this->playerScore.deathScore++;
|
|
|
|
}
|
|
|
|
int Player::GetKills() const
|
|
|
|
{
|
|
|
|
return this->playerScore.killScore;
|
|
|
|
}
|
|
|
|
int Player::GetDeath() const
|
|
|
|
{
|
|
|
|
return this->playerScore.deathScore;
|
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
void Player::DamageLife(int damage)
|
|
|
|
{
|
2014-02-26 10:23:38 +01:00
|
|
|
if(damage != 0)
|
2014-02-04 11:13:02 +01:00
|
|
|
{
|
2014-02-26 10:23:38 +01:00
|
|
|
this->playerStats.hp -= damage;
|
|
|
|
|
|
|
|
if(this->playerStats.hp > 100)
|
|
|
|
this->playerStats.hp = 100;
|
|
|
|
|
|
|
|
// send hp to client
|
|
|
|
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
|
2014-02-21 15:42:09 +01:00
|
|
|
|
2014-02-26 10:23:38 +01:00
|
|
|
if(this->playerStats.hp <= 0)
|
|
|
|
{
|
|
|
|
this->playerStats.hp = 0;
|
|
|
|
this->playerState = PLAYER_STATE_DIED;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 10:37:33 +01:00
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
|
2014-02-25 11:46:05 +01:00
|
|
|
bool Player::deathTimerTick(float dt)
|
|
|
|
{
|
|
|
|
this->deathTimer -= dt;
|
|
|
|
if( this->deathTimer <= 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void Player::setDeathTimer(float deathTimer)
|
|
|
|
{
|
|
|
|
this->deathTimer = deathTimer;
|
|
|
|
this->playerState = PLAYER_STATE_DEAD;
|
2014-02-25 12:12:24 +01:00
|
|
|
}
|