diff --git a/Crystal.cpp b/Crystal.cpp index b973485..6ced677 100644 --- a/Crystal.cpp +++ b/Crystal.cpp @@ -5,10 +5,11 @@ Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale) { - this->filled = filled; - this->empty = empty; + this->filled = Model::load(filled); + this->empty = Model::load(empty); + model = this->filled; + - model = Model::load(this->filled); this->position = position; this->rotation = rotation; this->scale = scale; @@ -20,6 +21,15 @@ Crystal::~Crystal() { if (model) Model::unload(model); + + //if isfilled, means model is model filled, so model empty has to been deleted. + //if is not filled, means model is model empty, so model filled has to been deleted. + if (isFilled) + if(empty) + Model::unload(empty); + else + if(filled) + Model::unload(filled); } void Crystal::draw() @@ -33,6 +43,6 @@ void Crystal::collide() { Player::getInstance()->crystals++; isFilled = false; - model = Model::load(empty); + model = empty; } } diff --git a/Crystal.h b/Crystal.h index 6b8ab1a..1f9a54f 100644 --- a/Crystal.h +++ b/Crystal.h @@ -14,6 +14,7 @@ public: void draw(); void collide(); private: - std::string filled, empty; + Model* filled; + Model* empty; }; diff --git a/Interface.cpp b/Interface.cpp index c97602a..c5ee6ba 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -14,6 +14,15 @@ Interface::Interface() crystalWidth = 20; crystalHeight = 50; crystalOffset = 5; + maxCrystals = 0; +} + +Interface::Interface(int maxCrystal) +{ + crystalWidth = 20; + crystalHeight = 50; + crystalOffset = 5; + maxCrystals = maxCrystal; } @@ -80,18 +89,23 @@ void Interface::draw() glColor4f(1.0f, 1.0f, 0.1f, 1.0); glutBitmapString("Level: " + std::to_string(player->level), 490, 900); - int cw, ch, offset; - cw = 20; - ch = 50; - offset = 5; - for (int i = 0; i < player->crystals; i++) + for (int i = 0; i < maxCrystals; i++) { glBegin(GL_QUADS); - glColor4f(0, 1.0f, 1.0f, 1.0f); + + if(i < player->crystals) + glColor4f(0, 1.0f, 1.0f, 1.0f); + else + glColor4f(0, 0.4f, 0.4f, 1.0f); + glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i); glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i); - glColor4f(0, 0.8f, 0.8f, 1.0f); + if (i < player->crystals) + glColor4f(0, 0.7f, 0.7f, 1.0f); + else + glColor4f(0, 0.2f, 0.2f, 1.0f); + glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i); glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i); glEnd(); diff --git a/Interface.h b/Interface.h index 434a1b3..9f9e33d 100644 --- a/Interface.h +++ b/Interface.h @@ -3,11 +3,13 @@ class Interface { public: Interface(); + Interface(int); ~Interface(); void draw(void); void update(float deltaTime); int crystalWidth, crystalHeight, crystalOffset; + int maxCrystals; }; diff --git a/World.cpp b/World.cpp index c3d0911..3db2f3d 100644 --- a/World.cpp +++ b/World.cpp @@ -94,7 +94,7 @@ World::World(const std::string &fileName): //Create Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat()); - position.y = getHeight(position.x, position.z) + 2.0f; + position.y = getHeight(position.x, position.z); entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision)); } @@ -126,7 +126,7 @@ World::World(const std::string &fileName): enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale)); } - + maxCrystals = 0; if (!v["crystal"].isNull()) { std::string filled = "unknown"; @@ -164,11 +164,12 @@ World::World(const std::string &fileName): scale = instance["scale"].asFloat(); position.y = getHeight(position.x, position.z); - + maxCrystals++; Crystal *c = new Crystal(filled, empty, position, rotation, scale); entities.push_back(c); } + interface->maxCrystals = maxCrystals; } } diff --git a/World.h b/World.h index 9ffb908..17d362a 100644 --- a/World.h +++ b/World.h @@ -21,7 +21,7 @@ private: Interface* interface; Skybox* skybox; - int music_id; + int music_id,maxCrystals; std::vector entities; std::vector enemies; diff --git a/worlds/small.json b/worlds/small.json index 422b331..826848b 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -14,7 +14,12 @@ "player": { "startposition": [ 20, 5, 20 ] }, - "objects": [ ], + "objects": [ + { + "file": "models/Teleporter/Teleporter.obj", + "pos": [ 10, 5, 10 ] + } + ], "enemies": [ { "file": "models/squid/Blooper.obj",