2013-12-12 09:36:14 +01:00
|
|
|
#include "PhysicsAPI.h"
|
|
|
|
#include "Object.h"
|
|
|
|
#include "DynamicObject.h"
|
|
|
|
#include "Player.h"
|
2014-01-21 15:46:54 +01:00
|
|
|
#include "Level.h"
|
2014-01-22 14:26:45 +01:00
|
|
|
#include "AttatchmentMassDriver.h"
|
2014-01-27 13:54:57 +01:00
|
|
|
#include "Game.h"
|
2014-02-03 15:32:46 +01:00
|
|
|
#include "CollisionManager.h"
|
2014-02-04 16:24:37 +01:00
|
|
|
#include "JumpPad.h"
|
2014-02-13 09:58:14 +01:00
|
|
|
#include "Portal.h"
|
2014-02-14 09:53:02 +01:00
|
|
|
#include "ExplosiveCrate.h"
|
2013-11-26 09:19:59 +01:00
|
|
|
|
2013-12-03 11:47:04 +01:00
|
|
|
using namespace Oyster;
|
2013-11-26 09:19:59 +01:00
|
|
|
|
2013-12-19 10:21:03 +01:00
|
|
|
using namespace GameLogic;
|
2013-11-28 09:26:29 +01:00
|
|
|
|
2014-01-22 15:47:44 +01:00
|
|
|
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss);
|
2014-02-14 09:53:02 +01:00
|
|
|
void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage);
|
2014-02-04 16:24:37 +01:00
|
|
|
void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force);
|
2014-02-13 09:58:14 +01:00
|
|
|
void Teleport(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 target);
|
2013-11-28 11:23:11 +01:00
|
|
|
|
2014-01-22 15:47:44 +01:00
|
|
|
//Physics::ICustomBody::SubscriptMessage
|
2014-02-21 11:10:47 +01:00
|
|
|
void Player::PlayerCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss)
|
2013-12-19 10:21:03 +01:00
|
|
|
{
|
2014-02-21 11:10:47 +01:00
|
|
|
Object *realObjA = ((Object*)(objA->GetCustomTag()));
|
|
|
|
Player *player;
|
|
|
|
Object *realObjB = (Object*)objB->GetCustomTag(); //needs to be changed?
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2014-02-21 11:10:47 +01:00
|
|
|
if(!realObjA)
|
2014-02-20 09:23:33 +01:00
|
|
|
return;
|
2014-02-21 11:10:47 +01:00
|
|
|
if(!realObjB)
|
2014-02-20 09:23:33 +01:00
|
|
|
return;
|
2014-02-20 09:14:42 +01:00
|
|
|
|
2014-02-21 11:10:47 +01:00
|
|
|
//check who is player and who is the object
|
|
|
|
if(realObjA->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player)
|
|
|
|
{
|
|
|
|
player = (Player*)realObjA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player = (Player*)realObjB;
|
|
|
|
realObjB = realObjA;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (realObjB->GetObjectType())
|
2014-01-21 15:46:54 +01:00
|
|
|
{
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_Generic:
|
2014-02-21 11:10:47 +01:00
|
|
|
PlayerVObject(*player,*realObjB, kineticEnergyLoss);
|
2014-01-22 15:47:44 +01:00
|
|
|
//return Physics::ICustomBody::SubscriptMessage_none;
|
2014-01-21 15:46:54 +01:00
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
|
|
|
|
case ObjectSpecialType::ObjectSpecialType_StandardBox:
|
2014-02-21 11:10:47 +01:00
|
|
|
PlayerVObject(*player,*realObjB, kineticEnergyLoss);
|
2014-02-14 09:53:02 +01:00
|
|
|
//return Physics::ICustomBody::SubscriptMessage_none;
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType::ObjectSpecialType_Player:
|
2014-01-22 15:47:44 +01:00
|
|
|
//return Physics::ICustomBody::SubscriptMessage_none;
|
2014-01-21 15:46:54 +01:00
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_World:
|
2014-02-21 11:10:47 +01:00
|
|
|
PlayerVObject(*player,*realObjB, kineticEnergyLoss);
|
2014-02-12 13:11:35 +01:00
|
|
|
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
|
2014-01-23 08:57:46 +01:00
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
|
|
|
|
case ObjectSpecialType::ObjectSpecialType_CrystalFormation:
|
2014-02-21 11:10:47 +01:00
|
|
|
PlayerVLethalObject(*player,*realObjB, kineticEnergyLoss,realObjB->GetExtraDamageOnCollision());
|
2014-02-14 09:53:02 +01:00
|
|
|
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
|
|
|
|
break;
|
2014-01-21 15:46:54 +01:00
|
|
|
}
|
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-02-04 16:24:37 +01:00
|
|
|
|
|
|
|
void JumpPad::JumpPadActivated(Oyster::Physics::ICustomBody *rigidBodyJumpPad, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
|
|
|
|
{
|
|
|
|
JumpPad *jumpPad = (JumpPad*)(rigidBodyJumpPad->GetCustomTag());
|
|
|
|
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
|
|
|
|
|
|
|
|
switch (realObj->GetObjectType())
|
|
|
|
{
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_Generic:
|
2014-02-04 16:24:37 +01:00
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_StandardBox:
|
2014-02-04 16:24:37 +01:00
|
|
|
SendObjectFlying(*obj, jumpPad->pushForce);
|
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_Player:
|
|
|
|
SendObjectFlying(*obj, jumpPad->pushForce);
|
2014-02-04 16:24:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force)
|
|
|
|
{
|
2014-02-12 14:45:10 +01:00
|
|
|
obj.ApplyImpulse(force);
|
2014-02-04 16:24:37 +01:00
|
|
|
}
|
2014-02-13 09:58:14 +01:00
|
|
|
|
|
|
|
void Portal::PortalActivated(Oyster::Physics::ICustomBody *rigidBodyPortal, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
|
|
|
|
{
|
|
|
|
Portal *portal = (Portal*)(rigidBodyPortal->GetCustomTag());
|
|
|
|
|
|
|
|
if(obj->GetState().mass == 0) return;
|
|
|
|
|
|
|
|
Teleport(*obj,portal->portalExit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Teleport(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 target)
|
|
|
|
{
|
|
|
|
obj.SetPosition(target);
|
|
|
|
}
|
2014-02-14 09:53:02 +01:00
|
|
|
|
2014-02-21 15:02:42 +01:00
|
|
|
void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss)
|
2014-02-14 09:53:02 +01:00
|
|
|
{
|
2014-02-21 15:02:42 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
|
2014-02-21 15:02:42 +01:00
|
|
|
Object *realObjA = ((Object*)(objA->GetCustomTag()));
|
|
|
|
Object *realObjB = (Object*)objB->GetCustomTag(); //needs to be changed?
|
|
|
|
ExplosiveCrate* crate;
|
2014-02-14 09:53:02 +01:00
|
|
|
|
2014-02-21 15:02:42 +01:00
|
|
|
if(!realObjA)
|
|
|
|
return;
|
|
|
|
if(!realObjB)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//check who is player and who is the object
|
|
|
|
if(realObjA->GetObjectType() == ObjectSpecialType::ObjectSpecialType_RedExplosiveBox)
|
|
|
|
{
|
|
|
|
crate = (ExplosiveCrate*)realObjA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
crate = (ExplosiveCrate*)realObjB;
|
|
|
|
realObjB = realObjA;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (realObjB->GetObjectType())
|
2014-02-14 09:53:02 +01:00
|
|
|
{
|
2014-02-14 13:54:50 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_Generic:
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType::ObjectSpecialType_StandardBox:
|
|
|
|
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType::ObjectSpecialType_Player:
|
2014-02-21 15:02:42 +01:00
|
|
|
if(crate->hasExploaded) return;
|
|
|
|
Oyster::Math::Float3 pos = crate->GetRigidBody()->GetState().centerPos;
|
2014-02-14 09:53:02 +01:00
|
|
|
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius);
|
|
|
|
|
|
|
|
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
|
2014-02-21 15:02:42 +01:00
|
|
|
crate->hasExploaded = true;
|
2014-02-14 09:53:02 +01:00
|
|
|
delete hitSphere;
|
2014-02-14 13:54:50 +01:00
|
|
|
break;
|
2014-02-14 09:53:02 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 16:20:50 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args)
|
|
|
|
{
|
|
|
|
Object *realObj = (Object*)obj->GetCustomTag();
|
|
|
|
ExplosiveCrate* ExplosionSource = ((ExplosiveCrate*)args);
|
|
|
|
|
2014-02-14 10:56:38 +01:00
|
|
|
Oyster::Math::Float3 explosionCenterPos = ExplosionSource->GetPosition();
|
|
|
|
Oyster::Math::Float3 hitObjectPos = obj->GetState().centerPos;
|
|
|
|
Oyster::Math::Float3 force = (((hitObjectPos- explosionCenterPos).GetNormalized()) * ExplosionSource->pushForceMagnitude);
|
2014-02-21 15:02:42 +01:00
|
|
|
|
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player)
|
|
|
|
{
|
|
|
|
Player *hitPlayer = (Player*)realObj;
|
2014-02-21 15:54:43 +01:00
|
|
|
hitPlayer->DamageLife(ExplosionSource->extraDamageOnCollision);
|
|
|
|
//hitPlayer->GetRigidBody()->ApplyImpulse(force);
|
2014-02-14 09:53:02 +01:00
|
|
|
//do shredding damage
|
|
|
|
}
|
|
|
|
|
2014-02-21 15:02:42 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
|
|
|
|
}
|
2013-12-19 10:21:03 +01:00
|
|
|
|
2014-01-22 15:47:44 +01:00
|
|
|
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss)
|
2014-01-21 15:46:54 +01:00
|
|
|
{
|
|
|
|
//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-02-21 11:35:38 +01:00
|
|
|
Oyster::Math::Float3 objPrevVel = obj.GetRigidBody()->GetState().previousVelocity;
|
|
|
|
Oyster::Math::Float3 playerPrevVel = player.GetRigidBody()->GetState().previousVelocity;
|
2014-02-21 11:10:47 +01:00
|
|
|
|
2014-02-21 11:35:38 +01:00
|
|
|
Oyster::Math::Float3 deltaPos = (player.GetPosition() - obj.GetPosition());
|
|
|
|
Oyster::Math::Float deltaSpeed = (objPrevVel - playerPrevVel).GetMagnitude();
|
|
|
|
Oyster::Math::Float angularFactor = deltaPos.GetNormalized().Dot( (objPrevVel - playerPrevVel).GetNormalized());
|
|
|
|
|
|
|
|
Oyster::Math::Float impactPower = deltaSpeed * angularFactor;
|
2014-02-21 15:02:42 +01:00
|
|
|
Oyster::Math::Float damageFactor = 0.01f;
|
2014-02-21 11:56:48 +01:00
|
|
|
|
2014-02-21 11:10:47 +01:00
|
|
|
|
2014-01-27 08:54:25 +01:00
|
|
|
int damageDone = 0;
|
2014-02-21 15:02:42 +01:00
|
|
|
int forceThreashHold = 30; //FIX: balance this
|
2014-01-27 08:54:25 +01:00
|
|
|
|
2014-02-21 11:35:38 +01:00
|
|
|
if(impactPower > forceThreashHold) //should only take damage if the force is high enough
|
2014-01-27 08:54:25 +01:00
|
|
|
{
|
2014-02-21 11:56:48 +01:00
|
|
|
if(obj.GetRigidBody()->GetState().mass == 0)
|
|
|
|
{
|
|
|
|
damageDone = impactPower * damageFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
damageDone = (impactPower * obj.GetRigidBody()->GetState().mass)* damageFactor;
|
|
|
|
}
|
|
|
|
|
2014-02-21 15:02:42 +01:00
|
|
|
player.DamageLife(damageDone);
|
2014-01-27 08:54:25 +01:00
|
|
|
}
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2014-01-27 08:54:25 +01:00
|
|
|
}
|
2014-02-12 13:11:35 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
|
|
|
|
void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage)
|
|
|
|
{
|
2014-02-18 13:47:40 +01:00
|
|
|
Oyster::Math::Float damageDone = 0;
|
|
|
|
Oyster::Math::Float forceThreashHold = 200000;
|
2014-02-14 09:53:02 +01:00
|
|
|
|
|
|
|
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
|
|
|
|
{
|
2014-02-18 13:47:40 +01:00
|
|
|
damageDone = (kineticEnergyLoss * 0.10f);
|
2014-02-14 09:53:02 +01:00
|
|
|
damageDone += ExtraDamage;
|
|
|
|
//player.DamageLife(damageDone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 10:36:45 +01:00
|
|
|
Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
|
2014-02-05 11:46:04 +01:00
|
|
|
{
|
|
|
|
return Physics::ICustomBody::SubscriptMessage_none;
|
|
|
|
}
|
|
|
|
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
|
2014-01-31 10:58:03 +01:00
|
|
|
{
|
|
|
|
return Physics::ICustomBody::SubscriptMessage_none;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-02-03 15:32:46 +01:00
|
|
|
Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::IgnoreCollision(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody *obj)
|
|
|
|
{
|
|
|
|
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
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
|
|
|
{
|
2014-01-29 14:33:21 +01:00
|
|
|
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
|
2014-01-16 11:40:29 +01:00
|
|
|
}
|
2014-01-22 14:26:45 +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-02-12 11:32:30 +01:00
|
|
|
if(obj->GetState().mass == 0) return;
|
|
|
|
|
2014-01-30 15:12:53 +01:00
|
|
|
Object *realObj = (Object*)obj->GetCustomTag();
|
2014-01-31 09:12:15 +01:00
|
|
|
|
2014-02-14 09:53:02 +01:00
|
|
|
if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World)
|
2014-01-30 15:12:53 +01:00
|
|
|
return;
|
2014-01-31 14:05:52 +01:00
|
|
|
|
2014-02-12 11:32:30 +01:00
|
|
|
obj->ApplyImpulse(((forcePushData*)(args))->pushForce);
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args)
|
|
|
|
{
|
2014-02-12 11:32:30 +01:00
|
|
|
if(obj->GetState().mass == 0) return;
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
AttatchmentMassDriver *weapon = ((AttatchmentMassDriver*)args);
|
|
|
|
|
|
|
|
if(weapon->hasObject)
|
|
|
|
{
|
|
|
|
//do nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Object* realObj = (Object*)(obj->GetCustomTag());
|
|
|
|
//check so that it is an object that you can pickup
|
|
|
|
|
|
|
|
switch(realObj->GetObjectType())
|
|
|
|
{
|
2014-02-14 09:53:02 +01:00
|
|
|
case ObjectSpecialType::ObjectSpecialType_StandardBox:
|
2014-02-03 15:32:46 +01:00
|
|
|
weapon->heldObject = obj; //weapon now holds the object
|
|
|
|
weapon->hasObject = true;
|
2014-02-21 11:10:47 +01:00
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-30 11:11:45 +01:00
|
|
|
}
|