Bläddra i källkod

Merge pull request #31 from CrystalPointA4/feature/loadingscreen

Feature/loadingscreen (reverted from commit 316d6c9e14c4a5e6964bdadcadcad36d133d90f4)
jancoow 9 år sedan
förälder
incheckning
92460b8ca4
25 ändrade filer med 180 tillägg och 194 borttagningar
  1. 1 0
      Controller.h
  2. 6 1
      ControllerHandler.cpp
  3. 57 38
      CrystalPoint.cpp
  4. 0 1
      CrystalPoint.h
  5. 0 2
      CrystalPoint.vcxproj
  6. 0 6
      CrystalPoint.vcxproj.filters
  7. 27 1
      Enemy.cpp
  8. 4 0
      Enemy.h
  9. 0 71
      LoadingScreen.cpp
  10. 0 22
      LoadingScreen.h
  11. 3 3
      Main.cpp
  12. 12 2
      Player.cpp
  13. 2 0
      Player.h
  14. 1 0
      Vector.cpp
  15. BIN
      WAVE/ape.wav
  16. BIN
      WAVE/hedge.wav
  17. BIN
      WAVE/letsRock.wav
  18. 44 10
      Weapon.cpp
  19. 3 2
      Weapon.h
  20. 13 25
      World.cpp
  21. 0 3
      World.h
  22. 6 4
      weapons.json
  23. BIN
      worlds/loadingScreen_picture.png
  24. 0 1
      worlds/rock.json
  25. 1 2
      worlds/small.json

+ 1 - 0
Controller.h

@@ -9,6 +9,7 @@ public:
     Vec3f ypr;
     Vec3f ypr;
     Vec2f joystick;
     Vec2f joystick;
     bool button, joystickButton, magnetSwitch;
     bool button, joystickButton, magnetSwitch;
+    bool lastButton, lastJoystickButton, lastMagetSwitch;
     int controllerId;
     int controllerId;
 
 
     void setConnected(bool connected);
     void setConnected(bool connected);

+ 6 - 1
ControllerHandler.cpp

@@ -120,8 +120,13 @@ void ControllerHandler::commandControllerData(std::vector<std::string> data) {
 
 
             c->joystick.x = std::stoi(data[2])/2000.0f;
             c->joystick.x = std::stoi(data[2])/2000.0f;
             c->joystick.y = std::stoi(data[3])/2000.0f;
             c->joystick.y = std::stoi(data[3])/2000.0f;
-            c->joystickButton = !(data[4] == "0");
 
 
+            c->lastButton = c->button;
+            c->lastJoystickButton = c->joystickButton;
+            c->lastMagetSwitch = c->magnetSwitch;
+
+            c->joystickButton = !(data[4] == "0");
+            c->button = !(data[8] == "0");
             c->magnetSwitch = !(data[9] == "0");
             c->magnetSwitch = !(data[9] == "0");
         }
         }
     }
     }

+ 57 - 38
CrystalPoint.cpp

@@ -24,7 +24,7 @@ void CrystalPoint::init()
 	cursor = Cursor::getInstance();
 	cursor = Cursor::getInstance();
 
 
 	menu = new Menu();
 	menu = new Menu();
-	menuIsBuild = false;
+	buildMenu();
 
 
 	lastFrameTime = 0;
 	lastFrameTime = 0;
 	state = true;
 	state = true;
@@ -64,8 +64,11 @@ void CrystalPoint::update()
 	lastFrameTime = frameTime;
 	lastFrameTime = frameTime;
 
 
 	if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
 	if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
