Преглед изворни кода

Merge remote-tracking branch 'refs/remotes/origin/developer' into feature/OpenAL

# Conflicts:
#	CrystalPoint.vcxproj.filters
#	Enemy.h
Aaldert пре 9 година
родитељ
комит
0f8fd67dd3
40 измењених фајлова са 1009 додато и 355 уклоњено
  1. 28 0
      Crystal.sln
  2. 0 104
      CrystalJohan.cpp
  3. 0 28
      CrystalJohan.sln
  4. 101 0
      CrystalPoint.cpp
  5. 6 5
      CrystalPoint.h
  6. 14 8
      CrystalPoint.vcxproj
  7. 58 32
      CrystalPoint.vcxproj.filters
  8. 58 0
      Cursor.cpp
  9. 24 0
      Cursor.h
  10. 18 3
      Enemy.cpp
  11. 4 3
      Enemy.h
  12. 4 2
      Entity.cpp
  13. 68 13
      HeightMap.cpp
  14. 4 3
      HeightMap.h
  15. 94 0
      Interface.cpp
  16. 11 0
      Interface.h
  17. 2 0
      LevelObject.cpp
  18. 19 11
      Main.cpp
  19. 14 12
      Model.cpp
  20. 28 2
      Player.cpp
  21. 10 4
      Player.h
  22. 7 7
      ReadMe.txt
  23. 0 13
      Singleton.h
  24. 14 0
      Vector.cpp
  25. 4 0
      Vector.h
  26. 20 0
      Vertex.cpp
  27. 5 0
      Vertex.h
  28. 113 65
      World.cpp
  29. 13 7
      World.h
  30. 137 0
      WorldHandler.cpp
  31. 36 0
      WorldHandler.h
  32. 38 0
      worlds/fire.json
  33. 0 0
      worlds/hell.pdn
  34. BIN
      worlds/hell.png
  35. BIN
      worlds/hmcs.png
  36. 33 0
      worlds/ice.json
  37. 17 0
      worlds/small.json
  38. BIN
      worlds/small.png
  39. 0 33
      worlds/world1.json
  40. 7 0
      worlds/worlds.json

+ 28 - 0
Crystal.sln

@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.24720.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CrystalPoint", "CrystalPoint.vcxproj", "{F82158C7-7345-4CB0-9F90-3AB49A071904}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Debug|x64.ActiveCfg = Debug|x64
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Debug|x64.Build.0 = Debug|x64
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Debug|x86.ActiveCfg = Debug|Win32
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Debug|x86.Build.0 = Debug|Win32
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Release|x64.ActiveCfg = Release|x64
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Release|x64.Build.0 = Release|x64
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Release|x86.ActiveCfg = Release|Win32
+		{F82158C7-7345-4CB0-9F90-3AB49A071904}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 0 - 104
CrystalJohan.cpp

@@ -1,104 +0,0 @@
-
-#include "CrystalJohan.h"
-#include <GL/freeglut.h>
-#include <cmath>
-#include <cstring>
-#include "World.h"
-
-void CrystalJohan::init()
-{
-	world = new World();
-	lastFrameTime = 0;
-
-	glClearColor(0.7, 0.7, 1.0, 1.0);
-	glEnable(GL_DEPTH_TEST);
-	glEnable(GL_LIGHTING);
-	glEnable(GL_LIGHT0);
-
-	mousePosition = Vec2f(width / 2, height / 2);
-}
-
-
-void CrystalJohan::draw()
-{
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	//Draw world
-	glEnable(GL_LIGHTING);
-	glEnable(GL_DEPTH_TEST);
-
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	gluPerspective(70, width / (float)height, 0.1f, 15000);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	world->draw();
-	
-	//Draw Cursor
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(0,width, height,0,-10,10);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	/*glDisable(GL_LIGHTING);
-	glDisable(GL_DEPTH_TEST);
-	glColor4f(1, cos(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), sin(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), 1);
-	glBegin(GL_TRIANGLES);
-	glVertex2f(mousePosition.x, mousePosition.y);
-	glVertex2f(mousePosition.x+15, mousePosition.y+15);
-	glVertex2f(mousePosition.x+5, mousePosition.y+20);
-
-	glEnd();*/
-
-	glutSwapBuffers();
-}
-
-
-void CrystalJohan::update()
-{
-	float frameTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
-	float deltaTime = frameTime - lastFrameTime;
-	lastFrameTime = frameTime;
-
-	//	if(keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
-	if (keyboardState.keys[27])
-		exit(0);
-
-
-	world->player.rotation.y += mouseOffset.x / 10.0f;
-	world->player.rotation.x += mouseOffset.y / 10.0f;
-	if (world->player.rotation.x > 90)
-		world->player.rotation.x = 90;
-	if (world->player.rotation.x < -90)
-		world->player.rotation.x = -90;
-
-	float speed = 20;
-
-	Vec3f oldPosition = world->player.position;
-	if (keyboardState.keys['a']) world->player.setPosition(0, deltaTime*speed, false);
-	if (keyboardState.keys['d']) world->player.setPosition(180, deltaTime*speed, false);
-	if (keyboardState.keys['w']) world->player.setPosition(90, deltaTime*speed, false);
-	if (keyboardState.keys['s']) world->player.setPosition(270, deltaTime*speed, false);
-	if (keyboardState.keys['q']) world->player.setPosition(1, deltaTime*speed, true);
-	if (keyboardState.keys['e']) world->player.setPosition(-1, deltaTime*speed, true);
-	if (!world->isPlayerPositionValid())
-		world->player.position = oldPosition;
-
-	world->update(deltaTime);
-
-	mousePosition = mousePosition + mouseOffset;
-
-	mouseOffset = Vec2f(0, 0);
-	prevKeyboardState = keyboardState;
-	glutPostRedisplay();
-}
-
-
-
-KeyboardState::KeyboardState()
-{
-	memset(keys, 0, sizeof(keys));
-	memset(special, 0, sizeof(special));
-}

+ 0 - 28
CrystalJohan.sln

@@ -1,28 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.24720.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CrystalJohan", "CrystalJohan.vcxproj", "{98776A7C-CD7A-4C62-946A-2263C27E9690}"
-EndProject
-Global
-	GlobalSection(SolutionConfigurationPlatforms) = preSolution
-		Debug|x64 = Debug|x64
-		Debug|x86 = Debug|x86
-		Release|x64 = Release|x64
-		Release|x86 = Release|x86
-	EndGlobalSection
-	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Debug|x64.ActiveCfg = Debug|x64
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Debug|x64.Build.0 = Debug|x64
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Debug|x86.ActiveCfg = Debug|Win32
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Debug|x86.Build.0 = Debug|Win32
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Release|x64.ActiveCfg = Release|x64
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Release|x64.Build.0 = Release|x64
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Release|x86.ActiveCfg = Release|Win32
-		{98776A7C-CD7A-4C62-946A-2263C27E9690}.Release|x86.Build.0 = Release|Win32
-	EndGlobalSection
-	GlobalSection(SolutionProperties) = preSolution
-		HideSolutionNode = FALSE
-	EndGlobalSection
-EndGlobal

+ 101 - 0
CrystalPoint.cpp

