2013-11-19 11:07:14 +01:00
|
|
|
#include "Level.h"
|
2014-01-20 15:47:52 +01:00
|
|
|
#include "CollisionManager.h"
|
2014-02-09 16:42:26 +01:00
|
|
|
#include "Game.h"
|
2014-02-14 10:32:41 +01:00
|
|
|
#include "JumpPad.h"
|
|
|
|
#include "ExplosiveCrate.h"
|
|
|
|
#include "Portal.h"
|
2014-02-20 08:33:07 +01:00
|
|
|
#include <Resource\OResource.h>
|
2014-02-19 11:25:33 +01:00
|
|
|
|
|
|
|
//Conversion from wstring to string
|
|
|
|
#include <codecvt>
|
|
|
|
|
2013-11-19 11:07:14 +01:00
|
|
|
using namespace GameLogic;
|
2014-01-14 10:28:12 +01:00
|
|
|
using namespace Utility::DynamicMemory;
|
2014-01-16 11:40:29 +01:00
|
|
|
using namespace Oyster::Physics;
|
2014-02-25 11:46:05 +01:00
|
|
|
using namespace Oyster::Math;
|
2013-12-05 11:50:39 +01:00
|
|
|
|
2013-11-19 11:07:14 +01:00
|
|
|
Level::Level(void)
|
|
|
|
{
|
2014-02-26 10:05:07 +01:00
|
|
|
srand (time(NULL));
|
2014-02-26 11:09:24 +01:00
|
|
|
objIDCounter = 100;
|
2013-11-19 11:07:14 +01:00
|
|
|
}
|
|
|
|
Level::~Level(void)
|
|
|
|
{
|
|
|
|
}
|
2014-02-20 08:33:07 +01:00
|
|
|
Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
|
2014-02-10 14:00:14 +01:00
|
|
|
{
|
2014-02-14 11:07:03 +01:00
|
|
|
Object* gameObj = NULL;
|
2014-02-14 10:32:41 +01:00
|
|
|
|
2014-02-13 16:33:26 +01:00
|
|
|
switch ((ObjectSpecialType)obj->specialTypeID)
|
2014-02-10 14:00:14 +01:00
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
case ObjectSpecialType_None:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-14 10:32:41 +01:00
|
|
|
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
break;
|
2014-02-13 16:33:26 +01:00
|
|
|
case ObjectSpecialType_Sky:
|
|
|
|
{
|
|
|
|
float skySize = ((SkyAttributes*)obj)->skySize;
|
2014-02-19 11:09:37 +01:00
|
|
|
//gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
break;
|
2014-02-13 16:33:26 +01:00
|
|
|
case ObjectSpecialType_World:
|
|
|
|
{
|
|
|
|
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
|
|
|
|
API::Instance().SetGravity(200); // could balance gravitation with the world size
|
|
|
|
|
|
|
|
float worldSize = ((WorldAttributes*)obj)->worldSize;
|
|
|
|
float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize;
|
2014-02-14 16:03:46 +01:00
|
|
|
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
break;
|
2014-02-13 16:33:26 +01:00
|
|
|
case ObjectSpecialType_Building:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-20 08:33:07 +01:00
|
|
|
break;
|
2014-02-13 16:33:26 +01:00
|
|
|
case ObjectSpecialType_Stone:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-02-14 10:08:29 +01:00
|
|
|
case ObjectSpecialType_StandardBox:
|
2014-02-13 16:33:26 +01:00
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_RedExplosiveBox:
|
|
|
|
{
|
2014-02-25 11:46:05 +01:00
|
|
|
Oyster::Math::Float dmg = 120;
|
2014-02-21 15:02:42 +01:00
|
|
|
Oyster::Math::Float force = 500;
|
|
|
|
Oyster::Math::Float radie = 3;
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
//case ObjectSpecialType_BlueExplosiveBox:
|
|
|
|
// int dmg = 70;
|
|
|
|
// gameObj = new ExplosiveBox(rigidBody, ObjectSpecialType_BlueExplosiveBox);
|
|
|
|
// break;
|
|
|
|
case ObjectSpecialType_SpikeBox:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_Spike:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_CrystalFormation:
|
|
|
|
{
|
|
|
|
int dmg = 50;
|
|
|
|
//gameObj = new Crystal(rigidBody);
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_CrystalShard:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_JumpPad:
|
|
|
|
{
|
2014-02-14 13:54:28 +01:00
|
|
|
float power = 500; //((JumpPadAttributes*)obj)->power;
|
2014-02-13 16:33:26 +01:00
|
|
|
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
|
2014-02-14 11:07:03 +01:00
|
|
|
Oyster::Math::Float3 pushForce = dir * power;
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_Portal:
|
|
|
|
{
|
|
|
|
Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination;
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectSpecialType_Generic:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
break;
|
2014-02-25 16:10:02 +01:00
|
|
|
case ObjectSpecialType_PickupHealth:
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue);
|
2014-02-25 16:10:02 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-02-10 14:00:14 +01:00
|
|
|
default:
|
2014-02-13 16:33:26 +01:00
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
break;
|
2014-02-13 16:33:26 +01:00
|
|
|
}
|
|
|
|
return gameObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICustomBody* Level::InitRigidBodyCube( const ObjectHeader* obj)
|
|
|
|
{
|
|
|
|
ICustomBody* rigidBody = NULL;
|
|
|
|
Oyster::Math::Float3 rigidWorldPos;
|
|
|
|
Oyster::Math::Float4 rigidWorldRotation;
|
|
|
|
float rigidBodyMass;
|
|
|
|
Oyster::Math::Float3 rigidBodySize;
|
|
|
|
|
|
|
|
//offset the rigidPosition from modelspace to worldspace;
|
|
|
|
rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.box.position;
|
2014-02-14 10:09:03 +01:00
|
|
|
|
2014-02-13 16:33:26 +01:00
|
|
|
//scales the position so the collision geomentry is in the right place
|
|
|
|
rigidWorldPos = rigidWorldPos * obj->scale;
|
|
|
|
|
|
|
|
//offset the rigidRotation from modelspace to worldspace;
|
|
|
|
Oyster::Math::Quaternion worldPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->rotation[0],obj->rotation[1],obj->rotation[2]), obj->rotation[3]);
|
|
|
|
Oyster::Math::Quaternion physicsPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->boundingVolume.sphere.rotation[0],obj->boundingVolume.sphere.rotation[1],obj->boundingVolume.sphere.rotation[2]), obj->boundingVolume.sphere.rotation[3]);
|
|
|
|
Oyster::Math::Quaternion rigidWorldQuaternion = worldPosQuaternion * physicsPosQuaternion;
|
|
|
|
|
|
|
|
rigidWorldRotation = Oyster::Math::Float4(rigidWorldQuaternion);
|
|
|
|
|
|
|
|
//mass scaled
|
|
|
|
rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.box.mass;
|
|
|
|
|
|
|
|
//size scaled
|
|
|
|
rigidBodySize = (Oyster::Math::Float3)obj->boundingVolume.box.size * (Oyster::Math::Float3)obj->scale;
|
|
|
|
|
|
|
|
//create the rigid body
|
|
|
|
rigidBody = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.box.restitutionCoeff , obj->boundingVolume.box.frictionCoeffStatic , obj->boundingVolume.box.frictionCoeffDynamic);
|
|
|
|
return rigidBody;
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
2014-02-13 16:33:26 +01:00
|
|
|
ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj)
|
2014-02-10 14:00:14 +01:00
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
ICustomBody* rigidBody = NULL;
|
|
|
|
Oyster::Math::Float3 rigidWorldPos;
|
|
|
|
Oyster::Math::Float4 rigidWorldRotation;
|
|
|
|
float rigidBodyMass;
|
|
|
|
float rigidBodyRadius;
|
|
|
|
|
|
|
|
//offset the rigidPosition from modelspace to worldspace;
|
|
|
|
rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.sphere.position;
|
|
|
|
//scales the position so the collision geomentry is in the right place
|
|
|
|
rigidWorldPos = rigidWorldPos * obj->scale;
|
|
|
|
|
|
|
|
//offset the rigidRotation from modelspace to worldspace;
|
|
|
|
Oyster::Math::Quaternion worldPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->rotation[0],obj->rotation[1],obj->rotation[2]), obj->rotation[3]);
|
|
|
|
Oyster::Math::Quaternion physicsPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->boundingVolume.sphere.rotation[0],obj->boundingVolume.sphere.rotation[1],obj->boundingVolume.sphere.rotation[2]), obj->boundingVolume.sphere.rotation[3]);
|
|
|
|
Oyster::Math::Quaternion rigidWorldQuaternion = worldPosQuaternion * physicsPosQuaternion;
|
|
|
|
|
|
|
|
rigidWorldRotation = Oyster::Math::Float4(rigidWorldQuaternion);
|
|
|
|
|
|
|
|
|
|
|
|
//mass scaled
|
|
|
|
rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.sphere.mass;
|
|
|
|
|
|
|
|
//Radius scaled
|
2014-02-20 09:21:38 +01:00
|
|
|
rigidBodyRadius = (obj->scale[0]) * obj->boundingVolume.sphere.radius;
|
|
|
|
//rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius;
|
2014-02-13 16:33:26 +01:00
|
|
|
|
|
|
|
//create the rigid body
|
|
|
|
rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic);
|
|
|
|
return rigidBody;
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
2014-02-18 21:50:51 +01:00
|
|
|
bool Level::InitiateLevel(std::wstring levelPath)
|
2013-12-13 11:06:03 +01:00
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
LevelLoader ll;
|
2014-02-19 11:25:33 +01:00
|
|
|
ll.SetFolderPath("..\\Content\\Worlds\\");
|
2014-02-10 14:00:14 +01:00
|
|
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
|
2014-02-19 11:25:33 +01:00
|
|
|
|
|
|
|
//Convert from wstring to string
|
|
|
|
typedef std::codecvt_utf8<wchar_t> convert_typeX;
|
2014-02-19 15:57:52 +01:00
|
|
|
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
2014-02-19 11:25:33 +01:00
|
|
|
|
|
|
|
std::string convertedLevelPath = converterX.to_bytes(levelPath);
|
|
|
|
objects = ll.LoadLevel(convertedLevelPath);
|
|
|
|
|
2014-02-18 21:50:51 +01:00
|
|
|
if(objects.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
2014-02-13 16:33:26 +01:00
|
|
|
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
|
|
|
|
API::Instance().SetGravity(200);
|
2014-02-19 15:57:52 +01:00
|
|
|
int objCount = (int)objects.size();
|
2014-02-13 16:33:26 +01:00
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
for (int i = 0; i < objCount; i++)
|
|
|
|
{
|
2014-02-26 11:09:24 +01:00
|
|
|
++this->objIDCounter;
|
2014-02-10 14:00:14 +01:00
|
|
|
ObjectTypeHeader* obj = objects.at(i);
|
|
|
|
switch (obj->typeID)
|
|
|
|
{
|
|
|
|
case ObjectType::ObjectType_LevelMetaData:
|
|
|
|
{
|
|
|
|
LevelMetaData* LevelObjData = ((LevelMetaData*)obj);
|
|
|
|
std::string levelName = LevelObjData->levelName;
|
2014-02-26 10:22:08 +01:00
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
// LevelObjData->worldSize;
|
2014-02-26 10:22:08 +01:00
|
|
|
|
|
|
|
//LevelMetaData is not an object.
|
2014-02-26 11:09:24 +01:00
|
|
|
--this->objIDCounter;
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Static:
|
|
|
|
{
|
|
|
|
ObjectHeader* staticObjData = ((ObjectHeader*)obj);
|
|
|
|
staticObjData->ModelFile;
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
ICustomBody* rigidBody_Static = NULL;
|
2014-02-19 10:55:59 +01:00
|
|
|
|
2014-02-11 09:17:16 +01:00
|
|
|
// collision shape
|
2014-02-19 12:09:42 +01:00
|
|
|
if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere)
|
2014-02-12 14:48:58 +01:00
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
rigidBody_Static = InitRigidBodySphere(staticObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box)
|
|
|
|
{
|
2014-02-14 10:09:03 +01:00
|
|
|
rigidBody_Static = InitRigidBodyCube(staticObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
//rigidBody_Static = InitRigidBodyCylinder(staticObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(rigidBody_Static != NULL)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
// create game object
|
2014-02-20 08:33:07 +01:00
|
|
|
Object* staticGameObj = CreateGameObj(staticObjData, rigidBody_Static);
|
2014-02-25 16:10:02 +01:00
|
|
|
|
|
|
|
if(staticObjData->specialTypeID == ObjectSpecialType_PickupHealth)
|
|
|
|
{
|
|
|
|
this->pickupSystem.CreatePickup((PickupHealth*)staticGameObj);
|
|
|
|
}
|
|
|
|
else if(staticGameObj != NULL)
|
2014-02-13 16:33:26 +01:00
|
|
|
{
|
|
|
|
this->staticObjects.Push((StaticObject*)staticGameObj);
|
|
|
|
}
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Dynamic:
|
|
|
|
{
|
2014-02-12 14:48:58 +01:00
|
|
|
ObjectHeader* dynamicObjData = ((ObjectHeader*)obj);
|
|
|
|
dynamicObjData->ModelFile;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
ICustomBody* rigidBody_Dynamic = NULL;
|
2014-02-10 14:41:43 +01:00
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
// collision shape
|
|
|
|
if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Sphere)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
rigidBody_Dynamic = InitRigidBodySphere(dynamicObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Box)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
rigidBody_Dynamic = InitRigidBodyCube(dynamicObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
//rigidBody_Dynamic = InitRigidBodyCylinder(dynamicObjData);
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(rigidBody_Dynamic != NULL)
|
|
|
|
{
|
2014-02-13 16:33:26 +01:00
|
|
|
// create game object
|
2014-02-20 08:33:07 +01:00
|
|
|
Object* dynamicGameObj = CreateGameObj(dynamicObjData, rigidBody_Dynamic);
|
2014-02-13 16:33:26 +01:00
|
|
|
if (dynamicGameObj != NULL)
|
|
|
|
{
|
2014-02-20 10:33:27 +01:00
|
|
|
dynamicGameObj->GetRigidBody()->SetSubscription(Level::PhysicsOnMoveLevel);
|
2014-02-13 16:33:26 +01:00
|
|
|
this->dynamicObjects.Push((DynamicObject*)dynamicGameObj);
|
|
|
|
}
|
2014-02-12 14:48:58 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Light:
|
|
|
|
// read on client
|
|
|
|
break;
|
2014-02-14 16:03:46 +01:00
|
|
|
case ObjectType::ObjectType_SpawnPoint:
|
|
|
|
{
|
|
|
|
Oyster::Math::Float3 pos;
|
|
|
|
pos.x = ((SpawnPointAttributes*)obj)->position[0];
|
|
|
|
pos.y = ((SpawnPointAttributes*)obj)->position[1];
|
|
|
|
pos.z = ((SpawnPointAttributes*)obj)->position[2];
|
|
|
|
spawnPoints.Push(pos);
|
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 16:10:02 +01:00
|
|
|
|
2014-02-18 21:50:51 +01:00
|
|
|
return true;
|
2014-01-16 11:40:29 +01:00
|
|
|
}
|
2013-12-13 11:06:03 +01:00
|
|
|
|
2013-12-18 08:30:58 +01:00
|
|
|
void Level::AddPlayerToTeam(Player *player, int teamID)
|
|
|
|
{
|
2014-01-20 15:47:52 +01:00
|
|
|
this->teamManager.AddPlayerToTeam(player,teamID);
|
2013-12-18 08:30:58 +01:00
|
|
|
}
|
2014-02-25 11:46:05 +01:00
|
|
|
void Level::AddPlayerToGame(Player *player)
|
|
|
|
{
|
2014-02-26 14:55:29 +01:00
|
|
|
int i = rand() % spawnPoints.Size();
|
|
|
|
Float3 spawnPoint = spawnPoints[i];
|
|
|
|
player->ResetPlayer(spawnPoint);
|
2014-02-26 10:05:07 +01:00
|
|
|
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
|
|
|
{
|
|
|
|
if (!this->playerObjects[i])
|
|
|
|
{
|
|
|
|
this->playerObjects[i] = player;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if no free space, allocate a new spot
|
2014-02-25 11:46:05 +01:00
|
|
|
this->playerObjects.Push(player);
|
|
|
|
}
|
|
|
|
void Level::RemovePlayerFromGame(Player *player)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
|
|
|
{
|
|
|
|
if ((Player*)this->playerObjects[i] == player)
|
|
|
|
{
|
2014-02-26 10:05:07 +01:00
|
|
|
this->playerObjects[i] = nullptr;
|
2014-02-25 11:46:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-18 08:30:58 +01:00
|
|
|
void Level::CreateTeam(int teamSize)
|
|
|
|
{
|
2014-01-20 15:47:52 +01:00
|
|
|
this->teamManager.CreateTeam(teamSize);
|
2013-12-18 08:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Level::RespawnPlayer(Player *player)
|
|
|
|
{
|
2014-02-25 11:46:05 +01:00
|
|
|
//this->teamManager.RespawnPlayerRandom(player);
|
2013-12-18 08:30:58 +01:00
|
|
|
|
2014-02-26 10:05:07 +01:00
|
|
|
int i = rand() % spawnPoints.Size();
|
|
|
|
Float3 spawnPoint = spawnPoints[i];
|
2014-02-25 11:46:05 +01:00
|
|
|
player->Respawn(spawnPoint);
|
|
|
|
}
|
|
|
|
void Level::Update(float deltaTime)
|
|
|
|
{
|
|
|
|
// update lvl-things
|
2014-02-26 12:00:30 +01:00
|
|
|
|
|
|
|
|
2014-02-25 11:46:05 +01:00
|
|
|
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
|
|
|
{
|
2014-02-26 14:55:29 +01:00
|
|
|
if(this->playerObjects[i])
|
2014-02-26 12:00:30 +01:00
|
|
|
{
|
2014-02-26 14:55:29 +01:00
|
|
|
if(this->playerObjects[i]->getAffectingPlayer() != NULL)
|
|
|
|
{
|
2014-02-26 12:00:30 +01:00
|
|
|
|
2014-02-26 14:55:29 +01:00
|
|
|
}
|
2014-02-26 12:00:30 +01:00
|
|
|
|
2014-02-26 14:55:29 +01:00
|
|
|
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
|
|
|
|
{
|
|
|
|
// true when timer reaches 0
|
|
|
|
if(this->playerObjects[i]->deathTimerTick(deltaTime))
|
|
|
|
RespawnPlayer(this->playerObjects[i]);
|
|
|
|
}
|
|
|
|
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
|
2014-02-26 10:05:07 +01:00
|
|
|
{
|
2014-02-26 14:55:29 +01:00
|
|
|
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
|
|
|
|
// HACK to avoid crasch. affected by tag is NULL
|
|
|
|
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
|
|
|
|
Player* killer = this->playerObjects[i]->getAffectingPlayer();
|
|
|
|
if(!killer) //if there is no killer then you commited suicide
|
|
|
|
{
|
|
|
|
killer = this->playerObjects[i];
|
|
|
|
}
|
|
|
|
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID
|
2014-02-26 10:05:07 +01:00
|
|
|
}
|
2014-02-26 12:00:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < dynamicObjects.Size(); i++)
|
|
|
|
{
|
|
|
|
if(dynamicObjects[i]->getAffectingPlayer() != NULL)
|
|
|
|
{
|
|
|
|
Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
|
|
|
|
|
|
|
|
if(vel <= 0.1f) // is bearly moving
|
|
|
|
{
|
|
|
|
//set the tag AffectedBy to NULL
|
|
|
|
dynamicObjects[i]->RemoveAffectedBy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < playerObjects.Size(); i++)
|
|
|
|
{
|
|
|
|
if(playerObjects[i]->getAffectingPlayer() != NULL)
|
|
|
|
{
|
|
|
|
Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
|
|
|
|
|
|
|
|
if(vel <= 0.1f) // is bearly moving
|
2014-02-26 10:05:07 +01:00
|
|
|
{
|
2014-02-26 12:00:30 +01:00
|
|
|
//set the tag AffectedBy to NULL
|
|
|
|
playerObjects[i]->RemoveAffectedBy();
|
2014-02-26 10:05:07 +01:00
|
|
|
}
|
2014-02-25 11:46:05 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 14:35:27 +01:00
|
|
|
|
2014-02-25 16:10:02 +01:00
|
|
|
this->pickupSystem.Update();
|
2014-02-25 11:46:05 +01:00
|
|
|
}
|
2014-02-05 11:46:04 +01:00
|
|
|
int Level::getNrOfDynamicObj()
|
|
|
|
{
|
|
|
|
return this->dynamicObjects.Size();
|
|
|
|
}
|
2014-01-28 15:04:25 +01:00
|
|
|
Object* Level::GetObj( int ID) const
|
|
|
|
{
|
2014-02-18 13:47:40 +01:00
|
|
|
for (int i = 0; i < (int)this->dynamicObjects.Size(); i++)
|
2014-02-04 16:08:28 +01:00
|
|
|
{
|
|
|
|
if(this->dynamicObjects[i]->GetID() == ID)
|
|
|
|
return this->dynamicObjects[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
2014-01-28 15:04:25 +01:00
|
|
|
}
|
2014-02-25 11:46:05 +01:00
|
|
|
|
2014-01-28 15:04:25 +01:00
|
|
|
void Level::PhysicsOnMoveLevel(const ICustomBody *object)
|
|
|
|
{
|
|
|
|
// function call from physics update when object was moved
|
|
|
|
Object* temp = (Object*)object->GetCustomTag();
|
2014-02-09 16:42:26 +01:00
|
|
|
((Game*)&Game::Instance())->onMoveFnc(temp);
|
2014-01-28 15:04:25 +01:00
|
|
|
}
|
2014-02-26 11:09:24 +01:00
|
|
|
Utility::DynamicMemory::DynamicArray<Player*> Level::GetPlayers()
|
2014-02-25 11:46:05 +01:00
|
|
|
{
|
|
|
|
return this->playerObjects;
|
|
|
|
}
|
|
|
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> Level::GetStaticObjects()
|
|
|
|
{
|
|
|
|
return this->staticObjects;
|
|
|
|
}
|
|
|
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> Level::GetDynamicObject()
|
|
|
|
{
|
|
|
|
return this->dynamicObjects;
|
|
|
|
}
|
2014-02-21 15:42:09 +01:00
|
|
|
|