-		state = !state;
-		
+        state = !state;
+
+	Controller *rightcontroller = controller.getRightController();
+	Controller *leftcontroller = controller.getLeftController();
+
 	if (state)
 	if (state)
 	{
 	{
 		Player* player = Player::getInstance();
 		Player* player = Player::getInstance();
@@ -75,7 +78,7 @@ void CrystalPoint::update()
 		if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
 		if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
 			worldhandler->NextWorld();
 			worldhandler->NextWorld();
 		if (keyboardState.special[GLUT_KEY_UP] && !prevKeyboardState.special[GLUT_KEY_UP])
 		if (keyboardState.special[GLUT_KEY_UP] && !prevKeyboardState.special[GLUT_KEY_UP])
-			player->NextLeftWeapon();
+			player->NextRightWeapon();
 		if (keyboardState.special[GLUT_KEY_DOWN] && !prevKeyboardState.special[GLUT_KEY_DOWN])
 		if (keyboardState.special[GLUT_KEY_DOWN] && !prevKeyboardState.special[GLUT_KEY_DOWN])
 			player->PreviousLeftWeapon();
 			player->PreviousLeftWeapon();
 		if (keyboardState.keys[27])
 		if (keyboardState.keys[27])
@@ -103,42 +106,53 @@ void CrystalPoint::update()
 		if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
 		if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
 		if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
 		if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
 
 
-		Controller *leftcontroller = controller.getLeftController();
 		if (leftcontroller != nullptr) {
 		if (leftcontroller != nullptr) {
 			Vec2f *leftControllerJoystick = &leftcontroller->joystick;
 			Vec2f *leftControllerJoystick = &leftcontroller->joystick;
 
 
-
-			if (leftcontroller->joystickButton) {
-				controller.rumble(leftcontroller->controllerId, 100, 100);
+			if (leftControllerJoystick->y > 0.3 || leftControllerJoystick->y < -0.3) {
+				player->rotation.x += leftControllerJoystick->y/4;
 			}
 			}
 
 
-
-			if (leftControllerJoystick->y > 0.3) {
-				player->setPosition(270, leftControllerJoystick->y * deltaTime * 2.0f, false);
-			}
-			else if (leftControllerJoystick->y < -0.3) {
-				player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime * 2.0f, false);
-			}
-			if (leftControllerJoystick->x > 0.3) {
-				player->setPosition(180, leftControllerJoystick->x * deltaTime * 2.0f, false);
-			}
-			else if (leftControllerJoystick->x < -0.3) {
-				player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime * 2.0f, false);
+			if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) {
+				player->rotation.y += leftControllerJoystick->x/4;
 			}
 			}
 
 
 			player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
 			player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
 
 
+			if(leftcontroller->button && leftcontroller->joystickButton){
+				state = !state;
+			}else if(!leftcontroller->lastButton && leftcontroller->button){
+                leftcontroller->lastButton = leftcontroller->button;
+                controller.rumble(leftcontroller->controllerId, 100, 200);
+                player->NextLeftWeapon();
+            }else if(!leftcontroller->lastJoystickButton && leftcontroller->joystickButton){
+                leftcontroller->lastJoystickButton = leftcontroller->joystickButton;
+                player->hit = true;
+            }
+
 		}
 		}
-		Controller *rightcontroller = controller.getRightController();
 		if(rightcontroller != nullptr){
 		if(rightcontroller != nullptr){
 			Vec2f *rightControllerJoystick = &rightcontroller->joystick;
 			Vec2f *rightControllerJoystick = &rightcontroller->joystick;
-			if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) {
-				player->rotation.x += rightcontroller->joystick.y/4;
-			}
 
 
-			if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) {
-				player->rotation.y += rightcontroller->joystick.x/4;
+			if (rightControllerJoystick->y > 0.3) {
+				player->setPosition(270, rightControllerJoystick->y * deltaTime * 2.0f, false);
+			}
+			else if (rightControllerJoystick->y < -0.3) {
+				player->setPosition(90, rightControllerJoystick->y * -1 * deltaTime * 2.0f, false);
+			}
+			if (rightControllerJoystick->x > 0.3) {
+				player->setPosition(180, rightControllerJoystick->x * deltaTime * 2.0f, false);
+			}
+			else if (rightControllerJoystick->x < -0.3) {
+				player->setPosition(0, rightControllerJoystick->x * -1 * deltaTime * 2.0f, false);
 			}
 			}
+
+            if(!rightcontroller->lastButton && rightcontroller->button){
+                rightcontroller->lastButton = rightcontroller->button;
+                controller.rumble(rightcontroller->controllerId, 100, 200);
+                player->NextRightWeapon();
+            }
+
             player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z));
             player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z));
         }
         }
 
 
@@ -151,19 +165,25 @@ void CrystalPoint::update()
 
 
 		if (!worldhandler->isPlayerPositionValid())
 		if (!worldhandler->isPlayerPositionValid())
 			player->position = oldPosition;
 			player->position = oldPosition;
-		/*else if (player->position.y > oldPosition.y + 1.2)
-			player->position = oldPosition;
-		*/
 		worldhandler->update(deltaTime);
 		worldhandler->update(deltaTime);
 	}	
 	}	
 	else
 	else
 	{
 	{
-		if (!menuIsBuild)
-		{
-			buildMenu();
-			menuIsBuild = true;
-		}
 		menu->update();
 		menu->update();
+		if (leftcontroller != nullptr) {
+			Vec2f *leftControllerJoystick = &leftcontroller->joystick;
+			if (leftControllerJoystick->y > 0.3 || leftControllerJoystick->y < -0.3) {
+				cursor->update(Vec2f(cursor->mousePosition.x,cursor->mousePosition.y+leftControllerJoystick->y ));
+			}
+			if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) {
+				cursor->update(Vec2f(cursor->mousePosition.x+leftControllerJoystick->x ,cursor->mousePosition.y));
+			}
+			if(leftcontroller->button){
+				cursor->state = 137;
+			}else if(cursor->state == 137){
+				cursor->state = GLUT_UP;
+			}
+		}
 		cursor->update(cursor->mousePosition + mouseOffset);
 		cursor->update(cursor->mousePosition + mouseOffset);
 	}
 	}
 
 
