فهرست منبع

crystals will be displayed, when not get with darker icons, when picked up crystals get colors

Remco 10 سال پیش
والد
کامیت
912a2234a3
7فایلهای تغییر یافته به همراه50 افزوده شده و 17 حذف شده
  1. 14 4
      Crystal.cpp
  2. 2 1
      Crystal.h
  3. 21 7
      Interface.cpp
  4. 2 0
      Interface.h
  5. 4 3
      World.cpp
  6. 1 1
      World.h
  7. 6 1
      worlds/small.json

+ 14 - 4
Crystal.cpp

@@ -5,10 +5,11 @@
 
 
 Crystal::Crystal(const std::string & filled, const std::string & empty, 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)
 {
 {
-	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->position = position;
 	this->rotation = rotation;
 	this->rotation = rotation;
 	this->scale = scale;
 	this->scale = scale;
@@ -20,6 +21,15 @@ Crystal::~Crystal()
 {
 {
 	if (model)
 	if (model)
 		Model::unload(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()
 void Crystal::draw()
@@ -33,6 +43,6 @@ void Crystal::collide()
 	{
 	{
 		Player::getInstance()->crystals++;
 		Player::getInstance()->crystals++;
 		isFilled = false;
 		isFilled = false;
-		model = Model::load(empty);
+		model = empty;
 	}	
 	}	
 }
 }

+ 2 - 1
Crystal.h

@@ -14,6 +14,7 @@ public:
 	void draw();
 	void draw();
 	void collide();
 	void collide();
 private:
 private:
-	std::string filled, empty;
+	Model* filled;
+	Model* empty;
 };
 };
 
 

+ 21 - 7
Interface.cpp

@@ -14,6 +14,15 @@ Interface::Interface()
 	crystalWidth = 20;
 	crystalWidth = 20;
 	crystalHeight = 50;
 	crystalHeight = 50;
 	crystalOffset = 5;
 	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);
 	glColor4f(1.0f, 1.0f, 0.1f, 1.0);
 	glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
 	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);
 		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 / 2	, crystalOffset*i + crystalHeight*i);
 		glVertex2f(975 - crystalWidth		, crystalHeight / 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 - crystalWidth / 2	, crystalHeight + crystalOffset*i + crystalHeight*i);
 		glVertex2f(975						, crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
 		glVertex2f(975						, crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
 		glEnd();
 		glEnd();

+ 2 - 0
Interface.h

@@ -3,11 +3,13 @@ class Interface
 {
 {
 public:
 public:
 	Interface();
 	Interface();
+	Interface(int);
 	~Interface();
 	~Interface();
 
 
 	void draw(void);
 	void draw(void);
 	void update(float deltaTime);
 	void update(float deltaTime);
 
 
 	int crystalWidth, crystalHeight, crystalOffset;
 	int crystalWidth, crystalHeight, crystalOffset;
+	int maxCrystals;
 };
 };
 
 

+ 4 - 3
World.cpp

@@ -94,7 +94,7 @@ World::World(const std::string &fileName):
 
 
 		//Create
 		//Create
 		Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());		
 		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));
 		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));
 		enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
 	}
 	}
-
+	maxCrystals = 0;
 	if (!v["crystal"].isNull())
 	if (!v["crystal"].isNull())
 	{
 	{
 		std::string filled = "unknown";
 		std::string filled = "unknown";
@@ -164,11 +164,12 @@ World::World(const std::string &fileName):
 					scale = instance["scale"].asFloat();
 					scale = instance["scale"].asFloat();
 
 
 				position.y = getHeight(position.x, position.z);
 				position.y = getHeight(position.x, position.z);
-
+				maxCrystals++;
 				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;
 		}
 		}
 	}
 	}
 
 

+ 1 - 1
World.h

@@ -21,7 +21,7 @@ private:
 	Interface* interface;
 	Interface* interface;
 	Skybox* skybox;
 	Skybox* skybox;
 	
 	
-	int music_id;
+	int music_id,maxCrystals;
 
 
 	std::vector<Entity*> entities;
 	std::vector<Entity*> entities;
 	std::vector<Enemy*> enemies;
 	std::vector<Enemy*> enemies;

+ 6 - 1
worlds/small.json

@@ -14,7 +14,12 @@
   "player": {
   "player": {
     "startposition": [ 20, 5, 20 ]
     "startposition": [ 20, 5, 20 ]
   },
   },
-  "objects": [ ],
+  "objects": [
+    {
+      "file": "models/Teleporter/Teleporter.obj",
+      "pos": [ 10, 5, 10 ]
+    }
+  ],
   "enemies": [
   "enemies": [
   {
   {
       "file": "models/squid/Blooper.obj",
       "file": "models/squid/Blooper.obj",