updated AttatchmentMassDriver and CollisionManager

weapon attatchments now have a owner(player) to facillitate the weapon
manipulating the player using it.

CollisionManager now works with a tag void* in the rigidbody to link
with a game object instead of the RefManager component
This commit is contained in:
Erik Persson 2013-12-12 12:16:13 +01:00
parent c801ab829a
commit 8f36f64c4f
12 changed files with 80 additions and 42 deletions

View File

@ -1,4 +1,5 @@
#include "AttatchmentMassDriver.h" #include "AttatchmentMassDriver.h"
#include "PhysicsAPI.h"
using namespace GameLogic; using namespace GameLogic;
@ -19,11 +20,20 @@ struct AttatchmentMassDriver::PrivateData
AttatchmentMassDriver::AttatchmentMassDriver(void) AttatchmentMassDriver::AttatchmentMassDriver(void)
{ {
myData = new PrivateData();
this->owner = 0;
}
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
{
myData = new PrivateData();
this->owner = &owner;
} }
AttatchmentMassDriver::~AttatchmentMassDriver(void) AttatchmentMassDriver::~AttatchmentMassDriver(void)
{ {
delete myData;
} }
/******************************************************** /********************************************************
@ -31,7 +41,17 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void)
********************************************************/ ********************************************************/
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput)
{ {
//switch case to determin what functionallity to use in the attatchment
switch (fireInput)
{
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
ForcePush(fireInput); ForcePush(fireInput);
break;
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
ForcePull(fireInput);
break;
}
} }
/******************************************************** /********************************************************
@ -39,7 +59,13 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp
********************************************************/ ********************************************************/
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput)
{ {
//create coneRigidBody that will then collide with object and push them in the aimed direction
}
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput)
{
Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100);
} }

View File

@ -8,6 +8,7 @@ namespace GameLogic
{ {
public: public:
AttatchmentMassDriver(void); AttatchmentMassDriver(void);
AttatchmentMassDriver(Player &owner);
~AttatchmentMassDriver(void); ~AttatchmentMassDriver(void);
@ -15,6 +16,7 @@ namespace GameLogic
private: private:
void ForcePush(const WEAPON_FIRE &fireInput); void ForcePush(const WEAPON_FIRE &fireInput);
void ForcePull(const WEAPON_FIRE &fireInput);
private: private:
struct PrivateData; struct PrivateData;

View File

@ -1,5 +1,4 @@
#include "CollisionManager.h" #include "CollisionManager.h"
#include "RefManager.h"
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
#include "Object.h" #include "Object.h"
#include "DynamicObject.h" #include "DynamicObject.h"
@ -13,15 +12,18 @@ namespace GameLogic
namespace CollisionManager namespace CollisionManager
{ {
void PlayerVBox(Player &player, DynamicObject &box);
Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
{ {
Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer)); Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef));
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType()) switch (realObj->GetType())
{ {
case OBJECT_TYPE_BOX: case OBJECT_TYPE_BOX:
//PlayerVBox(*player,(*(DynamicObject*) realObj)); PlayerVBox(*player,(*(DynamicObject*) realObj));
break; break;
case OBJECT_TYPE_PLAYER: case OBJECT_TYPE_PLAYER:
@ -31,15 +33,15 @@ namespace GameLogic
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
} }
/* void PlayerVBox(Player &player, DynamicObject &box) void PlayerVBox(Player &player, DynamicObject &box)
{ {
spela ljud? ta skada? etc etc player.DamageLife(20);
}*/ }
Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj)
{ {
DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox)); DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType()) switch (realObj->GetType())
{ {

View File

@ -3,8 +3,6 @@
#include "Object.h" #include "Object.h"
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
//#include "DynamicObject.h"
//#include "Player.h"
namespace GameLogic namespace GameLogic
{ {

View File

@ -176,7 +176,6 @@
<ClInclude Include="Level.h" /> <ClInclude Include="Level.h" />
<ClInclude Include="Object.h" /> <ClInclude Include="Object.h" />
<ClInclude Include="Player.h" /> <ClInclude Include="Player.h" />
<ClInclude Include="RefManager.h" />
<ClInclude Include="StaticObject.h" /> <ClInclude Include="StaticObject.h" />
<ClInclude Include="Weapon.h" /> <ClInclude Include="Weapon.h" />
</ItemGroup> </ItemGroup>
@ -191,7 +190,6 @@
<ClCompile Include="Level.cpp" /> <ClCompile Include="Level.cpp" />
<ClCompile Include="Object.cpp" /> <ClCompile Include="Object.cpp" />
<ClCompile Include="Player.cpp" /> <ClCompile Include="Player.cpp" />
<ClCompile Include="RefManager.cpp" />
<ClCompile Include="StaticObject.cpp" /> <ClCompile Include="StaticObject.cpp" />
<ClCompile Include="Weapon.cpp" /> <ClCompile Include="Weapon.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -3,22 +3,6 @@
using namespace GameLogic; using namespace GameLogic;
struct IAttatchment::PrivateData
{
PrivateData()
{
}
~PrivateData()
{
}
}myData;
IAttatchment::IAttatchment(void) IAttatchment::IAttatchment(void)
{ {
} }

View File

@ -1,6 +1,7 @@
#ifndef IATTATCHMENT_H #ifndef IATTATCHMENT_H
#define IATTATCHMENT_H #define IATTATCHMENT_H
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "Player.h"
namespace GameLogic namespace GameLogic
{ {
@ -17,8 +18,9 @@ namespace GameLogic
virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0;
private: private:
struct PrivateData;
PrivateData *myData; protected:
Player *owner;
}; };
} }

View File

@ -1,6 +1,6 @@
#include "Object.h" #include "Object.h"
#include "OysterMath.h" #include "OysterMath.h"
#include "RefManager.h" #include "CollisionManager.h"
using namespace GameLogic; using namespace GameLogic;
@ -16,7 +16,7 @@ Object::Object()
//poi //poi
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); rigidBody->gameObjectRef = this;
this->type = OBJECT_TYPE_UNKNOWN; this->type = OBJECT_TYPE_UNKNOWN;
@ -32,7 +32,7 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); rigidBody->gameObjectRef = this;
this->type = type; this->type = type;
} }
@ -48,3 +48,8 @@ OBJECT_TYPE Object::GetType()
{ {
return this->type; return this->type;
} }
Oyster::Physics::ICustomBody* Object::GetRigidBody()
{
return this->rigidBody;
}