@@ -0,0 +1,101 @@
+
+#include "CrystalPoint.h"
+#include <GL/freeglut.h>
+#include <cmath>
+#include <cstring>
+#include "WorldHandler.h"
+#include "Player.h"
+
+int CrystalPoint::width = 0;
+int CrystalPoint::height = 0;
+
+void CrystalPoint::init()
+{
+	player = Player::getInstance();
+	worldhandler = WorldHandler::getInstance();
+	//cursor = Cursor::getInstance();
+
+	lastFrameTime = 0;
+
+	glClearColor(0.7f, 0.7f, 1.0f, 1.0f);
+
+	mousePosition = Vec2f(width / 2, height / 2);
+}
+
+
+void CrystalPoint::draw()
+{
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	//Draw world
+	glEnable(GL_LIGHTING);
+	glEnable(GL_DEPTH_TEST);
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	gluPerspective(70, width / (float)height, 0.1f, 15000);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	worldhandler->draw();
+
+	//cursor->draw();
+
+	glutSwapBuffers();
+}
+
+
+void CrystalPoint::update()
+{
+	float frameTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float deltaTime = frameTime - lastFrameTime;
+	lastFrameTime = frameTime;
+
+	if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
+		worldhandler->PreviousWorld();
+	if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
+		worldhandler->NextWorld();
+	if (keyboardState.keys[27])
+		exit(0);
+
+	Player* player = Player::getInstance();
+
+	player->rotation.y += mouseOffset.x / 10.0f;
+	player->rotation.x += mouseOffset.y / 10.0f;
+	if (player->rotation.x > 90)
+		player->rotation.x = 90;
+	if (player->rotation.x < -90)
+		player->rotation.x = -90;
+
+	float speed = 10;
+
+	Vec3f oldPosition = player->position;
+	if (keyboardState.keys['a']) player->setPosition(0, deltaTime*speed, false);
+	if (keyboardState.keys['d']) player->setPosition(180, deltaTime*speed, false);
+	if (keyboardState.keys['w']) player->setPosition(90, deltaTime*speed, false);
+	if (keyboardState.keys['s']) player->setPosition(270, deltaTime*speed, false);
+	if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
+	if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
+
+	if (!worldhandler->isPlayerPositionValid())
+		player->position = oldPosition;
+
+	player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
+
+	worldhandler->update(deltaTime);
+
+	mousePosition = mousePosition + mouseOffset;
+	//cursor->update(mousePosition);
+
+	mouseOffset = Vec2f(0, 0);
+	prevKeyboardState = keyboardState;
+	glutPostRedisplay();
+}
+
+
+
+KeyboardState::KeyboardState()
+{
+	memset(keys, 0, sizeof(keys));
+	memset(special, 0, sizeof(special));
+}

+ 6 - 5
CrystalJohan.h → CrystalPoint.h

@@ -1,6 +1,7 @@
 #pragma once
 #pragma once
 
 
-class World;
+class WorldHandler;
+class Player;
 #include "Vector.h"
 #include "Vector.h"
 
 
 class KeyboardState
 class KeyboardState
@@ -13,21 +14,21 @@ public:
 	KeyboardState();
 	KeyboardState();
 };
 };
 
 