@@ -177,7 +197,7 @@ void CrystalPoint::update()
 
 
 void CrystalPoint::buildMenu()
 void CrystalPoint::buildMenu()
 {
 {
-	Button* start = new Button("Resume", Vec2f(width / 2 - 50, height / 2 - 30), 100, 50);
+	Button* start = new Button("Resume", Vec2f(1920 / 2 - 50, 1080 / 2 - 30), 100, 50);
 	auto toWorld = [](Button* b)
 	auto toWorld = [](Button* b)
 	{
 	{
 		state = true;
 		state = true;
@@ -186,14 +206,13 @@ void CrystalPoint::buildMenu()
 	menu->AddMenuElement(start);
 	menu->AddMenuElement(start);
 
 
 
 
-	Button* test = new Button("Exit", Vec2f(width / 2 - 50, height / 2 + 30), 100, 50);
+	Button* test = new Button("Exit", Vec2f(1920 / 2 - 50, 1080 / 2 + 30), 100, 50);
 	test->addAction([](Button* b)
 	test->addAction([](Button* b)
 	{
 	{
 		exit(0);
 		exit(0);
 	});
 	});
 	menu->AddMenuElement(test);
 	menu->AddMenuElement(test);
-
-	Text* t = new Text("Pause", Vec2f(width / 2 - Util::glutTextWidth("Pause") / 2, height / 2 - 75));
+	Text* t = new Text("Pause", Vec2f(1920 / 2 - Util::glutTextWidth("Pause") / 2, 1080 / 2 - 75));
 	t->setColor(Vec3f(255, 255, 0));
 	t->setColor(Vec3f(255, 255, 0));
 	menu->AddMenuElement(t);
 	menu->AddMenuElement(t);
 }
 }

+ 0 - 1
CrystalPoint.h

@@ -43,7 +43,6 @@ public:
 
 
 	static SoundSystem& GetSoundSystem() { return sound_system; }
 	static SoundSystem& GetSoundSystem() { return sound_system; }
 	
 	
-	bool menuIsBuild;
 
 
 private:
 private:
 	static SoundSystem sound_system;
 	static SoundSystem sound_system;

+ 0 - 2
CrystalPoint.vcxproj

@@ -170,7 +170,6 @@
     <ClCompile Include="lib\serial\src\impl\list_ports\list_ports_win.cc" />
     <ClCompile Include="lib\serial\src\impl\list_ports\list_ports_win.cc" />
     <ClCompile Include="lib\serial\src\impl\win.cc" />
     <ClCompile Include="lib\serial\src\impl\win.cc" />
     <ClCompile Include="lib\serial\src\serial.cc" />
     <ClCompile Include="lib\serial\src\serial.cc" />
-    <ClCompile Include="LoadingScreen.cpp" />
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Menu.cpp" />
     <ClCompile Include="Menu.cpp" />
     <ClCompile Include="MenuElement.cpp" />
     <ClCompile Include="MenuElement.cpp" />
@@ -204,7 +203,6 @@
     <ClInclude Include="lib\serial\include\impl\win.h" />
     <ClInclude Include="lib\serial\include\impl\win.h" />
     <ClInclude Include="lib\serial\include\serial.h" />
     <ClInclude Include="lib\serial\include\serial.h" />
     <ClInclude Include="lib\serial\include\v8stdint.h" />
     <ClInclude Include="lib\serial\include\v8stdint.h" />
-    <ClInclude Include="LoadingScreen.h" />
     <ClInclude Include="Main.h" />
     <ClInclude Include="Main.h" />
     <ClInclude Include="Menu.h" />
     <ClInclude Include="Menu.h" />
     <ClInclude Include="MenuElement.h" />
     <ClInclude Include="MenuElement.h" />

+ 0 - 6
CrystalPoint.vcxproj.filters

@@ -123,9 +123,6 @@
     <ClCompile Include="Util.cpp">
     <ClCompile Include="Util.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="LoadingScreen.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="World.h">
     <ClInclude Include="World.h">
@@ -224,9 +221,6 @@
     <ClInclude Include="Util.h">
     <ClInclude Include="Util.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="LoadingScreen.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <None Include="worlds\worlds.json">
     <None Include="worlds\worlds.json">

+ 27 - 1
Enemy.cpp

@@ -2,6 +2,7 @@
 #include <cmath>
 #include <cmath>
 #include "Enemy.h"
 #include "Enemy.h"
 #include "Model.h"
 #include "Model.h"
+#include "Player.h"
 #include <iostream>
 #include <iostream>
 
 
 Enemy::Enemy(const std::string &fileName,
 Enemy::Enemy(const std::string &fileName,
@@ -28,7 +29,7 @@ Enemy::Enemy(const std::string &fileName,
 	hasTarget = false;
 	hasTarget = false;
 	hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
 	hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
 	music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
 	music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
-	attack = false;	
+	attack = false;
 }
 }
 
 
 
 
@@ -66,6 +67,14 @@ void Enemy::collide(const Entity * entity)
 	position.z = difference.z + entity->position.z;
 	position.z = difference.z + entity->position.z;
 }
 }
 
 
+void Enemy::hit(int damage){
+	health -= damage;
+}
+
+bool Enemy::isDead(){
+	return health < 0;
+}
+
 void Enemy::update(float delta)
 void Enemy::update(float delta)
 {
 {
 	music->SetPos(position, Vec3f());
 	music->SetPos(position, Vec3f());
@@ -102,4 +111,21 @@ void Enemy::update(float delta)
 		}
 		}
 		rotation.y = atan2f(dx, dz) * 180 / M_PI;		
 		rotation.y = atan2f(dx, dz) * 180 / M_PI;		
 	}
 	}