View File

@ -8,7 +8,7 @@
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "CollisionManager.h"
namespace GameLogic namespace GameLogic
{ {
@ -21,6 +21,8 @@ namespace GameLogic
OBJECT_TYPE GetType(); OBJECT_TYPE GetType();
Oyster::Physics::ICustomBody* GetRigidBody();
private: private:
OBJECT_TYPE type; OBJECT_TYPE type;
protected: protected:

View File

@ -59,13 +59,16 @@ void Player::Update()
********************************************************/ ********************************************************/
void Player::Move(const PLAYER_MOVEMENT &movement) void Player::Move(const PLAYER_MOVEMENT &movement)
{ {
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
switch(movement) switch(movement)
{ {
case PLAYER_MOVEMENT_FORWARD: case PLAYER_MOVEMENT_FORWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
break; break;
case PLAYER_MOVEMENT_BACKWARD: case PLAYER_MOVEMENT_BACKWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
break; break;
case PLAYER_MOVEMENT_LEFT: case PLAYER_MOVEMENT_LEFT:
@ -93,7 +96,7 @@ void Player::UseWeapon(const WEAPON_FIRE &fireInput)
********************************************************/ ********************************************************/
void Player::Jump() void Player::Jump()
{ {
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
} }
bool Player::IsWalking() bool Player::IsWalking()
@ -114,6 +117,11 @@ Oyster::Math::Float3 Player::GetPos()
return rigidBody->GetCenter(); return rigidBody->GetCenter();
} }
Oyster::Math::Float3 Player::GetLookDir()
{
return myData->lookDir;
}
/******************************************************** /********************************************************
* Respawns the player on a new chosen position * Respawns the player on a new chosen position
* This resets a set of variables such as life, ammo etcetc * This resets a set of variables such as life, ammo etcetc
@ -122,3 +130,9 @@ void Player::Respawn()
{ {
} }
void Player::DamageLife(int damage)
{
myData->life -= damage;
}

View File

@ -26,8 +26,12 @@ namespace GameLogic
bool IsIdle(); bool IsIdle();
Oyster::Math::Float3 GetPos(); Oyster::Math::Float3 GetPos();
Oyster::Math::Float3 GetLookDir();
void Respawn(); void Respawn();
void DamageLife(int damage);
private: private:
struct PrivateData; struct PrivateData;
PrivateData *myData; PrivateData *myData;

View File

@ -5,6 +5,7 @@
#define WEAPON_H #define WEAPON_H
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "IAttatchment.h" #include "IAttatchment.h"
#include "Player.h"
namespace GameLogic namespace GameLogic
{ {
@ -21,8 +22,8 @@ namespace GameLogic
void Use(const WEAPON_FIRE &fireInput); void Use(const WEAPON_FIRE &fireInput);
void AddNewAttatchment(IAttatchment *attatchment); void AddNewAttatchment(IAttatchment *attatchment, Player *owner);
void SwitchAttatchment(IAttatchment *attatchment, int socketID); void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner);
void RemoveAttatchment(int socketID); void RemoveAttatchment(int socketID);
void SelectAttatchment(int socketID); void SelectAttatchment(int socketID);