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-05 09:06:33 +01:00
|
|
|
const int MOVE_FORCE = 500;
|
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-01-29 14:33:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
Player::Player(OBJECT_TYPE type)
|
|
|
|
:DynamicObject(type)
|
|
|
|
{
|
|
|
|
InitPlayer();
|
|
|
|
}
|
|
|
|
Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
|
|
|
|
:DynamicObject(rigidBody,type)
|
|
|
|
{
|
|
|
|
InitPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Player::Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
|
|
|
|
:DynamicObject(collisionFuncBefore,collisionFuncAfter,type)
|
|
|
|
{
|
|
|
|
InitPlayer();
|
|
|
|
}
|
|
|
|
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
|
|
|
|
:DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
|
|
|
|
{
|
|
|
|
InitPlayer();
|
|
|
|
}
|
|
|
|
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
|
|
|
|
:DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
|
|
|
|
{
|
|
|
|
InitPlayer();
|
2014-01-27 08:54:25 +01:00
|
|
|
}
|
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
void Player::InitPlayer()
|
2014-01-27 08:54:25 +01:00
|
|
|
{
|
2014-01-27 13:54:57 +01:00
|
|
|
weapon = new Weapon(2,this);
|
|
|
|
|
|
|
|
this->life = 100;
|
|
|
|
this->teamID = -1;
|
|
|
|
this->playerState = PLAYER_STATE_IDLE;
|
|
|
|
lookDir = Oyster::Math::Float4(0,0,-1,0);
|
2014-01-27 13:56:31 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
|
|
|
|
Player::~Player(void)
|
|
|
|
{
|
2014-01-27 13:54:57 +01:00
|
|
|
if(weapon)
|
|
|
|
{
|
|
|
|
delete weapon;
|
|
|
|
weapon = NULL;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
void Player::BeginFrame()
|
|
|
|
{
|
2014-02-04 16:24:37 +01:00
|
|
|
weapon->Update(0.002f);
|
2014-02-03 15:32:46 +01:00
|
|
|
Object::BeginFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::EndFrame()
|
|
|
|
{
|
2014-02-04 16:08:28 +01:00
|
|
|
// snap to axis
|
2014-02-03 15:32:46 +01:00
|
|
|
Object::EndFrame();
|
2014-02-04 16:08:28 +01:00
|
|
|
// rotate
|
|
|
|
|
|
|
|
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
|
|
|
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
|
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
currPhysicsState.AddRotation(deltaAxis);
|
2014-02-04 16:08:28 +01:00
|
|
|
dx = 0;
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
|
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-04 11:50:15 +01:00
|
|
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
|
|
|
//Oyster::Math::Float3 forward = lookDir;
|
2014-02-04 16:08:28 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime()));
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveBackwards()
|
|
|
|
{
|
2014-02-04 11:50:15 +01:00
|
|
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
|
|
|
//Oyster::Math::Float3 forward = lookDir;
|
2014-02-04 16:08:28 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveRight()
|
|
|
|
{
|
|
|
|
//Do cross product with forward vector and negative gravity vector
|
2014-02-04 11:50:15 +01:00
|
|
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
|
|
|
//Oyster::Math::Float3 forward = lookDir;
|
2014-02-03 15:52:00 +01:00
|
|
|
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
|
2014-02-04 16:08:28 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(-r * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
2014-01-16 12:26:14 +01:00
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
void Player::MoveLeft()
|
|
|
|
{
|
|
|
|
//Do cross product with forward vector and negative gravity vector
|
2014-02-04 11:50:15 +01:00
|
|
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
|
|
|
//Oyster::Math::Float3 forward = lookDir;
|
2014-02-03 15:52:00 +01:00
|
|
|
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero
|
2014-02-04 16:08:28 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(r * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
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-01-15 11:03:25 +01:00
|
|
|
this->life = 100;
|
|
|
|
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
|
|
|
|
this->lookDir = Oyster::Math::Float4(1,0,0);
|
2014-02-04 13:08:03 +01:00
|
|
|
this->newPhysicsState.SetCenterPosition(spawnPoint);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-03 15:52:00 +01:00
|
|
|
void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
2014-01-21 09:52:48 +01:00
|
|
|
{
|
2014-02-03 15:52:00 +01:00
|
|
|
Oyster::Math::Float dx = lookDir.w;
|
2014-02-04 11:50:15 +01:00
|
|
|
if(dx > 0.0f)
|
|
|
|
{
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-04 16:08:28 +01:00
|
|
|
//Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
|
|
|
//Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
|
|
|
|
//Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
|
2014-02-04 10:29:02 +01:00
|
|
|
|
2014-02-04 16:08:28 +01:00
|
|
|
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
|
2014-02-03 15:52:00 +01:00
|
|
|
|
|
|
|
this->lookDir = lookDir.xyz;
|
2014-02-04 16:08:28 +01:00
|
|
|
this->dx = lookDir.w;
|
2014-01-21 09:52:48 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:51:17 +01:00
|
|
|
void Player::Jump()
|
|
|
|
{
|
2014-02-03 16:30:47 +01:00
|
|
|
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
2014-02-04 16:08:28 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(up * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::IsWalking()
|
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
bool Player::IsJumping()
|
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
bool Player::IsIdle()
|
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
|
2014-01-09 12:51:17 +01:00
|
|
|
}
|
|
|
|
|
2014-01-15 11:03:25 +01:00
|
|
|
Oyster::Math::Float3 Player::GetPosition() const
|
2014-01-09 12:51:17 +01:00
|
|
|
{
|
2014-02-03 15:52:00 +01:00
|
|
|
return (Oyster::Math::Float3)currPhysicsState.GetCenterPosition();
|
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-03 15:52:00 +01:00
|
|
|
return this->currPhysicsState.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
|
|
|
}
|
|
|
|
|
|
|
|
void Player::DamageLife(int damage)
|
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
this->life -= damage;
|
2014-02-04 11:13:02 +01:00
|
|
|
this->life = 0;
|
|
|
|
|
|
|
|
if(this->life <= 0)
|
|
|
|
{
|
|
|
|
this->life = 0;
|
|
|
|
playerState = PLAYER_STATE_DEAD;
|
2014-02-04 16:24:37 +01:00
|
|
|
this->gameInstance->onDisableFnc(this);
|
2014-02-04 11:13:02 +01:00
|
|
|
}
|
2014-01-15 11:03:25 +01:00
|
|
|
}
|
|
|
|
|