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"
|
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;
|
2013-11-19 11:07:14 +01:00
|
|
|
|
2013-12-05 11:50:39 +01:00
|
|
|
|
2013-11-19 11:07:14 +01:00
|
|
|
Level::Level(void)
|
|
|
|
{
|
2014-01-28 15:04:25 +01:00
|
|
|
|
2013-11-19 11:07:14 +01:00
|
|
|
}
|
|
|
|
Level::~Level(void)
|
|
|
|
{
|
2014-02-10 13:25:28 +01:00
|
|
|
delete this->levelObj;
|
|
|
|
this->levelObj = NULL;
|
2013-11-19 11:07:14 +01:00
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
void Level::parseObjectType(ObjectTypeHeader* obj)
|
|
|
|
{
|
|
|
|
/*switch (obj->objectTypeID)
|
|
|
|
{
|
|
|
|
case skySphere:
|
|
|
|
// save the skysphere to be able to rotate it
|
|
|
|
break;
|
|
|
|
case jumppad:
|
|
|
|
// save direction
|
|
|
|
break;
|
|
|
|
case portal:
|
|
|
|
// save portal destination
|
|
|
|
break;
|
|
|
|
case world:
|
|
|
|
// add gravitation well here
|
|
|
|
// add outer limit of the world
|
|
|
|
case spawn:
|
|
|
|
// save spawnpoint pos
|
|
|
|
break;
|
2013-12-12 09:36:14 +01:00
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}*/
|
|
|
|
}
|
2014-02-10 16:28:25 +01:00
|
|
|
void Level::parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj)
|
2014-02-10 14:00:14 +01:00
|
|
|
{
|
|
|
|
// offset physObj med modelObj
|
|
|
|
}
|
2013-12-13 11:06:03 +01:00
|
|
|
void Level::InitiateLevel(std::string levelPath)
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
LevelLoader ll;
|
|
|
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
|
|
|
|
objects = ll.LoadLevel(levelPath);
|
|
|
|
int objCount = objects.size();
|
|
|
|
int modelCount = 0;
|
2014-02-11 09:17:16 +01:00
|
|
|
int staticObjCount = 0;
|
|
|
|
int dynamicObjCount = 0;
|
2014-02-10 14:00:14 +01:00
|
|
|
for (int i = 0; i < objCount; i++)
|
|
|
|
{
|
|
|
|
ObjectTypeHeader* obj = objects.at(i);
|
|
|
|
int id = obj->typeID;
|
|
|
|
switch (obj->typeID)
|
|
|
|
{
|
|
|
|
case ObjectType::ObjectType_LevelMetaData:
|
|
|
|
{
|
|
|
|
LevelMetaData* LevelObjData = ((LevelMetaData*)obj);
|
|
|
|
std::string levelName = LevelObjData->levelName;
|
|
|
|
// LevelObjData->worldSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Static:
|
|
|
|
{
|
|
|
|
|
|
|
|
ObjectHeader* staticObjData = ((ObjectHeader*)obj);
|
2014-02-10 16:28:25 +01:00
|
|
|
//LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj);
|
2014-02-10 14:00:14 +01:00
|
|
|
staticObjData->ModelFile;
|
|
|
|
|
2014-02-11 09:17:16 +01:00
|
|
|
ICustomBody* rigidBody_Static;
|
2014-02-10 14:41:43 +01:00
|
|
|
|
2014-02-11 09:17:16 +01:00
|
|
|
// collision shape
|
|
|
|
// radius, rotation in world, position in world, mass, restitution, static and dynamic friction
|
|
|
|
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
|
|
|
|
|
|
|
|
// add rigidbody to the logical obj
|
|
|
|
// Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this
|
|
|
|
// set object_type to objID
|
2014-02-12 13:11:35 +01:00
|
|
|
this->staticObjects.Push(new StaticObject(rigidBody, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-10 14:41:43 +01:00
|
|
|
|
2014-02-11 09:17:16 +01:00
|
|
|
this->staticObjects[staticObjCount]->objectID = modelCount++;
|
|
|
|
rigidBody->SetCustomTag(this->staticObjects[staticObjCount]);
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Dynamic:
|
|
|
|
{
|
|
|
|
ObjectHeader* staticObjData = ((ObjectHeader*)obj);
|
|
|
|
staticObjData->ModelFile;
|
|
|
|
|
|
|
|
ICustomBody* rigidBody_Dynamic;
|
2014-02-10 14:41:43 +01:00
|
|
|
|
2014-02-11 09:17:16 +01:00
|
|
|
rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f);
|
2013-12-13 11:06:03 +01:00
|
|
|
|
2014-02-12 13:11:35 +01:00
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-11 09:17:16 +01:00
|
|
|
this->dynamicObjects[dynamicObjCount]->objectID = modelCount++;
|
|
|
|
rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]);
|
2014-02-10 14:00:14 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ObjectType::ObjectType_Light:
|
|
|
|
// read on client
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-16 11:40:29 +01:00
|
|
|
}
|
|
|
|
void Level::InitiateLevel(float radius)
|
|
|
|
{
|
2014-02-11 13:41:38 +01:00
|
|
|
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
|
2014-02-12 11:36:08 +01:00
|
|
|
API::Instance().SetGravity(200);
|
2014-02-05 15:16:31 +01:00
|
|
|
int idCount = 100;
|
2014-01-29 13:18:17 +01:00
|
|
|
// add level sphere
|
2014-02-10 15:54:38 +01:00
|
|
|
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
|
2014-02-12 13:11:35 +01:00
|
|
|
levelObj = new StaticObject(rigidBody, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
|
2014-02-10 12:42:31 +01:00
|
|
|
this->levelObj->objectID = idCount++;
|
2014-01-28 15:04:25 +01:00
|
|
|
rigidBody->SetCustomTag(levelObj);
|
2014-02-03 10:42:40 +01:00
|
|
|
|
2014-01-28 15:04:25 +01:00
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
ICustomBody* rigidBody_TestBox;
|
|
|
|
|
|
|
|
int nrOfBoxex = 5;
|
2014-02-05 15:54:48 +01:00
|
|
|
int offset = 0;
|
2014-02-05 11:46:04 +01:00
|
|
|
for(int i =0; i< nrOfBoxex; i ++)
|
|
|
|
{
|
2014-02-10 15:54:38 +01:00
|
|
|
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f);
|
2014-02-05 11:46:04 +01:00
|
|
|
|
2014-02-12 13:11:35 +01:00
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-10 12:42:31 +01:00
|
|
|
this->dynamicObjects[i]->objectID = idCount++;
|
2014-02-05 11:46:04 +01:00
|
|
|
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
|
|
|
|
}
|
2014-02-10 12:42:31 +01:00
|
|
|
/*offset += nrOfBoxex;
|
2014-02-05 15:54:48 +01:00
|
|
|
for(int i =0; i< nrOfBoxex; i ++)
|
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0,5, -605 -( i*5)), 5);
|
2014-02-05 15:54:48 +01:00
|
|
|
|
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
|
|
|
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-02-05 15:54:48 +01:00
|
|
|
}
|
|
|
|
offset += nrOfBoxex;
|
|
|
|
for(int i =0; i< nrOfBoxex; i ++)
|
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(200, 620 + ( i*7), 0), 5);
|
2014-02-05 15:54:48 +01:00
|
|
|
|
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-09 21:24:09 +01:00
|
|
|
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
|
2014-02-05 15:54:48 +01:00
|
|
|
}
|
|
|
|
offset += nrOfBoxex;
|
|
|
|
for(int i =0; i< nrOfBoxex; i ++)
|
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(5, 605 + i*5, 0), 5);
|
2014-02-05 15:54:48 +01:00
|
|
|
|
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-06 21:15:28 +01:00
|
|
|
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-02-10 12:42:31 +01:00
|
|
|
}*/
|
2014-02-05 11:46:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
|
2014-02-04 16:08:28 +01:00
|
|
|
|
2014-02-12 09:32:13 +01:00
|
|
|
// add crystal
|
|
|
|
ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f);
|
2014-02-04 16:08:28 +01:00
|
|
|
|
2014-02-12 13:11:35 +01:00
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
2014-02-12 09:32:13 +01:00
|
|
|
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
|
|
|
|
this->dynamicObjects[nrOfBoxex]->objectID = idCount++;
|
|
|
|
|
2014-02-04 16:08:28 +01:00
|
|
|
|
|
|
|
|
2014-02-12 09:32:13 +01:00
|
|
|
// add house
|
|
|
|
ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f);
|
2014-02-12 13:11:35 +01:00
|
|
|
this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
|
2014-02-12 09:32:13 +01:00
|
|
|
rigidBody_House->SetCustomTag(this->staticObjects[0]);
|
|
|
|
this->staticObjects[0]->objectID = idCount++;
|
2014-02-12 13:37:21 +01:00
|
|
|
|
|
|
|
// add jumppad
|
|
|
|
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f);
|
|
|
|
|
|
|
|
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_JUMPPAD, Oyster::Math::Float3(0,1,0)));
|
|
|
|
rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]);
|
|
|
|
this->staticObjects[1]->objectID = idCount++;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-01-20 15:47:52 +01:00
|
|
|
this->teamManager.RespawnPlayerRandom(player);
|
2013-12-18 08:30:58 +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-04 16:08:28 +01:00
|
|
|
for (int i = 0; i< this->dynamicObjects.Size(); i++)
|
|
|
|
{
|
|
|
|
if(this->dynamicObjects[i]->GetID() == ID)
|
|
|
|
return this->dynamicObjects[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
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
|
|
|
}
|