-class CrystalJohan
+class CrystalPoint
 {
 {
 public:
 public:
 	void init();
 	void init();
 	void draw();
 	void draw();
 	void update();
 	void update();
 
 
-	World* world;
+	WorldHandler* worldhandler;
+	Player* player;
 
 
-	int width, height;
+	static int width, height;
 	KeyboardState keyboardState;
 	KeyboardState keyboardState;
 	KeyboardState prevKeyboardState;
 	KeyboardState prevKeyboardState;
 
 
 	Vec2f mouseOffset;
 	Vec2f mouseOffset;
-
 	Vec2f mousePosition;
 	Vec2f mousePosition;
 
 
 	float lastFrameTime;
 	float lastFrameTime;

+ 14 - 8
CrystalJohan.vcxproj → CrystalPoint.vcxproj

@@ -19,10 +19,11 @@
     </ProjectConfiguration>
     </ProjectConfiguration>
   </ItemGroup>
   </ItemGroup>
   <PropertyGroup Label="Globals">
   <PropertyGroup Label="Globals">
-    <ProjectGuid>{98776A7C-CD7A-4C62-946A-2263C27E9690}</ProjectGuid>
+    <ProjectGuid>{F82158C7-7345-4CB0-9F90-3AB49A071904}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>CrystalJohan</RootNamespace>
     <RootNamespace>CrystalJohan</RootNamespace>
     <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
     <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <ProjectName>CrystalPoint</ProjectName>
   </PropertyGroup>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -152,13 +153,12 @@
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
-    <Text Include="ReadMe.txt" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="CrystalJohan.cpp" />
+    <ClCompile Include="CrystalPoint.cpp" />
+    <ClCompile Include="Cursor.cpp" />
     <ClCompile Include="Enemy.cpp" />
     <ClCompile Include="Enemy.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="HeightMap.cpp" />
     <ClCompile Include="HeightMap.cpp" />
+    <ClCompile Include="Interface.cpp" />
     <ClCompile Include="json.cpp" />
     <ClCompile Include="json.cpp" />
     <ClCompile Include="LevelObject.cpp" />
     <ClCompile Include="LevelObject.cpp" />
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Main.cpp" />
@@ -168,26 +168,32 @@
     <ClCompile Include="Vector.cpp" />
     <ClCompile Include="Vector.cpp" />
     <ClCompile Include="Vertex.cpp" />
     <ClCompile Include="Vertex.cpp" />
     <ClCompile Include="World.cpp" />
     <ClCompile Include="World.cpp" />
+    <ClCompile Include="WorldHandler.cpp" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <ClInclude Include="CrystalJohan.h" />
+    <ClInclude Include="CrystalPoint.h" />
+    <ClInclude Include="Cursor.h" />
     <ClInclude Include="Enemy.h" />
     <ClInclude Include="Enemy.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="HeightMap.h" />
     <ClInclude Include="HeightMap.h" />
+    <ClInclude Include="Interface.h" />
     <ClInclude Include="json.h" />
     <ClInclude Include="json.h" />
     <ClInclude Include="LevelObject.h" />
     <ClInclude Include="LevelObject.h" />
     <ClInclude Include="Main.h" />
     <ClInclude Include="Main.h" />
     <ClInclude Include="Model.h" />
     <ClInclude Include="Model.h" />
     <ClInclude Include="OpenAL.h" />
     <ClInclude Include="OpenAL.h" />
     <ClInclude Include="Player.h" />
     <ClInclude Include="Player.h" />
-    <ClInclude Include="Singleton.h" />
     <ClInclude Include="stb_image.h" />
     <ClInclude Include="stb_image.h" />
     <ClInclude Include="vector.h" />
     <ClInclude Include="vector.h" />
     <ClInclude Include="Vertex.h" />
     <ClInclude Include="Vertex.h" />
     <ClInclude Include="World.h" />
     <ClInclude Include="World.h" />
+    <ClInclude Include="WorldHandler.h" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <None Include="worlds\world1.json" />
+    <None Include="worlds\fire.json" />
+    <None Include="worlds\ice.json" />
+    <None Include="worlds\small.json" />
+    <None Include="worlds\worlds.json" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Media Include="WAVE\Sound.wav" />
     <Media Include="WAVE\Sound.wav" />

+ 58 - 32
CrystalJohan.vcxproj.filters → CrystalPoint.vcxproj.filters

@@ -13,55 +13,64 @@
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
     </Filter>
     </Filter>
+    <Filter Include="Source Files\Object">
+      <UniqueIdentifier>{1e464995-b141-43fd-9e25-16d6ac47176b}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Source Files\World">
+      <UniqueIdentifier>{0de1a037-e536-40df-a0d0-0d929f2fe752}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Source Files\json">
+      <UniqueIdentifier>{9c655946-3f99-44ea-bc97-2817656954e0}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <Text Include="ReadMe.txt" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="CrystalJohan.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Main.cpp">
     <ClCompile Include="Main.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="World.cpp">
+    <ClCompile Include="Player.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Entity.cpp">
+    <ClCompile Include="json.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Enemy.cpp">
+    <ClCompile Include="WorldHandler.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="LevelObject.cpp">
-      <Filter>Source Files</Filter>
+    <ClCompile Include="Entity.cpp">
+      <Filter>Source Files\Object</Filter>
     </ClCompile>
     </ClCompile>
     <ClCompile Include="Model.cpp">
     <ClCompile Include="Model.cpp">
-      <Filter>Source Files</Filter>
+      <Filter>Source Files\Object</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Vector.cpp">
-      <Filter>Source Files</Filter>
+    <ClCompile Include="Vertex.cpp">
+      <Filter>Source Files\Object</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Player.cpp">
-      <Filter>Source Files</Filter>
+    <ClCompile Include="Vector.cpp">
+      <Filter>Source Files\Object</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="json.cpp">
-      <Filter>Source Files</Filter>
+    <ClCompile Include="World.cpp">
+      <Filter>Source Files\World</Filter>
     </ClCompile>
     </ClCompile>
     <ClCompile Include="HeightMap.cpp">
     <ClCompile Include="HeightMap.cpp">
-      <Filter>Source Files</Filter>
+      <Filter>Source Files\World</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Vertex.cpp">
+    <ClCompile Include="LevelObject.cpp">
+      <Filter>Source Files\World</Filter>
+    </ClCompile>
+    <ClCompile Include="Enemy.cpp">
+      <Filter>Source Files\Object</Filter>
+    </ClCompile>
+    <ClCompile Include="CrystalPoint.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="OpenAL.cpp">
+    <ClCompile Include="Cursor.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Interface.cpp">
+      <Filter>Source Files\World</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <ClInclude Include="CrystalJohan.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="World.h">
     <ClInclude Include="World.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -74,9 +83,6 @@
     <ClInclude Include="LevelObject.h">
     <ClInclude Include="LevelObject.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="vector.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Model.h">
     <ClInclude Include="Model.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -86,9 +92,6 @@
     <ClInclude Include="Player.h">
     <ClInclude Include="Player.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Singleton.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Main.h">
     <ClInclude Include="Main.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -101,12 +104,35 @@
     <ClInclude Include="Vertex.h">
     <ClInclude Include="Vertex.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="OpenAL.h">
+    <ClInclude Include="WorldHandler.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="CrystalPoint.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Interface.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Cursor.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="vector.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <None Include="worlds\world1.json" />
+    <None Include="worlds\worlds.json">
+      <Filter>Source Files\json</Filter>
+    </None>
+    <None Include="worlds\fire.json">
+      <Filter>Source Files\json</Filter>
+    </None>
+    <None Include="worlds\ice.json">
+      <Filter>Source Files\json</Filter>
+    </None>
+    <None Include="worlds\small.json">
+      <Filter>Source Files\json</Filter>
+    </None>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Media Include="WAVE\Sound.wav">
     <Media Include="WAVE\Sound.wav">

+ 58 - 0
Cursor.cpp

@@ -0,0 +1,58 @@
+#include "Cursor.h"
+#include <GL\freeglut.h>
+#include <cmath>
+#include "CrystalPoint.h"
+
+Cursor* Cursor::instance = NULL;
+
+Cursor::Cursor()
+{
+	enabled = false;
+}
+
+Cursor::~Cursor()
+{
+}
+
+Cursor* Cursor::getInstance(void)
+{
+	if (instance == nullptr)
+		instance = new Cursor();
+	
+	return instance;
+}
+
+void Cursor::enable(bool enable)
+{
+	enabled = enable;
+}
+
+bool Cursor::isEnabled(void)
+{
+	return enabled;
+}
+
+void Cursor::draw(void)
+{
+	//Draw Cursor
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	glDisable(GL_LIGHTING);
+	glDisable(GL_DEPTH_TEST);
+	glColor4f(1, cos(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), sin(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), 1);
+
+	glBegin(GL_TRIANGLES);
+	glVertex2f(mousePosition.x, mousePosition.y);
+	glVertex2f(mousePosition.x + 15, mousePosition.y + 15);
+	glVertex2f(mousePosition.x + 5, mousePosition.y + 20);
+	glEnd();
+}
+
+void Cursor::update(Vec2f newPosition)
+{
+	mousePosition = newPosition;
+}

+ 24 - 0
Cursor.h

@@ -0,0 +1,24 @@
+#pragma once
+#include "Vector.h"
+
+class Cursor
+{
+private:
+	Cursor();
+
+	static Cursor* instance;
+	bool enabled;
+	Vec2f mousePosition;
+public:
+	
+	~Cursor();
+
+	static Cursor* getInstance(void);
+	
+	void enable(bool enable);
+	bool isEnabled(void);
+
+	void draw(void);
+	void update(Vec2f newPosition);
+};
+

+ 18 - 3
Enemy.cpp

@@ -8,14 +8,13 @@
 Enemy::Enemy(const std::string &fileName,
 Enemy::Enemy(const std::string &fileName,
 	const Vec3f &position,
 	const Vec3f &position,
 	Vec3f &rotation,
 	Vec3f &rotation,
-	const float &scale,
-	const bool &hasCollision)
+	const float &scale)
 {
 {
 	model = Model::load(fileName);
 	model = Model::load(fileName);
 	this->position = position;
 	this->position = position;
 	this->rotation = rotation;
 	this->rotation = rotation;
 	this->scale = scale;
 	this->scale = scale;
-	this->canCollide = hasCollision;
+	this->canCollide = true;
 	target = position;
 	target = position;
 	speed = 1;
 	speed = 1;
 	radius = 10;
 	radius = 10;
@@ -49,6 +48,22 @@ void Enemy::draw()
 	glPopMatrix();
 	glPopMatrix();
 }
 }
 
 
+void Enemy::inEyeSight(Vec3f & TargetPosition)
+{
+	if (position.Distance(TargetPosition) <= radius)
+	{
+		hasTarget = true;
+		target = TargetPosition;
+	}
+	else
+		hasTarget = false;
+}
+
+bool Enemy::hasCollison(Vec3f &)
+{
+	
+}
+
 void Enemy::update(float delta)
 void Enemy::update(float delta)
 {
 {
 	if (!openal->isMusicPlaying()) {
 	if (!openal->isMusicPlaying()) {

+ 4 - 3
Enemy.h

@@ -8,7 +8,7 @@
 class Enemy : public Entity
 class Enemy : public Entity
 {
 {
 public:
 public:
-	Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale,const bool &hasCollision);
+	Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale);
 	~Enemy();
 	~Enemy();
 
 
 	bool hasTarget;
 	bool hasTarget;
@@ -17,7 +17,8 @@ public:
 
 
 	void update(float);
 	void update(float);
 	void draw();
 	void draw();
-private:
-	OpenAL *openal;
+
+	void inEyeSight(Vec3f &);
+	bool hasCollison(Vec3f &);
 };
 };
 
 

+ 4 - 2
Entity.cpp

@@ -14,6 +14,8 @@ Entity::Entity()
 
 
 Entity::~Entity()
 Entity::~Entity()
 {
 {
+	if(model)
+		Model::unload(model);
 }
 }
 
 
 
 
@@ -46,8 +48,8 @@ bool Entity::inObject(const Vec3f & point)
 	if (!model)
 	if (!model)
 		return false;
 		return false;
 	Vec3f center = position + model->center;
 	Vec3f center = position + model->center;
-	float distance = sqrt((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
-	if (distance < model->radius*scale)
+	float distance = ((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
+	if (distance < model->radius*scale*model->radius*scale)
 		return true;
 		return true;
 	return false;
 	return false;
 }
 }

+ 68 - 13
HeightMap.cpp

@@ -1,29 +1,56 @@
 #include "HeightMap.h"
 #include "HeightMap.h"
 #include "stb_image.h"
 #include "stb_image.h"
+#include "vector.h"
+
+#include "LevelObject.h"
 
 
 #include <GL/freeglut.h>
 #include <GL/freeglut.h>
 #include <iostream>
 #include <iostream>
 #include <string>
 #include <string>
+#include "World.h"
 
 
+#define RED 0
+#define GREEN 1
+#define BLUE 2
+#define ALPHA 3
 
 
-HeightMap::HeightMap(const std::string &file)
+HeightMap::HeightMap(const std::string &file, World* world)
 {
 {
 	int bpp;
 	int bpp;
 	unsigned char* imgData = stbi_load(file.c_str(), &width, &height, &bpp, 4);
 	unsigned char* imgData = stbi_load(file.c_str(), &width, &height, &bpp, 4);
 
 
-	for (int h = 0; h < height; h++)
+	auto heightAt = [&](int x, int y)
+	{
+		return (imgData[(x + y * width) * 4 ] / 256.0f) * 50.0f;
+	};
+
+	auto valueAt = [&](int x, int y, int offset = 0)
+	{
+		return imgData[(x + y * width) * 4 + offset];
+	};
+
+	for (int y = 0; y < height-1; y++)
 	{
 	{
-		for (int w = 0; w < width; w++)
+		for (int x = 0; x < width-1; x++)
 		{
 		{
 			int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
 			int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
-			for (int i = 0; i < 4; i++)
+			Vec3f ca(0, heightAt(x, y + 1) - heightAt(x, y), 1);
+			Vec3f ba(1, heightAt(x + 1, y) - heightAt(x, y), 0);
+
+			if (valueAt(x, y, GREEN) > 0)
 			{
 			{
-				float y = ((float)imgData[((h + offsets[i][0]) + (w + offsets[i][1]) * width) * 4]);
-				y = (y / 256.0f) * 100.0f;
+				world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, 0, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
+			}
+
+			Vec3f normal = ca.cross(ba);
+			normal.Normalize();
 
 
-				vertices.push_back(Vertex{ (float)(h + offsets[i][0])*scale, y*scale, (float)(w + offsets[i][1])*scale,
-									0, 1, 0,
-									(h + offsets[i][0]) / (float)height, (w + offsets[i][1]) / (float)width } );
+			for (int i = 0; i < 4; i++)
+			{
+				float h = heightAt(x + offsets[i][0], y + offsets[i][1]);
+				vertices.push_back(Vertex{ (float)(x + offsets[i][0]), h, (float)(y + offsets[i][1]),
+									normal.x, normal.y, normal.z,
+									(x + offsets[i][0]) / (float)height, (y + offsets[i][1]) / (float)width } );
 			}
 			}
 		}
 		}
 	}
 	}
@@ -48,32 +75,60 @@ HeightMap::HeightMap(const std::string &file)
 
 
 HeightMap::~HeightMap()
 HeightMap::~HeightMap()
 {
 {
+	glDeleteTextures(1, &imageIndex);
 }
 }
 
 
 void HeightMap::Draw()
 void HeightMap::Draw()
 {
 {
+	glEnable(GL_LIGHTING);
+	float color[] = { 0.7f, 0.7f, 0.7f, 1 };
+	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
+	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
+
 	glEnable(GL_TEXTURE_2D);
 	glEnable(GL_TEXTURE_2D);
 	glBindTexture(GL_TEXTURE_2D, imageIndex);
 	glBindTexture(GL_TEXTURE_2D, imageIndex);
 
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	//glEnableClientState(GL_COLOR_ARRAY);
 	//glEnableClientState(GL_COLOR_ARRAY);
-	//glEnableClientState(GL_NORMAL_ARRAY);
+	glEnableClientState(GL_NORMAL_ARRAY);
 
 
 	glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((float*)vertices.data()) + 0);
 	glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((float*)vertices.data()) + 0);
 	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), ((float*)vertices.data()) + 6);
 	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), ((float*)vertices.data()) + 6);
-	//glNormalPointer(GL_FLOAT, sizeof(Vertex), ((float*)cubeVertices.data()) + 3);
+	glNormalPointer(GL_FLOAT, sizeof(Vertex), ((float*)vertices.data()) + 3);
 	glDrawArrays(GL_QUADS, 0, vertices.size());
 	glDrawArrays(GL_QUADS, 0, vertices.size());
 
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	//glDisableClientState(GL_COLOR_ARRAY);
 	//glDisableClientState(GL_COLOR_ARRAY);
-	//glDisableClientState(GL_NORMAL_ARRAY);
+	glDisableClientState(GL_NORMAL_ARRAY);
 }
 }
 
 
-void HeightMap::GetHeigth(float x, float z)
+float HeightMap::GetHeight(float x, float y)
 {
 {
+	int ix = x;
+	int iy = y;
+
+	int index = (ix + (width - 1) * iy) * 4;
+
+	if (index + 3 >= vertices.size())
+		index = vertices.size() - 4;
+
+	if (index < 0)
+		index = 0;
+
+	Vertex& a = vertices[index];
+	Vertex& b = vertices[index+1];
+	Vertex& c = vertices[index+3];
+
+	float lowervalue = ((b.z - c.z)*(a.x - c.x) + (c.x - b.x)*(a.z - c.z));
+	float labda1 = ((b.z - c.z)*(x - c.x) + (c.x - b.x)*(y - c.z)) / lowervalue;
+	float labda2 = ((c.y - a.y)*(x - c.x) + (a.x - c.x)*(y - c.y)) / lowervalue;
+	float labda3 = 1 - labda1 - labda2;
+
+	Vertex z = a * labda1 + b * labda2 + c * labda3;
 
 
+	return z.y;
 }
 }
 
 
 void HeightMap::SetTexture(const std::string &file)
 void HeightMap::SetTexture(const std::string &file)

+ 4 - 3
HeightMap.h

@@ -5,6 +5,8 @@
 #include <vector>
 #include <vector>
 #include <GL/freeglut.h>
 #include <GL/freeglut.h>
 
 
+class World;
+
 class HeightMap
 class HeightMap
 {
 {
 private:
 private:
@@ -12,13 +14,12 @@ private:
 	int width;
 	int width;
 
 
 	GLuint imageIndex;
 	GLuint imageIndex;
-	int scale = 1;
 public:
 public:
-	HeightMap(const std::string &file);
+	HeightMap(const std::string &file, World* world);
 	~HeightMap();
 	~HeightMap();
 
 
 	void Draw();
 	void Draw();
-	void GetHeigth(float x, float z);
+	float GetHeight(float x, float y);
 	void SetTexture(const std::string &file);
 	void SetTexture(const std::string &file);
 
 
 	std::vector<Vertex> vertices;
 	std::vector<Vertex> vertices;

+ 94 - 0
Interface.cpp

@@ -0,0 +1,94 @@
+#include "Interface.h"
+#include <GL\freeglut.h>
+#include "CrystalPoint.h"
+
+#include <string>
+
+#include "Player.h"
+
+//Prototype
+void glutBitmapString(std::string str, int x, int y);
+
+Interface::Interface()
+{
+}
+
+
+Interface::~Interface()
+{
+}
+
+void Interface::draw()
+{
+	Player* player = Player::getInstance();
+
+	//Switch view to Ortho
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, 1000, 1000, 0, -10, 10);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	glDisable(GL_LIGHTING);
+	glDisable(GL_DEPTH_TEST);
+	glDisable(GL_TEXTURE_2D);
+	
+	//Draw interface
+
+	//Health bar
+	glBegin(GL_QUADS);
+	glColor4f(0,0,0, 1.0);
+	glVertex2f(250, 980);
+	glVertex2f(250, 965);
+	glVertex2f(750, 965);
+	glVertex2f(750, 980);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glColor4f(1.0f, 0.1f, 0.1f, 1.0);
+	glVertex2f(250, 980);
+	glVertex2f(250, 965);
+
+	glColor4f(1.0f, 0.5f, 0.5f, 1.0);
+	glVertex2f(250 + (player->health / 100 * 500), 965);
+	glVertex2f(250 + (player->health / 100 * 500), 980);
+	glEnd();
+
+	//XP bar
+	glBegin(GL_QUADS);
+	glColor4f(0, 0, 0, 1.0);
+	glVertex2f(250, 950);
+	glVertex2f(250, 935);
+	glVertex2f(750, 935);
+	glVertex2f(750, 950);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glColor4f(1.0f, 1.0f, 0.1f, 1.0);
+	glVertex2f(250, 950);
+	glVertex2f(250, 935);
+
+	glColor4f(1.0f, 1.0f, 0.5f, 1.0);
+	glVertex2f(250 + (player->xp / 100 * 500), 935);
+	glVertex2f(250 + (player->xp / 100 * 500), 950);
+	glEnd();
+
+	//Text: level
+	glColor4f(1.0f, 1.0f, 0.1f, 1.0);
+	glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
+
+}
+
+void Interface::update(float deltaTime)
+{
+
+}
+
+void glutBitmapString(std::string str, int x, int y)
+{
+	glRasterPos2f(x, y);
+	for (int i = 0; i < str.size(); i++)
+	{
+		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
+	}
+}

+ 11 - 0
Interface.h

@@ -0,0 +1,11 @@
+#pragma once
+class Interface
+{
+public:
+	Interface();
+	~Interface();
+
+	void draw(void);
+	void update(float deltaTime);
+};
+

+ 2 - 0
LevelObject.cpp

@@ -7,6 +7,8 @@ LevelObject::LevelObject(const std::string &fileName, const Vec3f &position, con
 {
 {
 	model = Model::load(fileName);
 	model = Model::load(fileName);
 	this->position = position;
 	this->position = position;
+	this->position.x -= model->center.x;
+	this->position.z -= model->center.z;
 	this->rotation = rotation;
 	this->rotation = rotation;
 	this->scale = scale;
 	this->scale = scale;
 	this->canCollide = hasCollision;
 	this->canCollide = hasCollision;

+ 19 - 11
Main.cpp

@@ -1,18 +1,18 @@
 #include <GL/freeglut.h>
 #include <GL/freeglut.h>
 
 
-#include "CrystalJohan.h"
+#include "CrystalPoint.h"
 #include <stdio.h>
 #include <stdio.h>
 #include "Vector.h"
 #include "Vector.h"
 
 
 void configureOpenGL(void);
 void configureOpenGL(void);
 
 
-CrystalJohan* app;
+CrystalPoint* app;
 
 
 bool justMoved = false;
 bool justMoved = false;
 
 
 int main(int argc, char* argv[])
 int main(int argc, char* argv[])
 {
 {
-	app = new CrystalJohan();
+	app = new CrystalPoint();
 	glutInit(&argc, argv);
 	glutInit(&argc, argv);
 
 
 	configureOpenGL();
 	configureOpenGL();
@@ -21,14 +21,15 @@ int main(int argc, char* argv[])
 
 
 	glutDisplayFunc([]() { app->draw(); } );
 	glutDisplayFunc([]() { app->draw(); } );
 	glutIdleFunc([]() { app->update(); } );
 	glutIdleFunc([]() { app->update(); } );
-	glutReshapeFunc([](int w, int h) { app->width = w; app->height = h; glViewport(0, 0, w, h); });
+	glutReshapeFunc([](int w, int h) { CrystalPoint::width = w; CrystalPoint::height = h; glViewport(0, 0, w, h); });
 
 
 	//Keyboard
 	//Keyboard
 	glutKeyboardFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = true; });
 	glutKeyboardFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = true; });
 	glutKeyboardUpFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = false; });
 	glutKeyboardUpFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = false; });
