This commit is contained in:
Erik Persson 2014-02-25 10:37:33 +01:00
parent 1b0772a004
commit bc17a9f09e
8 changed files with 156 additions and 15 deletions

View File

@ -99,6 +99,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
forcePushData args; forcePushData args;
args.pushForce = pushForce; args.pushForce = pushForce;
args.p = this->owner;
Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction);
@ -136,6 +137,7 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius);
forcePushData args; forcePushData args;
args.pushForce = -pushForce; args.pushForce = -pushForce;
args.p = this->owner;
Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction);

View File

@ -113,7 +113,7 @@ using namespace GameLogic;
Object *realObjA = ((Object*)(objA->GetCustomTag())); Object *realObjA = ((Object*)(objA->GetCustomTag()));
Object *realObjB = (Object*)objB->GetCustomTag(); //needs to be changed? Object *realObjB = (Object*)objB->GetCustomTag();
ExplosiveCrate* crate; ExplosiveCrate* crate;
if(!realObjA) if(!realObjA)
@ -166,11 +166,15 @@ using namespace GameLogic;
Player *hitPlayer = (Player*)realObj; Player *hitPlayer = (Player*)realObj;
hitPlayer->DamageLife(ExplosionSource->extraDamageOnCollision); hitPlayer->DamageLife(ExplosionSource->extraDamageOnCollision);
//hitPlayer->GetRigidBody()->ApplyImpulse(force); //hitPlayer->GetRigidBody()->ApplyImpulse(force);
//hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
realObj->GetRigidBody()->ApplyImpulse(force * 5);
//do shredding damage //do shredding damage
} }
} }
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss)
@ -226,6 +230,58 @@ using namespace GameLogic;
{ {
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
} }
void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss)
{
DynamicObject *realObjA = dynamic_cast<DynamicObject*>((Object*)objA->GetCustomTag());
DynamicObject *realObjB = dynamic_cast<DynamicObject*>((Object*)objB->GetCustomTag());
if(!realObjA || !realObjB) // one of the objects cannot be cast into a dynamicObject and so we leave the function
{
return;
}
//check which obj is the one that is already affected, if both are then use the special case of changing ownership.
if(realObjA->getAffectingPlayer() == NULL && realObjB->getAffectingPlayer() == NULL) //None of the objects have a player affecting them
{
return;//leave function as the are not to transfer any ownership
}
if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() == NULL)
{
//realobjA is the affectedObject, transfer this to realobjB
realObjB->SetAffectedBy(*realObjA->getAffectingPlayer());
}
if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL)
{
//realobjB is the affectedObject, transfer this to realobjA
realObjA->SetAffectedBy(*realObjB->getAffectingPlayer());
}
if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL)
{
//Both objects have a player affecting them, now use the special case
if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() )
{
//realObjA is the winner and will change Bs ownership to A
realObjB->SetAffectedBy(*realObjA->getAffectingPlayer());
}
else
{
realObjA->SetAffectedBy(*realObjB->getAffectingPlayer());
//realObjB is the winner and will change As ownership to B
}
}
}
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{ {
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
@ -250,7 +306,16 @@ using namespace GameLogic;
if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World)
return; return;
obj->ApplyImpulse(((forcePushData*)(args))->pushForce); obj->ApplyImpulse(((forcePushData*)(args))->pushForce);
DynamicObject *dynamicObj = dynamic_cast<DynamicObject*>(realObj);
if(dynamicObj)
{
dynamicObj->SetAffectedBy(*((forcePushData*)(args))->p);
}
} }
void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args) void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args)

View File

