|
@@ -9,16 +9,14 @@
|
|
|
#include "WorldHandler.h"
|
|
#include "WorldHandler.h"
|
|
|
|
|
|
|
|
World::World(const std::string &fileName)
|
|
World::World(const std::string &fileName)
|
|
|
-{
|
|
|
|
|
|
|
+{
|
|
|
nextworld = false;
|
|
nextworld = false;
|
|
|
|
|
|
|
|
//Store player instance
|
|
//Store player instance
|
|
|
player = Player::getInstance();
|
|
player = Player::getInstance();
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Create the interface
|
|
//Create the interface
|
|
|
interface = new Interface();
|
|
interface = new Interface();
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Open world json file
|
|
//Open world json file
|
|
|
std::ifstream file(fileName);
|
|
std::ifstream file(fileName);
|
|
@@ -27,7 +25,6 @@ World::World(const std::string &fileName)
|
|
|
|
|
|
|
|
json::Value v = json::readJson(file);
|
|
json::Value v = json::readJson(file);
|
|
|
file.close();
|
|
file.close();
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Check file
|
|
//Check file
|
|
|
if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
|
|
if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
|
|
@@ -42,13 +39,6 @@ World::World(const std::string &fileName)
|
|
|
std::cout << "Invalid world file: enemies - " << fileName << "\n";
|
|
std::cout << "Invalid world file: enemies - " << fileName << "\n";
|
|
|
if (v["crystal"].isNull())
|
|
if (v["crystal"].isNull())
|
|
|
std::cout << "Invalid world file: crystals - " << fileName << "\n";
|
|
std::cout << "Invalid world file: crystals - " << fileName << "\n";
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (!v["world"]["loadingscreen"].isNull())
|
|
|
|
|
- {
|
|
|
|
|
- ls.setTexture(v["world"]["loadingscreen"].asString());
|
|
|
|
|
- ls.draw();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
//Load object templates
|
|
//Load object templates
|
|
|
for (auto objt : v["world"]["object-templates"])
|
|
for (auto objt : v["world"]["object-templates"])
|
|
@@ -59,28 +49,23 @@ World::World(const std::string &fileName)
|
|
|
cancollide = objt["collision"].asBool();
|
|
cancollide = objt["collision"].asBool();
|
|
|
|
|
|
|
|
objecttemplates.push_back(std::pair<int, std::pair<std::string, bool>>(objt["color"], std::pair<std::string, bool>(objt["file"], cancollide)));
|
|
objecttemplates.push_back(std::pair<int, std::pair<std::string, bool>>(objt["color"], std::pair<std::string, bool>(objt["file"], cancollide)));
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//Generate heightmap for this world
|
|
//Generate heightmap for this world
|
|
|
heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
|
|
heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Load skybox
|
|
//Load skybox
|
|
|
skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
|
|
skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
|
|
|
skybox->init();
|
|
skybox->init();
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Map different texture to heightmap if available
|
|
//Map different texture to heightmap if available
|
|
|
if(!v["world"]["texture"].isNull())
|
|
if(!v["world"]["texture"].isNull())
|
|
|
heightmap->SetTexture(v["world"]["texture"].asString());
|
|
heightmap->SetTexture(v["world"]["texture"].asString());
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Set player starting position
|
|
//Set player starting position
|
|
|
player->position.x = v["player"]["startposition"][0].asFloat();
|
|
player->position.x = v["player"]["startposition"][0].asFloat();
|
|
|
player->position.z = v["player"]["startposition"][2].asFloat();
|
|
player->position.z = v["player"]["startposition"][2].asFloat();
|
|
|
player->position.y = heightmap->GetHeight(player->position.x, player->position.z);
|
|
player->position.y = heightmap->GetHeight(player->position.x, player->position.z);
|
|
|
-
|
|
|
|
|
|
|
|
|
|
//Load and place objects into world
|
|
//Load and place objects into world
|
|
|
for (auto object : v["objects"])
|
|
for (auto object : v["objects"])
|
|
@@ -113,7 +98,6 @@ World::World(const std::string &fileName)
|
|
|
position.y = getHeight(position.x, position.z);
|
|
position.y = getHeight(position.x, position.z);
|
|
|
|
|
|
|
|
entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
|
|
entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
maxEnemies = 0;
|
|
maxEnemies = 0;
|
|
@@ -156,7 +140,6 @@ World::World(const std::string &fileName)
|
|
|
|
|
|
|
|
maxEnemies++;
|
|
maxEnemies++;
|
|
|
enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale));
|
|
enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale));
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
maxCrystals = 0;
|
|
maxCrystals = 0;
|
|
|
if (!v["crystal"].isNull())
|
|
if (!v["crystal"].isNull())
|
|
@@ -200,7 +183,6 @@ World::World(const std::string &fileName)
|
|
|
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
|
|
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
|
|
|
|
|
|
|
|
entities.push_back(c);
|
|
entities.push_back(c);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
interface->maxCrystals = maxCrystals;
|
|
interface->maxCrystals = maxCrystals;
|
|
|
}
|
|
}
|
|
@@ -210,7 +192,6 @@ World::World(const std::string &fileName)
|
|
|
{
|
|
{
|
|
|
sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
|
|
sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
|
|
|
music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
|
|
music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!v["portal"].isNull())
|
|
if (!v["portal"].isNull())
|
|
@@ -236,7 +217,6 @@ World::World(const std::string &fileName)
|
|
|
portal = new Portal(v["portal"]["file"], pos, rot, scale);
|
|
portal = new Portal(v["portal"]["file"], pos, rot, scale);
|
|
|
entities.push_back(portal);
|
|
entities.push_back(portal);
|
|
|
portal->maxCrystals = maxCrystals;
|
|
portal->maxCrystals = maxCrystals;
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -268,7 +248,7 @@ float World::getHeight(float x, float y)
|
|
|
|
|
|
|
|
void World::draw()
|
|
void World::draw()
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ player->setCamera();
|
|
|
|
|
|
|
|
float lightPosition[4] = { 0, 2, 1, 0 };
|
|
float lightPosition[4] = { 0, 2, 1, 0 };
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
|
@@ -281,9 +261,6 @@ void World::draw()
|
|
|
GLfloat mat_specular[] = { 0.15, 0.15, 0.15, 0 };
|
|
GLfloat mat_specular[] = { 0.15, 0.15, 0.15, 0 };
|
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- player->setCamera();
|
|
|
|
|
skybox->draw();
|
|
skybox->draw();
|
|
|
player->draw();
|
|
player->draw();
|
|
|
|
|
|
|
@@ -323,11 +300,14 @@ void World::update(float elapsedTime)
|
|
|
|
|
|
|
|
//Al deze code zou in enemy moeten staan
|
|
//Al deze code zou in enemy moeten staan
|
|
|
enemy->inEyeSight(player->position);
|
|
enemy->inEyeSight(player->position);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
enemy->update(elapsedTime);
|
|
enemy->update(elapsedTime);
|
|
|
if (enemy->hasTarget)
|
|
if (enemy->hasTarget)
|
|
|
{
|
|
{
|
|
|
|
|
+ if(player->hit)
|
|
|
|
|
+ enemy->hit(player->leftWeapon->damage);
|
|
|
|
|
+
|
|
|
for (auto e : entities)
|
|
for (auto e : entities)
|
|
|
{
|
|
{
|
|
|
if (e->canCollide && e->inObject(enemy->position))
|
|
if (e->canCollide && e->inObject(enemy->position))
|
|
@@ -336,24 +316,24 @@ void World::update(float elapsedTime)
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if (enemy->attack)
|
|
|
|
|
- {
|
|
|
|
|
- remove = true;
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if (enemy->attack)
|
|
|
|
|
+ {
|
|
|
|
|
+ player->HpDown(enemy->damage / 2.0f);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- enemy->position.y = getHeight(enemy->position.x, enemy->position.z);
|
|
|
|
|
|
|
+ enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 1.7f;
|
|
|
|
|
|
|
|
|
|
+ if (enemy->isDead())
|
|
|
|
|
+ remove = true;
|
|
|
if(!remove)
|
|
if(!remove)
|
|
|
count++;
|
|
count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (remove)
|
|
if (remove)
|
|
|
{
|
|
{
|
|
|
- player->XpUp(enemies[count]->xp);
|
|
|
|
|
delete enemies[count];
|
|
delete enemies[count];
|
|
|
-
|
|
|
|
|
|
|
+ player->XpUp(enemies[count]->xp*2);
|
|
|
enemies.erase(enemies.begin() + count);
|
|
enemies.erase(enemies.begin() + count);
|
|
|
player->HpUp(10);
|
|
player->HpUp(10);
|
|
|
}
|
|
}
|
|
@@ -365,6 +345,8 @@ void World::update(float elapsedTime)
|
|
|
if (portal->enter(elapsedTime))
|
|
if (portal->enter(elapsedTime))
|
|
|
nextworld = true;
|
|
nextworld = true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ player->hit = false;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -385,3 +367,4 @@ bool World::isPlayerPositionValid()
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|