+	glutSpecialFunc([](int c, int, int) { app->keyboardState.special[c] = true; });
+	glutSpecialUpFunc([](int c, int, int) { app->keyboardState.special[c] = false; });
 	
 	
-	//Mouse
-	glutPassiveMotionFunc([](int x, int y)
+	auto mousemotion = [](int x, int y)
 	{
 	{
 		if (justMoved)
 		if (justMoved)
 		{
 		{
@@ -39,11 +40,18 @@ int main(int argc, char* argv[])
 		int dy = y - app->height / 2;
 		int dy = y - app->height / 2;
 		if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
 		if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
 		{
 		{
-			app->mouseOffset = app->mouseOffset + Vec2f(dx,dy);
+			app->mouseOffset = app->mouseOffset + Vec2f(dx, dy);
 			glutWarpPointer(app->width / 2, app->height / 2);
 			glutWarpPointer(app->width / 2, app->height / 2);
 			justMoved = true;
 			justMoved = true;
 		}
 		}
-	});
+	};
+
+	//Mouse
+	glutPassiveMotionFunc(mousemotion);
+	glutMotionFunc(mousemotion);
+
+	CrystalPoint::height = GLUT_WINDOW_HEIGHT;
+	CrystalPoint::width = GLUT_WINDOW_WIDTH;
 
 
 	glutMainLoop();
 	glutMainLoop();
 	return 0;
 	return 0;
@@ -81,8 +89,8 @@ void configureOpenGL()
 	//glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
 	//glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
 	//glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
 	//glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
 
 
-	//glEnable(GL_LIGHTING);
-	//glEnable(GL_LIGHT0);
+	glEnable(GL_LIGHTING);
+	glEnable(GL_LIGHT0);
 
 
-	glutSetCursor(GLUT_CURSOR_CROSSHAIR);
+	glutSetCursor(GLUT_CURSOR_NONE);
 }
 }