+	Player *player = Player::getInstance();
+
+	if(inObject(player->position + player->leftWeapon->collisionPoint)){
+		if(!isHit){
+			isHit = true;
+			hit(player->leftWeapon->damage);
+		}
+		std::cout << "HIT1";
+	}else if(inObject(player->rightWeapon->collisionPoint)){
+		if(!isHit){
+			isHit = true;
+			hit(player->rightWeapon->damage);
+		}
+		std::cout << "HIT2";
+	}else{
+		isHit = false;
+	}
 }
 }

+ 4 - 0
Enemy.h

@@ -21,11 +21,15 @@ public:
 	int xp;
 	int xp;
 	bool attack;
 	bool attack;
 
 
+	bool isHit;
+
 	void update(float);
 	void update(float);
 	void draw();
 	void draw();
 
 
 	void inEyeSight(Vec3f &);
 	void inEyeSight(Vec3f &);
 	void collide(const Entity *entity);
 	void collide(const Entity *entity);
+	void hit(int damage);
+	bool isDead(void);
 private:
 private:
 	int hit_sound_id;
 	int hit_sound_id;
 };
 };

+ 0 - 71
LoadingScreen.cpp

@@ -1,71 +0,0 @@
-
-#include "stb_image.h"
-#include "LoadingScreen.h"
-
-#include "CrystalPoint.h"
-#include "Util.h"
-#include <ostream>
-
-LoadingScreen::LoadingScreen()
-{
-	points = 0;
-}
-
-
-LoadingScreen::~LoadingScreen()
-{
-}
-
-void LoadingScreen::draw()
-{
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-	
-	glDisable(GL_LIGHTING);
-	glDisable(GL_DEPTH_TEST);
-	glDisable(GL_COLOR_MATERIAL);
-	glEnable(GL_TEXTURE_2D);
-	
-		
-	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-	glBindTexture(GL_TEXTURE_2D, textureId);
-	glBegin(GL_QUADS);
-	glTexCoord2f(0, 1);
-	glVertex2f(0, 0);
-	glTexCoord2f(0, 0);
-	glVertex2f(0, CrystalPoint::height);
-	glTexCoord2f(1, 0);
-	glVertex2f(CrystalPoint::width, CrystalPoint::height);
-	glTexCoord2f(1, 1);
-	glVertex2f(CrystalPoint::width, 0);	
-	glEnd();
-	
-	/*glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
-	
-	std::ostringstream oss;
-
-	oss << loading << points << std::endl;
-
-	Util::glutBitmapString(oss.str(),
-		CrystalPoint::width / 2 - Util::glutTextWidth(oss.str()),
-		CrystalPoint::height / 2 - 7);*/
-	
-	glDisable(GL_TEXTURE_2D);
-	glEnable(GL_LIGHTING);
-	glEnable(GL_DEPTH_TEST);
-	glutSwapBuffers();
-}
-
-void LoadingScreen::rise()
-{
-	points++;
-	draw();
-}
-
-void LoadingScreen::setTexture(const std::string filename)
-{
-	textureId = Util::loadTexture(filename);
-}

+ 0 - 22
LoadingScreen.h

@@ -1,22 +0,0 @@
-#pragma once
-#include <string>
-#include <GL\freeglut.h>
-
-class LoadingScreen
-{
-public:
-	LoadingScreen();
-	~LoadingScreen();
-
-	void draw();
-	void rise();
-	int points;
-
-	GLuint textureId;
-	void setTexture(const std::string fileName);
-
-private:
-	const std::string loading = "Loaded: ";
-
-};
-

+ 3 - 3
Main.cpp

@@ -61,6 +61,7 @@ int main(int argc, char* argv[])
 		if (button == GLUT_LEFT_BUTTON)
 		if (button == GLUT_LEFT_BUTTON)
 			Cursor::getInstance()->state = state;
 			Cursor::getInstance()->state = state;
 
 
+
 			//std::cout << "Left button is down" << std::endl;
 			//std::cout << "Left button is down" << std::endl;
 	};
 	};
 
 
