Explorar el Código

when collected all crystals it is possible to move to the next level, by stepping in the portal

Remco hace 10 años
padre
commit
0ca94aef4d
Se han modificado 9 ficheros con 134 adiciones y 34 borrados
  1. 2 0
      CrystalPoint.vcxproj
  2. 9 3
      CrystalPoint.vcxproj.filters
  3. 2 1
      Main.cpp
  4. 34 0
      Portal.cpp
  5. 19 0
      Portal.h
  6. 27 0
      World.cpp
  7. 2 0
      World.h
  8. 34 24
      worlds/ice.json
  9. 5 6
      worlds/small.json

+ 2 - 0
CrystalPoint.vcxproj

@@ -165,6 +165,7 @@
     <ClCompile Include="LevelObject.cpp" />
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Model.cpp" />
+    <ClCompile Include="Portal.cpp" />
     <ClCompile Include="Sound.cpp" />
     <ClCompile Include="SoundSystem.cpp" />
     <ClCompile Include="Player.cpp" />
@@ -186,6 +187,7 @@
     <ClInclude Include="LevelObject.h" />
     <ClInclude Include="Main.h" />
     <ClInclude Include="Model.h" />
+    <ClInclude Include="Portal.h" />
     <ClInclude Include="Sound.h" />
     <ClInclude Include="SoundSystem.h" />
     <ClInclude Include="Player.h" />

+ 9 - 3
CrystalPoint.vcxproj.filters

@@ -79,10 +79,13 @@
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="Sound.cpp">
-		<Filter>Source Files</Filter>
+      <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="Crystal.cpp">
-		<Filter>Source Files</Filter>
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Portal.cpp">
+      <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
@@ -138,7 +141,7 @@
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="Sound.h">
-	  <Filter>Header Files</Filter>
+      <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="Crystal.h">
       <Filter>Header Files</Filter>
@@ -146,6 +149,9 @@
     <ClInclude Include="Skybox.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Portal.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="worlds\worlds.json">

+ 2 - 1
Main.cpp

@@ -64,7 +64,8 @@ void configureOpenGL()
 	//Init window and glut display mode
 	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
 	glutInitWindowSize(800, 600);
-	glutCreateWindow("Crystal Point");
+	//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
+	glutCreateWindow("Crystal Point");	
 	glutFullScreen();
 
 	//Depth testing

+ 34 - 0
Portal.cpp

@@ -0,0 +1,34 @@
+#include "Portal.h"
+#include "Model.h"
+#include <iostream>
+#include "Player.h"
+#include "WorldHandler.h"
+
+Portal::Portal(const std::string &fileName,
+	const Vec3f &position,
+	Vec3f &rotation,
+	const float &scale)
+{
+	model = Model::load(fileName);
+	this->position = position;
+	this->rotation = rotation;
+	this->scale = scale;
+	this->canCollide = true;
+
+	mayEnter = false;
+	maxCrystals = 0;
+}
+
+
+Portal::~Portal()
+{
+}
+
+void Portal::collide()
+{		
+	if (maxCrystals == (Player::getInstance()->crystals) && !mayEnter)
+	{
+		canCollide = false;
+		mayEnter = true;
+	}
+}

+ 19 - 0
Portal.h

@@ -0,0 +1,19 @@
+#pragma once
+#include "Entity.h"
+#include <string>
+
+class Portal :
+	public Entity
+{
+public:
+	Portal(const std::string &fileName,
+		const Vec3f &position,
+		Vec3f &rotation,
+		const float &scale);
+	~Portal();
+
+	void collide();
+	int maxCrystals;
+	bool mayEnter;
+};
+

+ 27 - 0
World.cpp

@@ -181,6 +181,30 @@ World::World(const std::string &fileName):
 		music->Play();
 	}
 
+	if (!v["portal"].isNull())
+	{
+		Vec3f pos(0, 0, 0);
+		if (!v["portal"]["pos"].isNull())
+			pos = Vec3f(v["portal"]["pos"][0].asFloat(),
+				v["portal"]["pos"][1].asFloat(),
+				v["portal"]["pos"][0].asFloat());
+
+		pos.y = getHeight(pos.x, pos.z);
+
+		Vec3f rot(0, 0, 0);
+		if (!v["portal"]["rot"].isNull())
+			pos = Vec3f(v["portal"]["rot"][0].asFloat(),
+				v["portal"]["rot"][1].asFloat(),
+				v["portal"]["rot"][0].asFloat());
+
+		float scale = 1.0f;
+		if (!v["portal"]["scale"].isNull())
+			scale = !v["portal"]["scale"].asFloat();
+
+		portal = new Portal(v["portal"]["file"], pos, rot, scale);
+		entities.push_back(portal);
+		portal->maxCrystals = maxCrystals;
+	}
 }
 
 
@@ -256,6 +280,9 @@ void World::update(float elapsedTime)
 		}
 		enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
 	}
+
+	if (portal->mayEnter)
+		WorldHandler::getInstance()->NextWorld();
 }
 
 void World::addLevelObject(LevelObject* obj)

+ 2 - 0
World.h

@@ -8,6 +8,7 @@
 #include "Interface.h"
 #include "Crystal.h"
 #include "Skybox.h"
+#include "Portal.h"
 
 class Entity;
 
@@ -20,6 +21,7 @@ private:
 	HeightMap* heightmap;
 	Interface* interface;
 	Skybox* skybox;
+	Portal* portal;
 	
 	int music_id,maxCrystals;
 

+ 34 - 24
worlds/ice.json

@@ -1,33 +1,43 @@
 {
-   "world": {
+  "world": {
     "heightmap": "worlds/hmcs.png",
-    "texture": "worlds/hmcstexture.png",
+    "texture":  "hmcstexture.png",
+    "skybox": "skyboxes/peaceful/",
     "object-templates": [
-		{
-			"color":100,
-			"file": "models/boom/Boom.obj",
-			"collision": false
-		}
-	]
-   },
+      {
+        "color": 100,
+        "file": "models/boom/Boom.obj",
+        "collision": true
+      }
+    ],
+	"music": "WAVE/bond.wav"
+  },
   "player": {
-    "startposition": [ 0, 1.7, 0]
+    "startposition": [ 1, 5, 20 ]
+  },
+  "objects": [ ],
+  "portal": {     
+    "file": "models/Teleporter/Teleporter.obj",
+    "pos": [ 10, 5, 10 ]    
   },
-  "objects": [
-    {
-      "file": "models/boom/Boom.obj",
-      "pos": [ 10, 0, -4 ]
-    },
-    {
-      "file": "models/Teleporter/Teleporter.obj",
-      "pos": [ 0, 0, -4 ]
-    }
-  ],
   "enemies": [
-    {
+  {
       "file": "models/squid/Blooper.obj",
-      "pos": [ 10, 2, -10 ],
+      "pos": [ 20, 5, 10 ],
       "scale": 0.01
-    }
-  ]
+  }],
+  "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 ]
+      }
+    ]
+  }
 }

+ 5 - 6
worlds/small.json

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