+ 14 - 12
Model.cpp

@@ -158,12 +158,11 @@ void Model::Optimise(ObjGroup *t)
 	}
 	}
 }
 }
 
 
-Model::~Model(void)
-{
-}
-
 void Model::draw()
 void Model::draw()
 {
 {
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_NORMAL_ARRAY);
+	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	for (auto &g : groups)
 	for (auto &g : groups)
 	{
 	{
 		if (materials[g->materialIndex]->hasTexture)
 		if (materials[g->materialIndex]->hasTexture)
@@ -194,19 +193,14 @@ void Model::draw()
 			}
 			}
 		}
 		}
 
 
-		glEnableClientState(GL_VERTEX_ARRAY);
-		glEnableClientState(GL_NORMAL_ARRAY);
-		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 		glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 0);
 		glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 0);
 		glNormalPointer(GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 3);
 		glNormalPointer(GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 3);
 		glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 6);
 		glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 6);
 		glDrawArrays(GL_TRIANGLES, 0, g->VertexArray.size());
 		glDrawArrays(GL_TRIANGLES, 0, g->VertexArray.size());
-
-		glDisableClientState(GL_VERTEX_ARRAY);
-		glDisableClientState(GL_NORMAL_ARRAY);
-		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	}
 	}
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_NORMAL_ARRAY);
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
 }
 
 
 void Model::loadMaterialFile(std::string fileName, std::string dirName)
 void Model::loadMaterialFile(std::string fileName, std::string dirName)
@@ -381,3 +375,11 @@ void Model::unload(Model* model)
 		}
 		}
 	}
 	}
 }
 }
+
+Model::~Model(void)
+{
+	for (auto m : cache)
+	{
+		delete m.second.first;
+	}
+}

+ 28 - 2
Player.cpp

@@ -3,9 +3,36 @@
 #include "Player.h"
 #include "Player.h"
 #include <GL/freeglut.h>
 #include <GL/freeglut.h>
 
 
+Player* Player::instance = NULL;
+
 Player::Player()
 Player::Player()
 {
 {
 	speed = 10;
 	speed = 10;
+	health = 50;
+	xp = 75;
+	level = 10;
+}
+
+Player* Player::getInstance()
+{
+	if (instance == nullptr)
+		instance = new Player();
+
+	return instance;
+}
+
+void Player::init()
+{
+	instance = new Player();
+}
+
+Player::~Player()
+{
+	if (leftWeapon)
+		delete leftWeapon;
+
+	if (rightWeapon)
+		delete rightWeapon;
 }
 }
 
 
 void Player::setCamera()
 void Player::setCamera()
@@ -17,8 +44,7 @@ void Player::setCamera()
 }
 }
 
 
 void Player::setPosition(float angle, float fac, bool height)
 void Player::setPosition(float angle, float fac, bool height)
