Danbias/Code/Game/GameLogic/CollisionManager.cpp

90 lines
3.3 KiB
C++
Raw Normal View History

#include "PhysicsAPI.h"
#include "Object.h"
#include "DynamicObject.h"
#include "Player.h"
#include "Level.h"
#include "AttatchmentMassDriver.h"
#include "Game.h"
using namespace Oyster;
2013-12-19 10:21:03 +01:00
using namespace GameLogic;
2014-01-22 15:47:44 +01:00
void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss);
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss);
2014-01-22 15:47:44 +01:00
//Physics::ICustomBody::SubscriptMessage
2014-01-27 08:54:25 +01:00
void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
2013-12-19 10:21:03 +01:00
{
Player *player = ((Game::PlayerData*)(rigidBodyPlayer->GetCustomTag()))->player;
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
2014-01-30 11:11:45 +01:00
return;
2014-01-30 09:40:58 +01:00
switch (realObj->GetObjectType())
{
2014-01-27 08:54:25 +01:00
case OBJECT_TYPE::OBJECT_TYPE_GENERIC:
2014-01-22 15:47:44 +01:00
PlayerVObject(*player,*realObj, kineticEnergyLoss);
//return Physics::ICustomBody::SubscriptMessage_none;
break;
case OBJECT_TYPE::OBJECT_TYPE_BOX:
2014-01-22 15:47:44 +01:00
PlayerVBox(*player,(*(DynamicObject*) realObj), kineticEnergyLoss);
//return Physics::ICustomBody::SubscriptMessage_none;
break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
2014-01-22 15:47:44 +01:00
//return Physics::ICustomBody::SubscriptMessage_none;
break;
2014-01-23 08:57:46 +01:00
case OBJECT_TYPE::OBJECT_TYPE_WORLD:
int test = 5;
break;
}
2013-12-19 10:21:03 +01:00
2014-01-22 15:47:44 +01:00
//return Physics::ICustomBody::SubscriptMessage_none;
2013-12-19 10:21:03 +01:00
}
2014-01-22 15:47:44 +01:00
void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss)
2013-12-19 10:21:03 +01:00
{
//use kinetic energyloss of the collision in order too determin how much damage to take
//use as part of the damage algorithm
2013-12-19 10:21:03 +01:00
player.DamageLife(20);
}
2014-01-22 15:47:44 +01:00
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss)
{
//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
2014-01-27 08:54:25 +01:00
int damageDone = 0;
int forceThreashHold = 200;
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
{
damageDone = kineticEnergyLoss * 0.10f;
player.DamageLife(damageDone);
}
2014-01-27 08:54:25 +01:00
}
Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_none;
}
2014-01-22 15:47:44 +01:00
//Oyster::Physics::ICustomBody::SubscriptMessage
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
}
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
2014-01-16 11:40:29 +01:00
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
2014-01-16 11:40:29 +01:00
}
2014-01-30 11:11:45 +01:00
void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj, void *args)
2014-01-22 14:39:10 +01:00
{
2014-01-30 11:11:45 +01:00
Oyster::Math::Float3 pushForce = Oyster::Math::Float4(1,0,0) * (1);
2014-01-27 14:43:39 +01:00
Oyster::Physics::ICustomBody::State state;
state = obj->GetState();
state.ApplyLinearImpulse(pushForce);
obj->SetState(state);
//((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce);
2014-01-30 11:11:45 +01:00
}