Selaa lähdekoodia

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

Remco 9 vuotta sitten
vanhempi
commit
912a2234a3
7 muutettua tiedostoa jossa 50 lisäystä ja 17 poistoa
  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)
 {
-	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;
 	}	
 }

+ 2 - 1
Crystal.h

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

+ 21 - 7
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();

+ 2 - 0
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;
 };
 

+ 4 - 3
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;
 		}
 	}
 

+ 1 - 1
World.h

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

+ 6 - 1
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",