-{
-	fac *= speed;
+{	
 	if (height)
 	if (height)
 		position.y += angle*fac;
 		position.y += angle*fac;
 	else
 	else

+ 10 - 4
Player.h

@@ -1,25 +1,31 @@
 #pragma once
 #pragma once
-
-#include "Singleton.h"
-
 #include "Vector.h"
 #include "Vector.h"
 
 
 class Model;
 class Model;
 
 
-class Player : public Singleton<Player>
+class Player
 {
 {
+private:
+	static Player* instance;
 public:
 public:
 	Player();
 	Player();
+	~Player();
 
 
 	void setCamera();
 	void setCamera();
 	void setPosition(float angle, float fac, bool height);
 	void setPosition(float angle, float fac, bool height);
 
 
+	static Player* getInstance(void);
+	static void init(void);
+
 	Vec3f position;
 	Vec3f position;
 	Vec2f rotation;
 	Vec2f rotation;
 
 
 	Model* leftWeapon;
 	Model* leftWeapon;
 	Model* rightWeapon;
 	Model* rightWeapon;
 
 
+	float health;
+	float xp;
+	int level;
 
 
 	float speed;
 	float speed;
 };
 };

+ 7 - 7
ReadMe.txt

@@ -1,27 +1,27 @@
 ========================================================================
 ========================================================================
-    CONSOLE APPLICATION : CrystalJohan Project Overview
+    CONSOLE APPLICATION : CrystalPoint Project Overview
 ========================================================================
 ========================================================================
 
 
-AppWizard has created this CrystalJohan application for you.
+AppWizard has created this CrystalPoint application for you.
 
 
 This file contains a summary of what you will find in each of the files that
 This file contains a summary of what you will find in each of the files that
-make up your CrystalJohan application.
+make up your CrystalPoint application.
 
 
 
 
-CrystalJohan.vcxproj
+CrystalPoint.vcxproj
     This is the main project file for VC++ projects generated using an Application Wizard.
     This is the main project file for VC++ projects generated using an Application Wizard.
     It contains information about the version of Visual C++ that generated the file, and
     It contains information about the version of Visual C++ that generated the file, and
     information about the platforms, configurations, and project features selected with the
     information about the platforms, configurations, and project features selected with the
     Application Wizard.
     Application Wizard.
 
 
-CrystalJohan.vcxproj.filters
+CrystalPoint.vcxproj.filters
     This is the filters file for VC++ projects generated using an Application Wizard. 
     This is the filters file for VC++ projects generated using an Application Wizard. 
     It contains information about the association between the files in your project 
     It contains information about the association between the files in your project 
     and the filters. This association is used in the IDE to show grouping of files with
     and the filters. This association is used in the IDE to show grouping of files with
     similar extensions under a specific node (for e.g. ".cpp" files are associated with the
     similar extensions under a specific node (for e.g. ".cpp" files are associated with the
     "Source Files" filter).
     "Source Files" filter).
 
 
-CrystalJohan.cpp
+CrystalPoint.cpp
     This is the main application source file.
     This is the main application source file.
 
 
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
@@ -29,7 +29,7 @@ Other standard files:
 
 
 StdAfx.h, StdAfx.cpp
 StdAfx.h, StdAfx.cpp
     These files are used to build a precompiled header (PCH) file
     These files are used to build a precompiled header (PCH) file
-    named CrystalJohan.pch and a precompiled types file named StdAfx.obj.
+    named CrystalPoint.pch and a precompiled types file named StdAfx.obj.
 
 
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 Other notes:
 Other notes:

+ 0 - 13
Singleton.h

@@ -1,13 +0,0 @@
-#pragma once
-
-
-template <class T>
-class Singleton
-{
-public:
-	static T& getInstance()
-	{
-		static T* t = new T();
-		return *t;
-	}
-};

+ 14 - 0
Vector.cpp

@@ -80,6 +80,20 @@ bool Vec3f::operator!=(const Vec3f & other)
 	return x != other.x & y != other.y & z != other.z;
 	return x != other.x & y != other.y & z != other.z;
 }
 }
 
 
+Vec3f Vec3f::operator*(const float & other)
+{
+	return Vec3f(x*other, y*other, z*other);
+}
+
+Vec3f Vec3f::cross(const Vec3f & other)
+{
+	return Vec3f(
+		y*other.z - other.y*z,
+		z*other.x - other.z*x,
+		x*other.y - other.x*y
+		);
+}
+
 
 
 
 
 Vec2f::Vec2f(float x, float y)
 Vec2f::Vec2f(float x, float y)

+ 4 - 0
Vector.h

@@ -23,6 +23,10 @@ public:
 	Vec3f operator / (float value);
 	Vec3f operator / (float value);
 	bool operator ==(const Vec3f &other);
 	bool operator ==(const Vec3f &other);
 	bool operator !=(const Vec3f &other);
 	bool operator !=(const Vec3f &other);
+	Vec3f operator *(const float &other);
+
+	Vec3f cross(const Vec3f &other);
+
 };
 };
 
 
 class Vec2f
 class Vec2f

+ 20 - 0
Vertex.cpp

@@ -17,3 +17,23 @@ Vertex::Vertex(float x, float y, float z, float nx, float ny, float nz, float tx
 Vertex::~Vertex()
 Vertex::~Vertex()
 {
 {
 }
 }
+
+Vertex Vertex::operator/(float &other)
+{
+	return Vertex(x / other, y / other, z / other, normalX, normalY, normalZ, texX, texY);
+}
+
+Vertex Vertex::operator*(Vertex & other)
+{
+	return Vertex(x*other.x, y*other.y, z*other.z, normalX, normalY, normalZ, texX, texY);
+}
+
+Vertex Vertex::operator*(float & other)
+{
+	return Vertex(x*other, y*other, z*other, normalX, normalY, normalZ, texX, texY);
+}
+
+Vertex Vertex::operator+(Vertex & other)
+{
+	return Vertex(x+other.x, y+other.y, z+other.z, normalX, normalY, normalZ, texX, texY);
+}

+ 5 - 0
Vertex.h

@@ -15,5 +15,10 @@ public:
 
 
 	float texX;
 	float texX;
 	float texY;
 	float texY;
+
+	Vertex operator/(float &other);
+	Vertex operator*(Vertex &other);
+	Vertex operator*(float &other);
+	Vertex operator+(Vertex &other);
 };
 };
 
 

+ 113 - 65
World.cpp

@@ -1,106 +1,151 @@
 #include "World.h"
 #include "World.h"
 #include <GL/freeglut.h>
 #include <GL/freeglut.h>
 #include "Entity.h"
 #include "Entity.h"
-#include "LevelObject.h"
 #include "json.h"
 #include "json.h"
