Danbias/Code/Game/GameLogic/Player.cpp

149 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;
teamID = -1;
2013-12-20 09:42:02 +01:00
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0);
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;
int teamID;
2013-12-05 11:50:39 +01:00
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()
2013-12-19 10:21:03 +01:00
:Object(CollisionManager::PlayerCollision, OBJECT_TYPE::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
void Player::Move(const PLAYER_MOVEMENT &movement)
2013-11-21 12:05:39 +01:00
{
//Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
2013-12-19 15:35:49 +01:00
switch(movement)
{
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
2014-01-07 10:26:09 +01:00
MoveForward();
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD:
2014-01-07 10:26:09 +01:00
MoveBackwards();
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT:
2014-01-07 10:26:09 +01:00
MoveLeft();
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT:
2014-01-07 10:26:09 +01:00
MoveRight();
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP:
Jump();
break;
}
}
2013-12-20 09:42:02 +01:00
void Player::MoveForward()
{
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
2013-12-20 09:42:02 +01:00
}
void Player::MoveBackwards()
{
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
2013-12-20 09:42:02 +01:00
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
2014-01-07 10:26:09 +01:00
//Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100);
2013-12-20 09:42:02 +01:00
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
2014-01-07 10:26:09 +01:00
//Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100);
2013-12-20 09:42:02 +01:00
}
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
{
myData->weapon->Use(fireInput);
2013-11-21 12:05:39 +01:00
}
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
{
//API::Instance().SetCenter(rigidBody,spawnPoint);
myData->life = 100;
2013-12-19 10:21:03 +01:00
myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
myData->lookDir = Oyster::Math::Float3(1,0,0);
}
void Player::Jump()
{
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
}
bool Player::IsWalking()
{
2013-12-20 09:42:02 +01:00
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
}
bool Player::IsJumping()
{
2013-12-20 09:42:02 +01:00
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
}
bool Player::IsIdle()
{
2013-12-20 09:42:02 +01:00
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
}
2013-12-10 11:17:25 +01:00
Oyster::Math::Float3 Player::GetPos()
{
//return rigidBody->GetCenter();
2013-12-19 10:21:03 +01:00
return Oyster::Math::Float3(0,0,0);
2013-12-10 11:17:25 +01:00
}
Oyster::Math::Float3 Player::GetLookDir()
{
return myData->lookDir;
}
int Player::GetTeamID()
2013-11-21 12:05:39 +01:00
{
return myData->teamID;
2013-11-19 11:07:14 +01:00
}
void Player::DamageLife(int damage)
{
myData->life -= damage;
}