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
|
|
|
}
|
2013-12-12 09:36:14 +01:00
|
|
|
|
2013-12-13 11:06:03 +01:00
|
|
|
void Level::InitiateLevel(std::string levelPath)
|
|
|
|
{
|
|
|
|
|
2014-01-16 11:40:29 +01:00
|
|
|
}
|
|
|
|
void Level::InitiateLevel(float radius)
|
|
|
|
{
|
2014-02-05 11:46:04 +01:00
|
|
|
float heading = Utility::Value::Radian(180.0f);
|
|
|
|
float attitude = Utility::Value::Radian(0.0f);
|
|
|
|
float bank = Utility::Value::Radian(0);
|
|
|
|
|
|
|
|
double c1 = cos(heading/2);
|
|
|
|
double s1 = sin(heading/2);
|
|
|
|
double c2 = cos(attitude/2);
|
|
|
|
double s2 = sin(attitude/2);
|
|
|
|
double c3 = cos(bank/2);
|
|
|
|
double s3 = sin(bank/2);
|
|
|
|
double c1c2 = c1*c2;
|
|
|
|
double s1s2 = s1*s2;
|
|
|
|
double w =c1c2*c3 - s1s2*s3;
|
|
|
|
double x =c1c2*s3 + s1s2*c3;
|
|
|
|
double y =s1*c2*c3 + c1*s2*s3;
|
|
|
|
double z =c1*s2*c3 - s1*c2*s3;
|
|
|
|
double angle = 2 * acos(w);
|
|
|
|
|
|
|
|
double norm = x*x+y*y+z*z;
|
|
|
|
if (norm < 0.001) { // when all euler angles are zero angle =0 so
|
|
|
|
// we can set axis to anything to avoid divide by zero
|
|
|
|
x=1;
|
|
|
|
y=z=0;
|
|
|
|
} else {
|
|
|
|
norm = sqrt(norm);
|
|
|
|
x /= norm;
|
|
|
|
y /= norm;
|
|
|
|
z /= norm;
|
|
|
|
}
|
2014-01-29 14:33:21 +01:00
|
|
|
|
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:46:55 +01:00
|
|
|
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 1, 1, 1);
|
2014-01-28 15:04:25 +01:00
|
|
|
|
2014-01-21 14:28:27 +01:00
|
|
|
ICustomBody::State state;
|
|
|
|
rigidBody->GetState(state);
|
2014-02-09 21:24:09 +01:00
|
|
|
state.restitutionCoeff = 0.2f;
|
2014-01-21 14:28:27 +01:00
|
|
|
rigidBody->SetState(state);
|
2014-01-29 14:33:21 +01:00
|
|
|
levelObj = new StaticObject(rigidBody, LevelCollisionBefore, 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-02-09 21:24:09 +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:46:55 +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, 1, 1, 1);
|
2014-02-05 11:46:04 +01:00
|
|
|
|
|
|
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, 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-10 12:42:31 +01:00
|
|
|
//// add crystal
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-02-10 12:42:31 +01:00
|
|
|
//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);
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-02-10 12:42:31 +01:00
|
|
|
//this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
|
|
|
//rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
|
2014-02-05 11:46:04 +01:00
|
|
|
|
2014-02-10 12:42:31 +01:00
|
|
|
//
|
2014-02-04 16:08:28 +01:00
|
|
|
|
|
|
|
|
2014-02-10 12:42:31 +01:00
|
|
|
//// add house
|
|
|
|
//ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 905, 0), 0);
|
|
|
|
//this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
|
|
|
|
//rigidBody_House->SetCustomTag(this->staticObjects[0]);
|
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
|
|
|
}
|