Major updates to Collision handling with the class CollitionManager. changes started on the massdriver
This commit is contained in:
parent
8792aab992
commit
ebaa668382
|
@ -3,52 +3,38 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
|
||||
struct AttatchmentMassDriver::PrivateData
|
||||
{
|
||||
PrivateData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~PrivateData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}myData;
|
||||
|
||||
|
||||
AttatchmentMassDriver::AttatchmentMassDriver(void)
|
||||
{
|
||||
myData = new PrivateData();
|
||||
this->owner = 0;
|
||||
}
|
||||
|
||||
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
|
||||
{
|
||||
myData = new PrivateData();
|
||||
|
||||
this->owner = &owner;
|
||||
}
|
||||
|
||||
|
||||
AttatchmentMassDriver::~AttatchmentMassDriver(void)
|
||||
{
|
||||
delete myData;
|
||||
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
|
||||
********************************************************/
|
||||
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
|
||||
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float dt)
|
||||
{
|
||||
//switch case to determin what functionallity to use in the attatchment
|
||||
switch (usage)
|
||||
{
|
||||
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
|
||||
ForcePush(usage);
|
||||
ForcePush(usage,dt);
|
||||
break;
|
||||
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
|
||||
ForcePull(usage);
|
||||
ForcePull(usage,dt);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -57,17 +43,27 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
|
|||
/********************************************************
|
||||
* Pushes objects in a cone in front of the weapon when fired
|
||||
********************************************************/
|
||||
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage)
|
||||
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt)
|
||||
{
|
||||
//create coneRigidBody that will then collide with object and push them in the aimed direction
|
||||
Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt);
|
||||
|
||||
|
||||
//create frustum that will then collide with object and push them in the aimed direction
|
||||
|
||||
//sample with frustum using visitor pattern(needs a function ptr sent with it that idicates what happens when a collision has been made)
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack)
|
||||
********************************************************/
|
||||
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage)
|
||||
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
|
||||
{
|
||||
//Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100);
|
||||
Oyster::Physics::Struct::CustomBodyState state = this->owner->GetRigidBody()->GetState();
|
||||
|
||||
//do something with state
|
||||
state.ApplyLinearImpulse(Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt));
|
||||
|
||||
this->owner->GetRigidBody()->SetState(state);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,30 +15,29 @@ namespace GameLogic
|
|||
~AttatchmentMassDriver(void);
|
||||
|
||||
|
||||
void UseAttatchment(const WEAPON_FIRE &usage);
|
||||
void UseAttatchment(const WEAPON_FIRE &usage, float dt);
|
||||
|
||||
private:
|
||||
/********************************************************
|
||||
* Pushes objects and players in a cone in front of the player
|
||||
* @param fireInput: allows switching on different functionality in this specific function
|
||||
********************************************************/
|
||||
void ForcePush(const WEAPON_FIRE &usage);
|
||||
void ForcePush(const WEAPON_FIRE &usage, float dt);
|
||||
|
||||
/********************************************************
|
||||
* Pulls the player forward, this is a movement tool
|
||||
* @param fireInput: allows switching on different functionality in this specific function
|
||||
********************************************************/
|
||||
void ForcePull(const WEAPON_FIRE &usage);
|
||||
void ForcePull(const WEAPON_FIRE &usage, float dt);
|
||||
|
||||
/********************************************************
|
||||
* Sucks objects towards the player, the player can then pick up an object and throw it as a projectile
|
||||
* @param fireInput: allows switching on different functionality in this specific function
|
||||
********************************************************/
|
||||
void ForceSuck(const WEAPON_FIRE &usage);
|
||||
void ForceSuck(const WEAPON_FIRE &usage, float dt);
|
||||
|
||||
private:
|
||||
struct PrivateData;
|
||||
PrivateData *myData;
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,62 +1,59 @@
|
|||
#include "CollisionManager.h"
|
||||
#include "PhysicsAPI.h"
|
||||
#include "Object.h"
|
||||
#include "DynamicObject.h"
|
||||
#include "Player.h"
|
||||
#include "Level.h"
|
||||
|
||||
using namespace Oyster;
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
void PlayerVBox(Player &player, DynamicObject &box);
|
||||
void PlayerVObject(Player &player, Object &obj);
|
||||
|
||||
|
||||
Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
|
||||
Physics::ICustomBody::SubscriptMessage Player::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
|
||||
{
|
||||
//Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef));
|
||||
//Object *realObj = (Object*)obj->gameObjectRef;
|
||||
Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag()));
|
||||
Object *realObj = (Object*)obj->GetCustomTag();
|
||||
|
||||
//switch (realObj->GetType())
|
||||
//{
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_BOX:
|
||||
// PlayerVBox(*player,(*(DynamicObject*) realObj));
|
||||
// break;
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
|
||||
//
|
||||
// break;
|
||||
//}
|
||||
switch (realObj->GetType())
|
||||
{
|
||||
case OBJECT_H::OBJECT_TYPE_GENERIC:
|
||||
PlayerVObject(*player,*realObj);
|
||||
Physics::ICustomBody::SubscriptMessage_none;
|
||||
break;
|
||||
|
||||
case OBJECT_TYPE::OBJECT_TYPE_BOX:
|
||||
PlayerVBox(*player,(*(DynamicObject*) realObj));
|
||||
Physics::ICustomBody::SubscriptMessage_none;
|
||||
break;
|
||||
case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
|
||||
Physics::ICustomBody::SubscriptMessage_none;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
|
||||
void PlayerVBox(Player &player, DynamicObject &box)
|
||||
{
|
||||
//use kinetic energyloss of the collision in order too determin how much damage to take
|
||||
//use as part of the damage algorithm
|
||||
player.DamageLife(20);
|
||||
}
|
||||
|
||||
void PlayerVObject(Player &player, Object &obj)
|
||||
{
|
||||
//Collision between a player and a general static or dynamic object
|
||||
//use kinetic energyloss of the collision in order too determin how much damage to take
|
||||
//use as part of the damage algorithm
|
||||
player.DamageLife(20);
|
||||
}
|
||||
|
||||
Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj)
|
||||
{
|
||||
if(rigidBodyBox == 0)
|
||||
{
|
||||
return Physics::ICustomBody::SubscriptMessage::SubscriptMessage_none;
|
||||
}
|
||||
//DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
|
||||
//Object *realObj = (Object*)obj->gameObjectRef;
|
||||
|
||||
//switch (realObj->GetType())
|
||||
//{
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_BOX:
|
||||
//
|
||||
// break;
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
|
||||
// //PlayerVBox(*(Player*)realObj,*box);
|
||||
// break;
|
||||
//}
|
||||
|
||||
return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
|
||||
Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
|
||||
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
|
||||
{
|
||||
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
|
||||
}
|
||||
|
|
|
@ -10,14 +10,7 @@ namespace GameLogic
|
|||
class CollisionManager
|
||||
{
|
||||
public:
|
||||
//these are the main collision functions
|
||||
//typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
|
||||
static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
|
||||
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
|
||||
//these are the specific collision case functions
|
||||
//void PlayerVBox(Player &player, DynamicObject &box);
|
||||
//void BoxVBox(DynamicObject &box1, DynamicObject &box2);
|
||||
//put general collision functions here that are not part of a specific object
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ namespace GameLogic
|
|||
{
|
||||
OBJECT_TYPE_PLAYER = 0,
|
||||
OBJECT_TYPE_BOX = 1,
|
||||
OBJECT_TYPE_WORLD = 2,
|
||||
OBJECT_TYPE_WORLD = 2,
|
||||
OBJECT_TYPE_GENERIC = 4,
|
||||
OBJECT_TYPE_UNKNOWN = -1,
|
||||
};
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace GameLogic
|
|||
IAttatchment(void);
|
||||
~IAttatchment(void);
|
||||
|
||||
virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0;
|
||||
virtual void UseAttatchment(const WEAPON_FIRE &usage, float dt) = 0;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -51,6 +51,14 @@ namespace GameLogic
|
|||
********************************************************/
|
||||
void RespawnPlayer(Player *player);
|
||||
|
||||
/********************************************************
|
||||
* Collision function for level, this is to be sent to physics through the subscribe function with the rigidbody
|
||||
* Will be called when the physics detect a collision
|
||||
* @param rigidBodyLevel: physics object of the level
|
||||
* @param obj: physics object for the object that collided with the level
|
||||
********************************************************/
|
||||
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
|
||||
|
||||
private:
|
||||
TeamManager teamManager;
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
|
||||
|
|
|
@ -8,7 +8,7 @@ using namespace GameLogic;
|
|||
using namespace Oyster::Physics;
|
||||
|
||||
Player::Player()
|
||||
:DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
|
||||
:DynamicObject(Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
|
||||
{
|
||||
weapon = new Weapon();
|
||||
|
||||
|
@ -81,7 +81,7 @@ void Player::MoveLeft()
|
|||
|
||||
void Player::UseWeapon(const WEAPON_FIRE &usage)
|
||||
{
|
||||
this->weapon->Use(usage);
|
||||
this->weapon->Use(usage,gameInstance->GetFrameTime());
|
||||
}
|
||||
|
||||
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
|
||||
|
|
|
@ -41,7 +41,18 @@ namespace GameLogic
|
|||
********************************************************/
|
||||
void Respawn(Oyster::Math::Float3 spawnPoint);
|
||||
|
||||
<<<<<<< HEAD
|
||||
void Rotate(float x, float y);
|
||||
=======
|
||||
/********************************************************
|
||||
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
|
||||
* Will be called when the physics detect a collision
|
||||
* @param rigidBodyPlayer: physics object of the player
|
||||
* @param obj: physics object for the object that collided with the player
|
||||
********************************************************/
|
||||
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
|
||||
|
||||
>>>>>>> Major updates to Collision handling with the class CollitionManager. changes started on the massdriver
|
||||
|
||||
bool IsWalking();
|
||||
bool IsJumping();
|
||||
|
@ -65,6 +76,9 @@ namespace GameLogic
|
|||
PLAYER_STATE playerState;
|
||||
Oyster::Math::Float4 lookDir;
|
||||
|
||||
bool hasTakenDamage;
|
||||
float invincibleCooldown;
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -1,60 +1,39 @@
|
|||
#include "Weapon.h"
|
||||
#include "AttatchmentSocket.h"
|
||||
#include "AttatchmentMassDriver.h"
|
||||
#include "DynamicArray.h"
|
||||
|
||||
|
||||
using namespace GameLogic;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
struct Weapon::PrivateData
|
||||
{
|
||||
PrivateData()
|
||||
{
|
||||
weaponState = WEAPON_STATE_IDLE;
|
||||
selectedAttatchment = 0;
|
||||
currentNrOfAttatchments = 0;
|
||||
selectedSocketID = 0;
|
||||
attatchmentSockets = 0;
|
||||
}
|
||||
|
||||
~PrivateData()
|
||||
{
|
||||
}
|
||||
|
||||
WEAPON_STATE weaponState;
|
||||
|
||||
DynamicArray<SmartPointer<AttatchmentSocket>> attatchmentSockets;
|
||||
int currentNrOfAttatchments;
|
||||
SmartPointer<IAttatchment> selectedAttatchment;
|
||||
int selectedSocketID;
|
||||
|
||||
}myData;
|
||||
|
||||
Weapon::Weapon()
|
||||
{
|
||||
myData = new PrivateData();
|
||||
weaponState = WEAPON_STATE_IDLE;
|
||||
selectedAttatchment = 0;
|
||||
currentNrOfAttatchments = 0;
|
||||
selectedSocketID = 0;
|
||||
attatchmentSockets = 0;
|
||||
}
|
||||
|
||||
Weapon::Weapon(int MaxNrOfSockets)
|
||||
{
|
||||
myData = new PrivateData();
|
||||
myData->attatchmentSockets.Resize(MaxNrOfSockets);
|
||||
attatchmentSockets.Resize(MaxNrOfSockets);
|
||||
}
|
||||
|
||||
|
||||
Weapon::~Weapon(void)
|
||||
{
|
||||
delete myData;
|
||||
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* Uses the weapon based on the input given and the current chosen attatchment
|
||||
********************************************************/
|
||||
void Weapon::Use(const WEAPON_FIRE &usage)
|
||||
void Weapon::Use(const WEAPON_FIRE &usage, float dt)
|
||||
{
|
||||
if (myData->selectedAttatchment)
|
||||
if (selectedAttatchment)
|
||||
{
|
||||
myData->selectedAttatchment->UseAttatchment(usage);
|
||||
selectedAttatchment->UseAttatchment(usage, dt);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,24 +47,24 @@ void Weapon::Use(const WEAPON_FIRE &usage)
|
|||
********************************************************/
|
||||
bool Weapon::IsFireing()
|
||||
{
|
||||
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
|
||||
return (weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
|
||||
}
|
||||
|
||||
bool Weapon::IsIdle()
|
||||
{
|
||||
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
|
||||
return (weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
|
||||
}
|
||||
|
||||
bool Weapon::IsReloading()
|
||||
{
|
||||
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
|
||||
return (weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
|
||||
}
|
||||
|
||||
bool Weapon::IsValidSocket(int socketID)
|
||||
{
|
||||
if(socketID < (int)myData->attatchmentSockets.Size() && socketID >= 0)
|
||||
if(socketID < (int)attatchmentSockets.Size() && socketID >= 0)
|
||||
{
|
||||
if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0)
|
||||
if (attatchmentSockets[socketID]->GetAttatchment() != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -96,16 +75,16 @@ bool Weapon::IsValidSocket(int socketID)
|
|||
|
||||
int Weapon::GetCurrentSocketID()
|
||||
{
|
||||
return myData->selectedSocketID;
|
||||
return selectedSocketID;
|
||||
}
|
||||
|
||||
|
||||
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
|
||||
{
|
||||
if(myData->currentNrOfAttatchments < (int)myData->attatchmentSockets.Size())
|
||||
if(currentNrOfAttatchments < (int)attatchmentSockets.Size())
|
||||
{
|
||||
myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment);
|
||||
myData->currentNrOfAttatchments++;
|
||||
attatchmentSockets[currentNrOfAttatchments]->SetAttatchment(attatchment);
|
||||
currentNrOfAttatchments++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +92,7 @@ void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *
|
|||
{
|
||||
if (IsValidSocket(socketID))
|
||||
{
|
||||
myData->attatchmentSockets[socketID]->SetAttatchment(attatchment);
|
||||
attatchmentSockets[socketID]->SetAttatchment(attatchment);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +100,7 @@ void Weapon::RemoveAttatchment(int socketID)
|
|||
{
|
||||
if (IsValidSocket(socketID))
|
||||
{
|
||||
myData->attatchmentSockets[socketID]->RemoveAttatchment();
|
||||
attatchmentSockets[socketID]->RemoveAttatchment();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,8 +108,8 @@ void Weapon::SelectAttatchment(int socketID)
|
|||
{
|
||||
if (IsValidSocket(socketID))
|
||||
{
|
||||
myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment();
|
||||
myData->selectedSocketID = socketID;
|
||||
selectedAttatchment = attatchmentSockets[socketID]->GetAttatchment();
|
||||
selectedSocketID = socketID;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,21 +6,20 @@
|
|||
#include "GameLogicStates.h"
|
||||
#include "IAttatchment.h"
|
||||
#include "Player.h"
|
||||
#include "AttatchmentSocket.h"
|
||||
#include "DynamicArray.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class Weapon
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Weapon(void);
|
||||
Weapon(int nrOfAttatchmentSockets);
|
||||
~Weapon(void);
|
||||
|
||||
void Use(const WEAPON_FIRE &fireInput);
|
||||
void Use(const WEAPON_FIRE &usage, float dt);
|
||||
|
||||
void AddNewAttatchment(IAttatchment *attatchment, Player *owner);
|
||||
void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner);
|
||||
|
@ -35,9 +34,12 @@ namespace GameLogic
|
|||
|
||||
int GetCurrentSocketID();
|
||||
|
||||
private:
|
||||
struct PrivateData;
|
||||
PrivateData *myData;
|
||||
private:
|
||||
WEAPON_STATE weaponState;
|
||||
Utility::DynamicMemory::DynamicArray<AttatchmentSocket*> attatchmentSockets;
|
||||
int currentNrOfAttatchments;
|
||||
IAttatchment *selectedAttatchment;
|
||||
int selectedSocketID;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue