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 "PhysicsAPI.h"
using namespace GameLogic;
@ -19,11 +20,20 @@ struct AttatchmentMassDriver::PrivateData
AttatchmentMassDriver::AttatchmentMassDriver(void)
{
myData = new PrivateData();
this->owner = 0;
}
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
{
myData = new PrivateData();
this->owner = &owner;
}
AttatchmentMassDriver::~AttatchmentMassDriver(void)
{
delete myData;
}
/********************************************************
@ -31,7 +41,17 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void)
********************************************************/
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput)
{
ForcePush(fireInput);
//switch case to determin what functionallity to use in the attatchment
switch (fireInput)
{
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
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)
{
//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:
AttatchmentMassDriver(void);
AttatchmentMassDriver(Player &owner);
~AttatchmentMassDriver(void);
@ -15,6 +16,7 @@ namespace GameLogic
private:
void ForcePush(const WEAPON_FIRE &fireInput);
void ForcePull(const WEAPON_FIRE &fireInput);
private:
struct PrivateData;

View File

@ -1,5 +1,4 @@
#include "CollisionManager.h"
#include "RefManager.h"
#include "PhysicsAPI.h"
#include "Object.h"
#include "DynamicObject.h"
@ -13,15 +12,18 @@ namespace GameLogic
namespace CollisionManager
{
void PlayerVBox(Player &player, DynamicObject &box);
Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
{
Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer));
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj);
Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef));
Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType())
{
case OBJECT_TYPE_BOX:
//PlayerVBox(*player,(*(DynamicObject*) realObj));
PlayerVBox(*player,(*(DynamicObject*) realObj));
break;
case OBJECT_TYPE_PLAYER:
@ -31,15 +33,15 @@ namespace GameLogic
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)
{
DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox));
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj);
DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType())
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -59,13 +59,16 @@ void Player::Update()
********************************************************/
void Player::Move(const PLAYER_MOVEMENT &movement)
{
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
switch(movement)
{
case PLAYER_MOVEMENT_FORWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
break;
case PLAYER_MOVEMENT_BACKWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
break;
case PLAYER_MOVEMENT_LEFT:
@ -93,7 +96,7 @@ void Player::UseWeapon(const WEAPON_FIRE &fireInput)
********************************************************/
void Player::Jump()
{
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
}
bool Player::IsWalking()
@ -114,6 +117,11 @@ Oyster::Math::Float3 Player::GetPos()
return rigidBody->GetCenter();
}
Oyster::Math::Float3 Player::GetLookDir()
{
return myData->lookDir;
}
/********************************************************
* Respawns the player on a new chosen position
* 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();
Oyster::Math::Float3 GetPos();
Oyster::Math::Float3 GetLookDir();
void Respawn();
void DamageLife(int damage);
private:
struct PrivateData;
PrivateData *myData;

View File

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