Danbias/Code/Game/GameLogic/Player.cpp

126 lines
2.4 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-19 10:21:03 +01:00
playerState.value = 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 10:21:03 +01:00
switch(movement.value)
{
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT:
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT:
break;
2013-12-19 10:21:03 +01:00
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP:
Jump();
break;
}
}
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-19 10:21:03 +01:00
return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_WALKING);
}
bool Player::IsJumping()
{
2013-12-19 10:21:03 +01:00
return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_JUMPING);
}
bool Player::IsIdle()
{
2013-12-19 10:21:03 +01:00
return (myData->playerState.value == 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;
}