@@ -79,9 +80,8 @@ void configureOpenGL()
 {
 {
 	//Init window and glut display mode
 	//Init window and glut display mode
 	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
 	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
-	glutInitWindowSize(1440, 900);	
-	//glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
-
+	glutInitWindowSize(1440, 900);
+	//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
 	glutCreateWindow("Crystal Point");	
 	glutCreateWindow("Crystal Point");	
 	//glutFullScreen();
 	//glutFullScreen();
 
 

+ 12 - 2
Player.cpp

@@ -18,6 +18,7 @@ Player::Player()
 	maxXp = 100;
 	maxXp = 100;
 	level = 1;
 	level = 1;
 	crystals = 0;
 	crystals = 0;
+    hit = false;
 
 
 	loadWeapons();
 	loadWeapons();
 
 
@@ -150,6 +151,7 @@ void Player::loadWeapons()
 		std::string name = w["name"].asString();
 		std::string name = w["name"].asString();
 		std::string fileN = w["file"].asString();
 		std::string fileN = w["file"].asString();
 		float damage = w["damage"].asFloat();
 		float damage = w["damage"].asFloat();
+		float scale = w["scale"].asFloat();
 
 
 		Weapon::Element e = Weapon::FIRE;
 		Weapon::Element e = Weapon::FIRE;
 
 
@@ -174,8 +176,8 @@ void Player::loadWeapons()
 		Vec2f maxRot = Vec2f(w["maxRotation"][0].asFloat(), w["maxRotation"][1].asFloat());
 		Vec2f maxRot = Vec2f(w["maxRotation"][0].asFloat(), w["maxRotation"][1].asFloat());
 		Vec2f minRot = Vec2f(w["minRotation"][0].asFloat(), w["minRotation"][1].asFloat());
 		Vec2f minRot = Vec2f(w["minRotation"][0].asFloat(), w["minRotation"][1].asFloat());
 
 
-		lweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, leftoffset, anchor, maxRot, minRot, collision);
-		rweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, rightoffset, anchor, maxRot, minRot, collision);
+		lweapon = new Weapon(name, damage, e, fileN, scale, position, rotation, leftoffset, anchor, maxRot, minRot, collision);
+		rweapon = new Weapon(name, damage, e, fileN, scale, position, rotation, rightoffset, anchor, maxRot, minRot, collision);
 
 
 		leftweapons.push_back(lweapon);
 		leftweapons.push_back(lweapon);
 		rightweapons.push_back(rweapon);
 		rightweapons.push_back(rweapon);
@@ -191,6 +193,8 @@ void Player::PreviousRightWeapon()
 		currentrightweapon = (rightweapons.size() > level ? level - 1 : rightweapons.size() - 1);
 		currentrightweapon = (rightweapons.size() > level ? level - 1 : rightweapons.size() - 1);
 
 
 	rightWeapon = rightweapons[currentrightweapon];
 	rightWeapon = rightweapons[currentrightweapon];
+	rightWeapon->move(position);
+	rightWeapon->rotate(rotation);
 }
 }
 void Player::NextRightWeapon(void)
 void Player::NextRightWeapon(void)
 {
 {
@@ -200,6 +204,8 @@ void Player::NextRightWeapon(void)
 		currentrightweapon = 0;
 		currentrightweapon = 0;
 
 
 	rightWeapon = rightweapons[currentrightweapon];
 	rightWeapon = rightweapons[currentrightweapon];
+	rightWeapon->move(position);
+	rightWeapon->rotate(rotation);
 }
 }
 void Player::PreviousLeftWeapon(void)
 void Player::PreviousLeftWeapon(void)
 {
 {
@@ -209,6 +215,8 @@ void Player::PreviousLeftWeapon(void)
 		currentleftweapon = (leftweapons.size() > level ? level - 1 : leftweapons.size() - 1);
 		currentleftweapon = (leftweapons.size() > level ? level - 1 : leftweapons.size() - 1);
 
 
 	leftWeapon = leftweapons[currentleftweapon];
 	leftWeapon = leftweapons[currentleftweapon];
+	leftWeapon->move(position);
+	leftWeapon->rotate(rotation);
 }
 }
 void Player::NextLeftWeapon(void)
 void Player::NextLeftWeapon(void)
 {
 {
@@ -218,4 +226,6 @@ void Player::NextLeftWeapon(void)
 		currentleftweapon = 0;
 		currentleftweapon = 0;
 
 
 	leftWeapon = leftweapons[currentleftweapon];
 	leftWeapon = leftweapons[currentleftweapon];
+	leftWeapon->move(position);
+	leftWeapon->rotate(rotation);
 }
 }

+ 2 - 0
Player.h

@@ -40,6 +40,8 @@ public:
 	int level;
 	int level;
 	int crystals;
 	int crystals;
 
 
+	bool hit;
+
 	float speed;
 	float speed;
 
 
 	void HpUp(int);
 	void HpUp(int);

+ 1 - 0
Vector.cpp

@@ -2,6 +2,7 @@
 #include <cmath>
 #include <cmath>
 #include "Vector.h"
 #include "Vector.h"
 
 