@ -1,5 +1,6 @@
#include "DynamicObject.h" #include "DynamicObject.h"
#include "CollisionManager.h" #include "CollisionManager.h"
#include "Player.h"
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Math; using namespace Oyster::Math;
@ -10,6 +11,7 @@ DynamicObject::DynamicObject()
{ {
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL;
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
@ -17,12 +19,14 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev
{ {
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL;
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID) :Object(rigidBody, EventOnCollision, type, objectID)
{ {
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL;
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
@ -31,6 +35,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev
this->extraDamageOnCollision = extraDamageOnCollision; this->extraDamageOnCollision = extraDamageOnCollision;
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL;
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
@ -39,6 +44,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P
this->extraDamageOnCollision = extraDamageOnCollision; this->extraDamageOnCollision = extraDamageOnCollision;
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL;
} }
DynamicObject::~DynamicObject(void) DynamicObject::~DynamicObject(void)
{ {
@ -75,3 +81,23 @@ void DynamicObject::Activate()
this->isActive = true; this->isActive = true;
this->isReleased = false; this->isReleased = false;
} }
void DynamicObject::SetAffectedBy(Player &player)
{
this->affectedBy = &player;
if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player
{
player.AddAffectedObject(*this);
}
}
Player* DynamicObject::getAffectingPlayer()
{
return this->affectedBy;
}
void DynamicObject::RemoveAffectedBy()
{
this->affectedBy = NULL;
}

View File

@ -9,6 +9,7 @@
namespace GameLogic namespace GameLogic
{ {
class Player;
class DynamicObject : public Object class DynamicObject : public Object
{ {
@ -28,9 +29,17 @@ namespace GameLogic
void Inactivate(); void Inactivate();
void Activate(); void Activate();
void SetAffectedBy(GameLogic::Player &player);
void RemoveAffectedBy();
GameLogic::Player* getAffectingPlayer();
static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
private: private:
bool isActive; bool isActive;
bool isReleased; bool isReleased;
protected:
GameLogic::Player *affectedBy;
}; };

View File

@ -2,8 +2,10 @@
#define GAMELOGICSTATES_H #define GAMELOGICSTATES_H
#include "OysterMath.h" #include "OysterMath.h"
namespace GameLogic namespace GameLogic
{ {
class Player;
enum PLAYER_MOVEMENT enum PLAYER_MOVEMENT
{ {
PLAYER_MOVEMENT_FORWARD = 0, PLAYER_MOVEMENT_FORWARD = 0,
@ -41,6 +43,7 @@ namespace GameLogic
struct forcePushData struct forcePushData
{ {
Oyster::Math::Float3 pushForce; Oyster::Math::Float3 pushForce;
Player *p;
}; };

View File

@ -59,12 +59,12 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break; break;
case ObjectSpecialType_Stone: case ObjectSpecialType_Stone:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_StandardBox: case ObjectSpecialType_StandardBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_RedExplosiveBox: case ObjectSpecialType_RedExplosiveBox:
@ -81,12 +81,12 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
// break; // break;
case ObjectSpecialType_SpikeBox: case ObjectSpecialType_SpikeBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Spike: case ObjectSpecialType_Spike:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_CrystalFormation: case ObjectSpecialType_CrystalFormation:
@ -98,7 +98,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break; break;
case ObjectSpecialType_CrystalShard: case ObjectSpecialType_CrystalShard:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_JumpPad: case ObjectSpecialType_JumpPad:

View File

@ -18,6 +18,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
:DynamicObject(rigidBody, EventOnCollision, type, objectID) :DynamicObject(rigidBody, EventOnCollision, type, objectID)
{ {
weapon = new Weapon(2,this); weapon = new Weapon(2,this);
AffectedObjects.Reserve(15);
this->life = 100; this->life = 100;
this->teamID = teamID; this->teamID = teamID;
@ -46,6 +48,9 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
{ {
weapon = new Weapon(2,this); weapon = new Weapon(2,this);
AffectedObjects.Reserve(15);
this->life = 100; this->life = 100;
this->teamID = teamID; this->teamID = teamID;
this->playerState = PLAYER_STATE_IDLE; this->playerState = PLAYER_STATE_IDLE;
@ -213,6 +218,16 @@ void Player::BeginFrame()
void Player::EndFrame() void Player::EndFrame()
{ {
//check if there are any objects that can be removed from the AffectedObjects list
for(int i = 0; i < this->AffectedObjects.Size(); i++)
{
if((this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f)
{
this->AffectedObjects[i]->RemoveAffectedBy();
this->AffectedObjects.Remove(i);
}
}
} }
@ -334,8 +349,7 @@ PLAYER_STATE Player::GetState() const
void Player::DamageLife(int damage) void Player::DamageLife(int damage)
{ {
if( this->playerState != PLAYER_STATE_DEAD)
{
this->life -= damage; this->life -= damage;
this->gameInstance->onDamageTakenFnc( this, this->life); this->gameInstance->onDamageTakenFnc( this, this->life);
@ -346,5 +360,20 @@ void Player::DamageLife(int damage)
this->deathTimeLeft = this->deathTime; this->deathTimeLeft = this->deathTime;
this->gameInstance->onDeadFnc(this, this->deathTimeLeft); this->gameInstance->onDeadFnc(this, this->deathTimeLeft);
} }
}
}
void Player::AddAffectedObject(DynamicObject &AffectedObject)
{
//check if object already exists in the list, if so then do not add
for(int i = 0; i < AffectedObjects.Size(); i++)
{
if(AffectedObjects[i]->GetID() == AffectedObject.GetID())
{
//object already exists, exit function
return;
}
}
//else you add the object to the stack
AffectedObjects.Push(&AffectedObject);
} }

View File

@ -7,6 +7,7 @@
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "OysterMath.h" #include "OysterMath.h"
#include "DynamicObject.h" #include "DynamicObject.h"
#include "DynamicArray.h"
namespace GameLogic namespace GameLogic
@ -50,6 +51,8 @@ namespace GameLogic
void TurnLeft(Oyster::Math3D::Float deltaRadians); void TurnLeft(Oyster::Math3D::Float deltaRadians);
void AddAffectedObject(DynamicObject &AffectedObject);
/******************************************************** /********************************************************
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody * 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 * Will be called when the physics detect a collision
@ -77,10 +80,14 @@ namespace GameLogic
void EndFrame(); void EndFrame();
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
private: private:
void Jump(); void Jump();
private: private:
Utility::DynamicMemory::DynamicArray<DynamicObject*> AffectedObjects;
Oyster::Math::Float life; Oyster::Math::Float life;
int teamID; int teamID;
Weapon *weapon; Weapon *weapon;