added new model for crystal, not possible to move through crystals
This commit is contained in:
+13
-6
@@ -2,17 +2,19 @@
|
|||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
|
|
||||||
Crystal::Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale)
|
Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale)
|
||||||
{
|
{
|
||||||
model = Model::load(fileName);
|
this->filled = filled;
|
||||||
|
this->empty = empty;
|
||||||
|
|
||||||
|
model = Model::load(this->filled);
|
||||||
this->position = position;
|
this->position = position;
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
this->scale = scale;
|
this->scale = scale;
|
||||||
this->canCollide = true;
|
this->canCollide = true;
|
||||||
filled = true;
|
isFilled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Crystal::~Crystal()
|
Crystal::~Crystal()
|
||||||
{
|
{
|
||||||
if (model)
|
if (model)
|
||||||
@@ -21,6 +23,11 @@ Crystal::~Crystal()
|
|||||||
|
|
||||||
void Crystal::draw()
|
void Crystal::draw()
|
||||||
{
|
{
|
||||||
if (filled)
|
Entity::draw();
|
||||||
Entity::draw();
|
}
|
||||||
|
|
||||||
|
void Crystal::pickUp()
|
||||||
|
{
|
||||||
|
isFilled = false;
|
||||||
|
model = Model::load(empty);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ class Crystal :
|
|||||||
public Entity
|
public Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale);
|
Crystal(const std::string &filled, const std::string &empty,
|
||||||
|
const Vec3f &position, Vec3f &rotation, const float &scale);
|
||||||
~Crystal();
|
~Crystal();
|
||||||
|
|
||||||
bool filled;
|
bool isFilled;
|
||||||
void draw();
|
void draw();
|
||||||
|
void pickUp();
|
||||||
|
private:
|
||||||
|
std::string filled, empty;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -118,31 +118,50 @@ World::World(const std::string &fileName)
|
|||||||
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto e : v["crystals"])
|
if (!v["crystal"].isNull())
|
||||||
{
|
{
|
||||||
//Rotation
|
std::string filled = "unknown";
|
||||||
Vec3f rotation(0, 0, 0);
|
std::string empty = "unknown";
|
||||||
if (!e["rot"].isNull())
|
|
||||||
rotation = Vec3f(e["rot"][0].asFloat(), e["rot"][1].asFloat(), e["rot"][2].asFloat());
|
|
||||||
|
|
||||||
//Scale
|
if(!v["crystal"]["full texture"].isNull())
|
||||||
float scale = 1.0f;
|
filled = v["crystal"]["full texture"].asString();
|
||||||
if (!e["scale"].isNull())
|
|
||||||
scale = e["scale"].asFloat();
|
|
||||||
|
|
||||||
//Position
|
if(!v["crystal"]["empty texture"].isNull())
|
||||||
if (e["pos"].isNull())
|
empty = v["crystal"]["empty texture"].asString();
|
||||||
std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
|
|
||||||
|
|
||||||
//File
|
if (!v["crystal"]["instances"].isNull())
|
||||||
if (e["file"].isNull())
|
{
|
||||||
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
for (auto instance : v["crystal"]["instances"])
|
||||||
|
{
|
||||||
|
Vec3f position(0, 0, 0);
|
||||||
|
Vec3f rotation(0, 0, 0);
|
||||||
|
float scale = 1.0f;
|
||||||
|
|
||||||
//Create
|
if (!instance["pos"].isNull())
|
||||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
{
|
||||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
position.x = instance["pos"][0];
|
||||||
|
position.y = instance["pos"][1];
|
||||||
|
position.z = instance["pos"][2];
|
||||||
|
}
|
||||||
|
|
||||||
crystals.push_back(new Crystal(e["file"].asString(), position, rotation, scale));
|
if (!instance["rot"].isNull())
|
||||||
|
{
|
||||||
|
rotation.x = instance["rot"][0];
|
||||||
|
rotation.y = instance["rot"][1];
|
||||||
|
rotation.z = instance["rot"][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!instance["scale"].isNull())
|
||||||
|
scale = instance["scale"].asFloat();
|
||||||
|
|
||||||
|
position.y = getHeight(position.x, position.z);
|
||||||
|
|
||||||
|
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
|
||||||
|
|
||||||
|
crystals.push_back(c);
|
||||||
|
//entities.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,20 +233,7 @@ void World::update(float elapsedTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
|
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
|
||||||
//tot hier
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto &crystal : crystals)
|
|
||||||
{
|
|
||||||
if (crystal->canCollide && crystal->inObject(player->position) && crystal->filled)
|
|
||||||
{
|
|
||||||
crystal->filled = false;
|
|
||||||
player->crystals++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,10 +244,23 @@ void World::addLevelObject(LevelObject* obj)
|
|||||||
|
|
||||||
bool World::isPlayerPositionValid()
|
bool World::isPlayerPositionValid()
|
||||||
{
|
{
|
||||||
for (auto e : entities)
|
for (auto &e : entities)
|
||||||
{
|
{
|
||||||
if (e->canCollide && e->inObject(player->position))
|
if (e->canCollide && e->inObject(player->position))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto & c : crystals)
|
||||||
|
{
|
||||||
|
if (c->canCollide && c->inObject(player->position))
|
||||||
|
{
|
||||||
|
if (c->isFilled)
|
||||||
|
{
|
||||||
|
c->pickUp();
|
||||||
|
player->crystals++;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
newmtl SpringIsComing:Material_007
|
||||||
|
illum 4
|
||||||
|
Kd 0.75 0.80 0.80
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree01:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree01:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree02:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree02:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree03:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree03:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree04:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree04:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl initialShadingGroup
|
||||||
|
illum 4
|
||||||
|
Kd 0.34 0.34 0.34
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
newmtl lambert2SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.00 1.00 1.00
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
newmtl rock3:Material_016
|
||||||
|
illum 4
|
||||||
|
Kd 0.64 0.64 0.64
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,92 @@
|
|||||||
|
newmtl SpringIsComing:Material_007
|
||||||
|
illum 4
|
||||||
|
Kd 0.75 0.80 0.80
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree01:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree01:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree02:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree02:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree03:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree03:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree04:Material_001
|
||||||
|
illum 4
|
||||||
|
Kd 0.01 0.00 0.00
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl Tree04:Material_004
|
||||||
|
illum 4
|
||||||
|
Kd 0.60 0.20 0.30
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
|
newmtl initialShadingGroup
|
||||||
|
illum 4
|
||||||
|
Kd 0.34 0.34 0.34
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
newmtl lambert2SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.00 1.00 1.00
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
newmtl rock3:Material_016
|
||||||
|
illum 4
|
||||||
|
Kd 0.64 0.64 0.64
|
||||||
|
Ka 1.00 1.00 1.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 96.08
|
||||||
File diff suppressed because it is too large
Load Diff
+14
-10
@@ -19,14 +19,18 @@
|
|||||||
"pos": [ 20, 5, 10 ],
|
"pos": [ 20, 5, 10 ],
|
||||||
"scale": 0.01
|
"scale": 0.01
|
||||||
}],
|
}],
|
||||||
"crystals": [
|
"crystal": {
|
||||||
{
|
"full texture": "models/crystal/Crystal.obj",
|
||||||
"file": "models/sphere/sphere.obj",
|
"empty texture": "models/crystal/PickedUpCrystal.obj",
|
||||||
"pos": [ 33, 2, 31 ]
|
"instances": [
|
||||||
},
|
{
|
||||||
{
|
"pos": [ 31, 5, 33 ],
|
||||||
"file": "models/sphere/sphere.obj",
|
"rot": [ 0, 0, 0 ]
|
||||||
"pos": [ 45, 2, 31 ]
|
},
|
||||||
}
|
{
|
||||||
]
|
"pos": [ 40, 5, 40 ],
|
||||||
|
"rot": [ 0, 0, 0 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user