+
 Vec3f::Vec3f(float x, float y, float z)
 Vec3f::Vec3f(float x, float y, float z)
 {
 {
 	this->x = x;
 	this->x = x;

BIN
WAVE/ape.wav


BIN
WAVE/hedge.wav


BIN
WAVE/letsRock.wav


+ 44 - 10
Weapon.cpp

@@ -27,7 +27,8 @@ Weapon::Weapon(std::string name, int damage, Element e, std::string modelFilenam
     this->ankerPoint = ankerPoint;
     this->ankerPoint = ankerPoint;
     this->maxRotation = maxRotation;
     this->maxRotation = maxRotation;
     this->minRotation = minRotation;
     this->minRotation = minRotation;
-	this->collision = collision;
+    this->collisionPoint = collisionPoint;
+
 };
 };
 
 
 Weapon::~Weapon(){
 Weapon::~Weapon(){
@@ -52,11 +53,28 @@ void Weapon::move(Vec3f location){
     position = location;
     position = location;
 }
 }
 
 
+Vec3f multiply(float matrix[16], Vec3f vec)
+{
+    Vec3f result;
+
+    for(int i = 0; i < 4; i++)
+    {
+        for(int p = 0; p < 4; p++)
+        {
+            result[i] += matrix[i * p] * vec[p];
+        }
+    }
+
+    return result;
+}
+
+
 void Weapon::draw(){
 void Weapon::draw(){
     if (weaponmodel != nullptr)
     if (weaponmodel != nullptr)
     {
     {
         glPushMatrix();
         glPushMatrix();
 
 
+
         //Player position and rotation
         //Player position and rotation
         glTranslatef(position.x, position.y, position.z);
         glTranslatef(position.x, position.y, position.z);
         glRotatef(rotation.x, 1, 0, 0);
         glRotatef(rotation.x, 1, 0, 0);
@@ -66,28 +84,44 @@ void Weapon::draw(){
         //offset from player
         //offset from player
         glTranslatef(offsetPlayer.x, offsetPlayer.y, offsetPlayer.z);
         glTranslatef(offsetPlayer.x, offsetPlayer.y, offsetPlayer.z);
 
 
+        glScalef(scale, scale, scale);
+
         //Rotate weapon itself, from specific anker point
         //Rotate weapon itself, from specific anker point
         glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
         glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
         glRotatef(rotationWeapon.z, 0, 0, 1);
         glRotatef(rotationWeapon.z, 0, 0, 1);
         glRotatef(rotationWeapon.y, 0, 1, 0);
         glRotatef(rotationWeapon.y, 0, 1, 0);
         glRotatef(rotationWeapon.x, 1, 0, 0);
         glRotatef(rotationWeapon.x, 1, 0, 0);
-        glTranslatef(-ankerPoint.x, -ankerPoint.y, -ankerPoint.z);
-
-        glScalef(scale, scale, scale);
-
-        weaponmodel->draw();
-
-        //Test code for finding anker point
+/*
         glColor3ub(255, 255, 0);
         glColor3ub(255, 255, 0);
-        glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
         glBegin(GL_LINES);
         glBegin(GL_LINES);
         glVertex2f(0, 4);
         glVertex2f(0, 4);
         glVertex2f(0, -4);
         glVertex2f(0, -4);
         glVertex2f(4, 0);
         glVertex2f(4, 0);
         glVertex2f(-4, 0);
         glVertex2f(-4, 0);
-        glEnd();
+        glEnd();*/
+
+        glTranslatef(-ankerPoint.x, -ankerPoint.y, -ankerPoint.z);
+
+        weaponmodel->draw();
+
+        //Test code for finding anchor point
+        glTranslatef(collisionPoint.x, collisionPoint.y, collisionPoint.z);
+
+        float matrix[16];
+        glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
+
+        Vec3f point = multiply(matrix, Vec3f(1,1,1));
+
 
 
         glPopMatrix();
         glPopMatrix();
 
 
+        glPushMatrix();
+
+
+
+        glPopMatrix();
     }
     }
 }
 }
+
+
+

+ 3 - 2
Weapon.h

@@ -16,7 +16,7 @@ public:
     Weapon(std::string name, int damage, Element element, std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
     Weapon(std::string name, int damage, Element element, std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
            Vec3f offsetPlayer, Vec3f ankerPoint,
            Vec3f offsetPlayer, Vec3f ankerPoint,
            Vec2f maxRotation, Vec2f minXRotation,
            Vec2f maxRotation, Vec2f minXRotation,
-		   Vec3f collision);
+		   Vec3f collisionPoint);
     ~Weapon();
     ~Weapon();
 
 
     void draw();
     void draw();
@@ -32,8 +32,9 @@ public:
 
 
     float scale;
     float scale;
     Vec3f position, rotation, rotationWeapon;
     Vec3f position, rotation, rotationWeapon;
-    Vec3f offsetPlayer, ankerPoint, collision;
+    Vec3f offsetPlayer, ankerPoint, collisionPoint;
     Vec2f maxRotation, minRotation;
     Vec2f maxRotation, minRotation;
+
 };
 };
 
 
 
 

+ 13 - 25
World.cpp

@@ -9,16 +9,14 @@
 #include "WorldHandler.h"
 #include "WorldHandler.h"
 
 
 World::World(const std::string &fileName)
 World::World(const std::string &fileName)
-{		
+{
 	nextworld = false;
 	nextworld = false;
 
 
 	//Store player instance
 	//Store player instance
 	player = Player::getInstance();
 	player = Player::getInstance();
-	
 
 
 	//Create the interface
 	//Create the interface
 	interface = new Interface();
 	interface = new Interface();
-	
 
 
 	//Open world json file
 	//Open world json file
 	std::ifstream file(fileName);
 	std::ifstream file(fileName);
@@ -27,7 +25,6 @@ World::World(const std::string &fileName)
 
 
 	json::Value v = json::readJson(file);
 	json::Value v = json::readJson(file);
 	file.close();
 	file.close();
-	
 
 
 	//Check file
 	//Check file
 	if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
 	if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
@@ -42,13 +39,6 @@ World::World(const std::string &fileName)
 		std::cout << "Invalid world file: enemies - " << fileName << "\n";
 		std::cout << "Invalid world file: enemies - " << fileName << "\n";
 	if (v["crystal"].isNull())
 	if (v["crystal"].isNull())
 		std::cout << "Invalid world file: crystals - " << fileName << "\n";
 		std::cout << "Invalid world file: crystals - " << fileName << "\n";
-	
-
-	if (!v["world"]["loadingscreen"].isNull())
-	{
-		ls.setTexture(v["world"]["loadingscreen"].asString());
-		ls.draw();
-	}	
 
 
 	//Load object templates
 	//Load object templates
 	for (auto objt : v["world"]["object-templates"])
 	for (auto objt : v["world"]["object-templates"])
@@ -59,28 +49,23 @@ World::World(const std::string &fileName)
 			cancollide = objt["collision"].asBool();
 			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)));
 		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
 	//Generate heightmap for this world
 	heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
 	heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