+#include "Model.h"
+#include "CrystalPoint.h"
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
 
 
-World::World() : player(Player::getInstance())
+World::World(const std::string &fileName)
 {
 {
+	//Store player instance
+	player = Player::getInstance();
 
 
-	std::ifstream file("worlds/world1.json");
+	//Create the interface
+	interface = new Interface();
+
+	//Open world json file
+	std::ifstream file(fileName);
 	if(!file.is_open())
 	if(!file.is_open())
-		std::cout<<"Uhoh, can't open file\n";
+		std::cout<<"Error, can't open world file - " << fileName << "\n";
 
 
 	json::Value v = json::readJson(file);
 	json::Value v = json::readJson(file);
 	file.close();
 	file.close();
 
 
-	heightmap = new HeightMap(v["world"]["heightmap"].asString());
-	heightmap->SetTexture(v["world"]["texture"].asString());
+	//Check file
+	if(v["world"].isNull() || v["world"]["heightmap"].isNull())
+		std::cout << "Invalid world file: world - " << fileName << "\n";
+	if (v["player"].isNull() || v["player"]["startposition"].isNull())
+		std::cout << "Invalid world file: player - " << fileName << "\n";
+	if (v["objects"].isNull())
+		std::cout << "Invalid world file: objects - " << fileName << "\n";
+	if (v["world"]["object-templates"].isNull())
+		std::cout << "Invalid world file: object templates - " << fileName << "\n";
+
+	//Load object templates
+	for (auto objt : v["world"]["object-templates"])
+	{
+		//collision
+		bool cancollide = true;
+		if (!objt["collision"].isNull())
+			cancollide = objt["collision"].asBool();
+
+		objecttemplates.push_back(std::pair<int, std::pair<std::string, bool>>(objt["color"], std::pair<std::string, bool>(objt["file"], cancollide)));
+	}
+
+	//Generate heightmap for this world
+	heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
 
 
-	player.position.x = v["player"]["startposition"][0];
-	player.position.y = v["player"]["startposition"][1];
-	player.position.z = v["player"]["startposition"][2];
+	//Map different texture to heightmap if available
+	if(!v["world"]["texture"].isNull())
+		heightmap->SetTexture(v["world"]["texture"].asString());
 
 
+	//Set player starting position
+	player->position.x = v["player"]["startposition"][0].asFloat();
+	player->position.y = v["player"]["startposition"][1].asFloat();
+	player->position.z = v["player"]["startposition"][2].asFloat();
 
 
+	//Load and place objects into world
 	for (auto object : v["objects"])
 	for (auto object : v["objects"])
 	{
 	{
+		//Collision
 		bool hasCollision = true;
 		bool hasCollision = true;
 		if (!object["collide"].isNull())
 		if (!object["collide"].isNull())
 			hasCollision = object["collide"].asBool();
 			hasCollision = object["collide"].asBool();
 
 
+		//Rotation
 		Vec3f rotation(0, 0, 0);
 		Vec3f rotation(0, 0, 0);
 		if(!object["rot"].isNull())
 		if(!object["rot"].isNull())
-			rotation = Vec3f(object["rot"][0], object["rot"][1], object["rot"][2]);
+			rotation = Vec3f(object["rot"][0].asFloat(), object["rot"][1].asFloat(), object["rot"][2].asFloat());
 
 
+		//Scale
 		float scale = 1;
 		float scale = 1;
 		if (!object["scale"].isNull())
 		if (!object["scale"].isNull())
 			scale = object["scale"].asFloat();
 			scale = object["scale"].asFloat();
 		
 		
-		Vec3f position(object["pos"][0], object["pos"][1], object["pos"][2]);
-		entities.push_back(new LevelObject(object["file"], position, rotation, scale, hasCollision));
+		//Position
+		if (object["pos"].isNull())
+			std::cout << "Invalid world file: objects pos - " << fileName << "\n";
+		
+		//File
+		if (object["file"].isNull())
+			std::cout << "Invalid world file: objects file - " << fileName << "\n";
+
+		//Create
+		Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());
+		entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
 	}
 	}
 
 
-	//look up table for the enemies	
-	std::vector<std::pair<int, std::string>>enemy_models;
-	for (auto enemy_model : v["enemy_models"])
+	//Load and place enemies into world
+	for (auto e : v["enemies"])
 	{		
 	{		
-		int id = -1;
-		if (!enemy_model["id"].isNull())
-			id = enemy_model["id"].asInt();
+		//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 fileName = "";
-		if (!enemy_model["file"].isNull())
-			fileName = enemy_model["file"].asString();
+		//Scale
+		float scale = 1.0f;
+		if (!e["scale"].isNull())
+			scale = e["scale"].asFloat();
 
 
-		enemy_models.push_back(std::pair<int, std::string>(id,fileName));
-	}
+		//Position
+		if (e["pos"].isNull())
+			std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
 
 
-	for (auto enemy : v["enemy_data"])
-	{
-		int id = -1;
-		if (!enemy["id"].isNull())
-			id = enemy["id"];
-		for (auto enemy_model : enemy_models)
-		{
-			if (id == enemy_model.first)
-			{				
-				Vec3f position(0, 0, 0);
-				if (!enemy["pos"].isNull())
-					position = Vec3f(enemy["pos"][0], enemy["pos"][1], enemy["pos"][2]);
-
-				Vec3f rotation(0, 0, 0);
-				if (!enemy["rot"].isNull())
-					rotation = Vec3f(enemy["rot"][0], enemy["rot"][1], enemy["rot"][2]);
-
-				float scale = 1.0f;
-				if (!enemy["scale"].isNull())
-					scale = enemy["scale"].asFloat();
-				
-				enemies.push_back(new Enemy(enemy_model.second,position,rotation,scale,true));
-			}
+		//File
+		if (e["file"].isNull())
+			std::cout << "Invalid world file: enemies file - " << fileName << "\n";
+
+		//Create
+		Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
+		enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
 
 
-		}
-		
 	}
 	}
 }
 }
 
 
 
 
 World::~World()
 World::~World()
 {
 {
+	//delete heightmap;
+}
+
+std::pair<std::string, bool> World::getObjectFromValue(int val)
+{
+	for (auto i : objecttemplates)
+	{
+		if (i.first == val)
+			return i.second;
+	}
+
+	return objecttemplates[0].second;
+}
+
+float World::getHeight(float x, float y)
+{
+	return heightmap->GetHeight(x, y);
 }
 }
 
 
 void World::draw()
 void World::draw()
 {
 {
-	player.setCamera();
+	player->setCamera();
 
 
 	float lightPosition[4] = { 0, 2, 1, 0 };
 	float lightPosition[4] = { 0, 2, 1, 0 };
 	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
 	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
-	float lightAmbient[4] = { 0.5, 0.5, 0.5, 1 };
+	float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
 	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
 	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
 
 
-	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 	heightmap->Draw();
 	heightmap->Draw();
 
 
 	for (auto &enemy : enemies)
 	for (auto &enemy : enemies)
@@ -109,8 +154,7 @@ void World::draw()
 	for (auto &entity : entities)
 	for (auto &entity : entities)
 		entity->draw();
 		entity->draw();
 
 
-	
-
+	interface->draw();
 }
 }
 
 
 void World::update(float elapsedTime)
 void World::update(float elapsedTime)
@@ -120,16 +164,11 @@ void World::update(float elapsedTime)
 
 
 	for (auto &enemy : enemies)
 	for (auto &enemy : enemies)
 	{
 	{
-		if (enemy->position.Distance(player.position) <= enemy->radius)
-		{			
-			enemy->hasTarget = true;
-			enemy->target.x = player.position.x;
-			enemy->target.z = player.position.z;
-		}
-		else
-			enemy->hasTarget = false;
-
-		Vec3f oldpos = enemy->position;
+
+		//Al deze code zou in enemy moeten staan
+		enemy->inEyeSight(player->position);
+
+		
 		enemy->update(elapsedTime);
 		enemy->update(elapsedTime);
 		if (enemy->hasTarget)
 		if (enemy->hasTarget)
 		{
 		{
@@ -137,19 +176,28 @@ void World::update(float elapsedTime)
 			{
 			{
 				if (e->canCollide && e->inObject(enemy->position))
 				if (e->canCollide && e->inObject(enemy->position))
 				{
 				{
-					enemy->position = oldpos;
+					Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden
+					difference.Normalize();
+					difference = difference * (e->model->radius + 0.01f);
+					enemy->position = e->position + difference;
 					break;
 					break;
 				}
 				}
 			}
 			}
 		}		
 		}		
+		//tot hier
 	}
 	}
 }
 }
 
 
