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"
|
||||
|
||||
|
||||
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->rotation = rotation;
|
||||
this->scale = scale;
|
||||
this->canCollide = true;
|
||||
filled = true;
|
||||
isFilled = true;
|
||||
}
|
||||
|
||||
|
||||
Crystal::~Crystal()
|
||||
{
|
||||
if (model)
|
||||
@@ -20,7 +22,12 @@ Crystal::~Crystal()
|
||||
}
|
||||
|
||||
void Crystal::draw()
|
||||
{
|
||||
Entity::draw();
|
||||
}
|
||||
|
||||
void Crystal::pickUp()
|
||||
{
|
||||
if (filled)
|
||||
Entity::draw();
|
||||
isFilled = false;
|
||||
model = Model::load(empty);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@ class Crystal :
|
||||
public Entity
|
||||
{
|
||||
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();
|
||||
|
||||
bool filled;
|
||||
bool isFilled;
|
||||
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));
|
||||
}
|
||||
|
||||
for (auto e : v["crystals"])
|
||||
if (!v["crystal"].isNull())
|
||||
{
|
||||
//Rotation
|
||||
Vec3f rotation(0, 0, 0);
|
||||
if (!e["rot"].isNull())
|
||||
rotation = Vec3f(e["rot"][0].asFloat(), e["rot"][1].asFloat(), e["rot"][2].asFloat());
|
||||
std::string filled = "unknown";
|
||||
std::string empty = "unknown";
|
||||
|
||||
//Scale
|
||||
float scale = 1.0f;
|
||||
if (!e["scale"].isNull())
|
||||
scale = e["scale"].asFloat();
|
||||
if(!v["crystal"]["full texture"].isNull())
|
||||
filled = v["crystal"]["full texture"].asString();
|
||||
|
||||
//Position
|
||||
if (e["pos"].isNull())
|
||||
std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
|
||||
if(!v["crystal"]["empty texture"].isNull())
|
||||
empty = v["crystal"]["empty texture"].asString();
|
||||
|
||||
//File
|
||||
if (e["file"].isNull())
|
||||
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
||||
if (!v["crystal"]["instances"].isNull())
|
||||
{
|
||||
for (auto instance : v["crystal"]["instances"])
|
||||
{
|
||||
Vec3f position(0, 0, 0);
|
||||
Vec3f rotation(0, 0, 0);
|
||||
float scale = 1.0f;
|
||||
|
||||
//Create
|
||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
||||
if (!instance["pos"].isNull())
|
||||
{
|
||||
position.x = instance["pos"][0];
|
||||
position.y = instance["pos"][1];
|
||||
position.z = instance["pos"][2];
|
||||
}
|
||||
|
||||
if (!instance["rot"].isNull())
|
||||
{
|
||||
rotation.x = instance["rot"][0];
|
||||
rotation.y = instance["rot"][1];
|
||||
rotation.z = instance["rot"][2];
|
||||
}
|
||||
|
||||
crystals.push_back(new Crystal(e["file"].asString(), position, rotation, scale));
|
||||
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;
|
||||
//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()
|
||||
{
|
||||
for (auto e : entities)
|
||||
for (auto &e : entities)
|
||||
{
|
||||
if (e->canCollide && e->inObject(player->position))
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto & c : crystals)
|
||||
{
|
||||
if (c->canCollide && c->inObject(player->position))
|
||||
{
|
||||
if (c->isFilled)
|
||||
{
|
||||
c->pickUp();
|
||||
player->crystals++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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 ],
|
||||
"scale": 0.01
|
||||
}],
|
||||
"crystals": [
|
||||
{
|
||||
"file": "models/sphere/sphere.obj",
|
||||
"pos": [ 33, 2, 31 ]
|
||||
},
|
||||
{
|
||||
"file": "models/sphere/sphere.obj",
|
||||
"pos": [ 45, 2, 31 ]
|
||||
}
|
||||
]
|
||||
"crystal": {
|
||||
"full texture": "models/crystal/Crystal.obj",
|
||||
"empty texture": "models/crystal/PickedUpCrystal.obj",
|
||||
"instances": [
|
||||
{
|
||||
"pos": [ 31, 5, 33 ],
|
||||
"rot": [ 0, 0, 0 ]
|
||||
},
|
||||
{
|
||||
"pos": [ 40, 5, 40 ],
|
||||
"rot": [ 0, 0, 0 ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user