-	
 
 
 	//Load skybox
 	//Load skybox
 	skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
 	skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
 	skybox->init();
 	skybox->init();
-	
 
 
 	//Map different texture to heightmap if available
 	//Map different texture to heightmap if available
 	if(!v["world"]["texture"].isNull())
 	if(!v["world"]["texture"].isNull())
 		heightmap->SetTexture(v["world"]["texture"].asString());
 		heightmap->SetTexture(v["world"]["texture"].asString());
-	
 
 
 	//Set player starting position
 	//Set player starting position
 	player->position.x = v["player"]["startposition"][0].asFloat();
 	player->position.x = v["player"]["startposition"][0].asFloat();
 	player->position.z = v["player"]["startposition"][2].asFloat();
 	player->position.z = v["player"]["startposition"][2].asFloat();
 	player->position.y = heightmap->GetHeight(player->position.x, player->position.z);
 	player->position.y = heightmap->GetHeight(player->position.x, player->position.z);
-	
 
 
 	//Load and place objects into world
 	//Load and place objects into world
 	for (auto object : v["objects"])
 	for (auto object : v["objects"])
@@ -113,7 +98,6 @@ World::World(const std::string &fileName)
 		position.y = getHeight(position.x, position.z);
 		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));
-		
 	}
 	}
 
 
 	maxEnemies = 0;
 	maxEnemies = 0;
@@ -156,7 +140,6 @@ World::World(const std::string &fileName)
 
 
 		maxEnemies++;
 		maxEnemies++;
 		enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale));
 		enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale));
-		
 	}
 	}
 	maxCrystals = 0;
 	maxCrystals = 0;
 	if (!v["crystal"].isNull())
 	if (!v["crystal"].isNull())
@@ -200,7 +183,6 @@ World::World(const std::string &fileName)
 				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;
 			interface->maxCrystals = maxCrystals;
 		}
 		}
@@ -210,7 +192,6 @@ World::World(const std::string &fileName)
 	{
 	{
 		sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
 		sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
 		music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
 		music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
-		
 	}
 	}
 
 
 	if (!v["portal"].isNull())
 	if (!v["portal"].isNull())
@@ -236,7 +217,6 @@ World::World(const std::string &fileName)
 		portal = new Portal(v["portal"]["file"], pos, rot, scale);
 		portal = new Portal(v["portal"]["file"], pos, rot, scale);
 		entities.push_back(portal);
 		entities.push_back(portal);
 		portal->maxCrystals = maxCrystals;
 		portal->maxCrystals = maxCrystals;
-		
 	}
 	}
 }
 }
 
 
@@ -269,6 +249,7 @@ float World::getHeight(float x, float y)
 void World::draw()
 void World::draw()
 {
 {
 
 
+	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);
@@ -323,11 +304,14 @@ void World::update(float elapsedTime)
 
 
 		//Al deze code zou in enemy moeten staan
 		//Al deze code zou in enemy moeten staan
 		enemy->inEyeSight(player->position);
 		enemy->inEyeSight(player->position);
-		
+
 
 
 		enemy->update(elapsedTime);
 		enemy->update(elapsedTime);
 		if (enemy->hasTarget)
 		if (enemy->hasTarget)
 		{
 		{
+            if(player->hit)
+                enemy->hit(player->leftWeapon->damage);
+
 			for (auto e : entities)
 			for (auto e : entities)
 			{
 			{
 				if (e->canCollide && e->inObject(enemy->position))
 				if (e->canCollide && e->inObject(enemy->position))
@@ -336,10 +320,12 @@ void World::update(float elapsedTime)
 					break;
 					break;
 				}
 				}
 			}
 			}
-		}
 
 
 		if (enemy->attack)
 		if (enemy->attack)
 		{			
 		{			
+                player->HpDown(enemy->damage / 4);
+			}
+		}
 			remove = true;
 			remove = true;
 			continue;
 			continue;
 		}
 		}