+void World::addLevelObject(LevelObject* obj)
+{
+	entities.push_back(obj);
+}
+
 bool World::isPlayerPositionValid()
 bool World::isPlayerPositionValid()
 {
 {
 	for (auto e : entities)
 	for (auto e : entities)
 	{
 	{
-		if (e->canCollide && e->inObject(player.position))
+		if (e->canCollide && e->inObject(player->position))
 			return false;
 			return false;
 	}
 	}
 	return true;
 	return true;

+ 13 - 7
World.h

@@ -4,25 +4,31 @@
 #include "HeightMap.h"
 #include "HeightMap.h"
 #include "Player.h"
 #include "Player.h"
 #include "Enemy.h"
 #include "Enemy.h"
+#include "LevelObject.h"
+#include "Interface.h"
 
 
 class Entity;
 class Entity;
 
 
 class World
 class World
 {
 {
-public:
-	World();
-	~World();
+private:
+	std::vector<std::pair<int, std::pair<std::string, bool>>> objecttemplates;
 
 
+	Player* player;
+	HeightMap* heightmap;
+	Interface* interface;
 
 
-	Player& player;
 	std::vector<Entity*> entities;
 	std::vector<Entity*> entities;
-
 	std::vector<Enemy*> enemies;
 	std::vector<Enemy*> enemies;
-
-	HeightMap* heightmap;
+public:
+	World(const std::string &fileName);
+	~World();
 
 
 	void draw();
 	void draw();
 	void update(float elapsedTime);
 	void update(float elapsedTime);
 	bool isPlayerPositionValid();
 	bool isPlayerPositionValid();
+	float getHeight(float x, float y);
+	void addLevelObject(LevelObject* obj);
+	std::pair<std::string, bool> getObjectFromValue(int i);
 };
 };
 
 

+ 137 - 0
WorldHandler.cpp

@@ -0,0 +1,137 @@
+#include "WorldHandler.h"
+#include "World.h"
+
+#include "json.h"
+#include <fstream>
+#include <iostream>
+#include <string>
+
+WorldHandler* WorldHandler::instance = nullptr;
+
+void WorldHandler::ChangeWorld(int i)
+{
+	if (i < 0)
+		i = worldfiles.size() - 1;
+
+	else if (i >= worldfiles.size())
+		i = 0;
+
+	if (i != worldIndex)
+	{
+		loadingWorld = true;
+
+		if(worldIndex != -1)
+			delete world;
+
+		world = new World(worldfiles[i]);
+		worldIndex = i;
+		loadingWorld = false;
+	}
+}
+
+WorldHandler::WorldHandler()
+{
+	loadingWorld = true;
+	worldIndex = -1;
+
+	//Find worlds.json
+	std::ifstream file("worlds/worlds.json");
+	if (!file.is_open())
+		std::cout << "Error, can't open worlds overview file\n";
+
+	json::Value v = json::readJson(file);
+	file.close();
+
+	//Load file names into vector
+	if (v["worlds"].isNull() || !v["worlds"].isArray())
+		std::cout << "Error, no content in worlds overview file\n";
+
+	for (auto line : v["worlds"])
+	{
+		std::cout << "Found world: " << line << "\n";
+		worldfiles.push_back(line);
+	}
+
+	if (worldfiles.size() > 0)
+	{
+		ChangeWorld(0);
+	}
+}
+
+WorldHandler::~WorldHandler()
+{
+	worldIndex = -1;
+	delete world;
+}
+
+WorldHandler* WorldHandler::getInstance()
+{
+	if (instance == nullptr)
+		instance = new WorldHandler();
+
+	return instance;
+}
+
+void WorldHandler::init()
+{
+	instance = new WorldHandler();
+}
+
+void WorldHandler::draw(void)
+{
+	if(!loadingWorld)
+		world->draw();
+	else
+	{
+		//Draw Loading screen
+	}
+}
+
+void WorldHandler::update(float deltaTime)
+{
+	if(!loadingWorld)
+		world->update(deltaTime);
+}
+
+bool WorldHandler::isPlayerPositionValid(void)
+{
+	if(!loadingWorld)
+		return world->isPlayerPositionValid();
+}
+
+float WorldHandler::getHeight(float x, float y)
+{
+	if (!loadingWorld)
+		return world->getHeight(x, y);
+	else
+		return 0.0f;
+}
+
+
+void WorldHandler::Navigate(const std::string &fileName)
+{
+	if (!loadingWorld)
+	{
+		for (int i = 0; i < worldfiles.size(); i++)
+		{
+			if (worldfiles[i] == fileName)
+				ChangeWorld(i);
+		}
+	}
+}
+
+void WorldHandler::NextWorld()
+{
+	if (!loadingWorld)
+	{
+		ChangeWorld(worldIndex + 1);
+	}
+}
+
+void WorldHandler::PreviousWorld()
+{
+	if (!loadingWorld)
+	{
+		ChangeWorld(worldIndex - 1);
+	}
+}

+ 36 - 0
WorldHandler.h

@@ -0,0 +1,36 @@
+#pragma once
+#include <string>
+#include <vector>
+
+class World;
+
+class WorldHandler
+{
+private:
+	WorldHandler();
+	static WorldHandler* instance;
+
+	bool loadingWorld;
+	World* world;
+	int worldIndex;
+	void ChangeWorld(int i);
+public:
+	
+	~WorldHandler();
+
+	static WorldHandler* getInstance(void);
+	static void init();
+
+	void draw(void);
+	void update(float deltaTime);
+
+	bool isPlayerPositionValid(void);
+	float getHeight(float x, float y);
+
+	void Navigate(const std::string &fileName);
+	void NextWorld();
+	void PreviousWorld();
+
+	std::vector<std::string> worldfiles;
+};
+

+ 38 - 0
worlds/fire.json

@@ -0,0 +1,38 @@
+{
+   "world": {
+    "heightmap": "worlds/hell.png",
+    "texture": "worlds/helltexture.png",
+	    "object-templates": [
+			  {
+				  "color": 25,
+				  "file": "models/boom/Boom.obj"
+			  },
+			  {
+				  "color": 23,
+				  "file": "models/boom/Boom.obj"
+			  }
+	    ]
+   },
+  "player": {
+    "startposition": [ 0, 1.7, 0]
+  },
+  "objects": [
+    {
+      "file": "models/boom/Boom.obj",
+      "pos": [ 4, 0, -4 ],
+      "collide": "true"
+    },
+    {
+      "file": "models/boom/Boom.obj",
+      "pos": [ -4, 0, -4 ],
+      "collide": "true"
+     }
+  ],
+  "enemies": [
+    {
+      "file": "models/squid/Blooper.obj",
+      "pos": [ 1, 2, -10 ],
+      "scale": 0.01
+    }
+  ]
+}

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
worlds/hell.pdn




+ 33 - 0
worlds/ice.json

@@ -0,0 +1,33 @@
+{
+   "world": {
+    "heightmap": "worlds/hmcs.png",
+    "texture": "worlds/hmcstexture.png",
+    "object-templates": [
+		{
+			"color":100,
+			"file": "models/boom/Boom.obj",
+			"collision": false
+		}
+	]
+   },
+  "player": {
+    "startposition": [ 0, 1.7, 0]
+  },
+  "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 ],
+      "scale": 0.01
+    }
+  ]
+}

+ 17 - 0
worlds/small.json

@@ -0,0 +1,17 @@
+{
+   "world": {
+    "heightmap": "worlds/small.png",
+	"object-templates": [
+		{
+			"color":100,
+			"file": "models/boom/Boom.obj",
+			"collision": false
+		}
+	]
+   },
+  "player": {
+    "startposition": [ 20, 5, 20 ]
+  },
+  "objects": [],
+  "enemies": []
+}


+ 0 - 33
worlds/world1.json

@@ -1,33 +0,0 @@
-{
-   "world": {
-      "heightmap": "worlds/hmcs.png",
-	  "texture": "worlds/hmcstexture.png"
-   },
-  "player": {
-    "startposition": [ -100, 1.7, -100 ]
-  },
-  "objects": [
-    {
-      "file": "models/boom/Boom.obj",
-      "pos": [ 4, 0, -4 ]
-    },
-    {
-      "file": "models/Teleporter/Teleporter.obj",
-      "pos": [ 0, 0, -4 ],
-      "rot": [ 0, 0, 0 ]
-    }
-  ],
-  "enemy_models": [
-    {
-      "id": 0,
-      "file": "models/squid/Blooper.obj"
-    }
-  ],
-  "enemy_data": [
-    {
-      "id": 0,
-      "pos": [ 1, 2, -10 ],
-      "scale": 0.01
-    }   
-  ]
-}

+ 7 - 0
worlds/worlds.json

@@ -0,0 +1,7 @@
+{
+  "worlds": [
+    "worlds/small.json",
+    "worlds/ice.json",
+    "worlds/fire.json"
+  ]
+}

Неке датотеке нису приказане због велике количине промена