@@ -351,9 +337,8 @@ void World::update(float elapsedTime)
 
 
 	if (remove)
 	if (remove)
 	{
 	{
-		player->XpUp(enemies[count]->xp);
 		delete enemies[count];
 		delete enemies[count];
-		
+		player->XpUp(enemies[count]->xp*2);
 		enemies.erase(enemies.begin() + count);
 		enemies.erase(enemies.begin() + count);
 		player->HpUp(10);		
 		player->HpUp(10);		
 	}
 	}
@@ -365,6 +350,8 @@ void World::update(float elapsedTime)
 		if (portal->enter(elapsedTime))
 		if (portal->enter(elapsedTime))
 			nextworld = true;
 			nextworld = true;
 	}
 	}
+
+    player->hit = false;
 		
 		
 }
 }
 
 
@@ -385,3 +372,4 @@ bool World::isPlayerPositionValid()
 	}
 	}
 	return true;
 	return true;
 }
 }
+

+ 0 - 3
World.h

@@ -10,7 +10,6 @@
 #include "Skybox.h"
 #include "Skybox.h"
 #include "CrystalPoint.h"
 #include "CrystalPoint.h"
 #include "Portal.h"
 #include "Portal.h"
-#include "LoadingScreen.h"
 
 
 class Entity;
 class Entity;
 
 
@@ -33,8 +32,6 @@ private:
 	std::vector<Entity*> entities;
 	std::vector<Entity*> entities;
 	std::vector<Enemy*> enemies;
 	std::vector<Enemy*> enemies;
 	//std::vector<Crystal*> crystals;
 	//std::vector<Crystal*> crystals;
-
-	LoadingScreen ls;
 public:
 public:
 	World(const std::string &fileName);
 	World(const std::string &fileName);
 	~World();
 	~World();

+ 6 - 4
weapons.json

@@ -10,12 +10,13 @@
       "collision": [ 0, 0, 0 ],
       "collision": [ 0, 0, 0 ],
       "maxRotation": [ 170, 70 ],
       "maxRotation": [ 170, 70 ],
       "minRotation": [ 20, -80 ],
       "minRotation": [ 20, -80 ],
+      "scale": 0.3,
 
 
       "left": {
       "left": {
-        "offset": [ 4.5, -8, -1 ]
+        "offset": [ 1.5, -2.6, 0 ]
       },
       },
       "right": {
       "right": {
-        "offset": [ 0.5, -8, -1 ]
+        "offset": [ -0.1, -2.6, 0 ]
       }
       }
     },
     },
     {
     {
@@ -28,12 +29,13 @@
       "collision": [ 0, 0, 0 ],
       "collision": [ 0, 0, 0 ],
       "maxRotation": [ 170, 70 ],
       "maxRotation": [ 170, 70 ],
       "minRotation": [ 20, -80 ],
       "minRotation": [ 20, -80 ],
+      "scale": 0.3,
 
 
       "left": {
       "left": {
-        "offset": [ 4.5, -8, -1 ]
+        "offset": [ 1.5, -2.6, 0 ]
       },
       },
       "right": {
       "right": {
-        "offset": [ 0.5, -8, -1 ]
+        "offset": [ -0.1, -2.6, 0 ]
       }
       }
     }
     }
   ]
   ]

BIN
worlds/loadingScreen_picture.png


+ 0 - 1
worlds/rock.json

@@ -2,7 +2,6 @@
   "world": {
   "world": {
     "heightmap": "worlds/rockHeightmap.png",
     "heightmap": "worlds/rockHeightmap.png",
     "texture": "worlds/rockStone.png",
     "texture": "worlds/rockStone.png",
-    "loadingscreen": "worlds/loadingScreen_picture.png",
 	"skybox": "skyboxes/water/",
 	"skybox": "skyboxes/water/",
 	"music": "WAVE/world1.wav",
 	"music": "WAVE/world1.wav",
     "object-templates": [
     "object-templates": [

+ 1 - 2
worlds/small.json

@@ -1,7 +1,6 @@
 {
 {
   "world": {
   "world": {
     "heightmap": "worlds/small.png",
     "heightmap": "worlds/small.png",
-    "loadingscreen": "worlds/loadingScreen_picture.png",
     "skybox": "skyboxes/water/",
     "skybox": "skyboxes/water/",
     "object-templates": [
     "object-templates": [
       {
       {
@@ -13,7 +12,7 @@
 	"music": "WAVE/world1.wav"
 	"music": "WAVE/world1.wav"
   },
   },
   "player": {
   "player": {
-    "startposition": [ 20, 0, 20 ]
+    "startposition": [ -10, -10, -10 ]
   },
   },
   "objects": [ ],
   "objects": [ ],
   "portal": {     
   "portal": {