浏览代码

Merge branch 'developer' into feature/Controller

# Conflicts:
#	CrystalPoint.cpp
#	Player.cpp
Kenneth van Ewijk 9 年之前
父节点
当前提交
942b068851
共有 21 个文件被更改,包括 174 次插入30 次删除
  1. 13 3
      CrystalPoint.cpp
  2. 1 0
      CrystalPoint.vcxproj
  3. 3 0
      CrystalPoint.vcxproj.filters
  4. 7 2
      Enemy.cpp
  5. 2 1
      Enemy.h
  6. 4 4
      Interface.cpp
  7. 1 1
      Main.cpp
  8. 2 4
      Model.cpp
  9. 1 1
      Model.h
  10. 48 3
      Player.cpp
  11. 7 2
      Player.h
  12. 28 0
      Portal.cpp
  13. 8 0
      Portal.h
  14. 11 0
      Sound.cpp
  15. 1 0
      Sound.h
  16. 二进制
      WAVE/portal.wav
  17. 28 5
      World.cpp
  18. 2 0
      World.h
  19. 2 1
      worlds/rock.json
  20. 4 2
      worlds/small.json
  21. 1 1
      worlds/worlds.json

+ 13 - 3
CrystalPoint.cpp

@@ -17,8 +17,6 @@ int CrystalPoint::height = 0;
 SoundSystem CrystalPoint::sound_system;
 bool state = false;
 
-
-
 void CrystalPoint::init()
 {
 	player = Player::getInstance();
@@ -51,9 +49,9 @@ void CrystalPoint::draw()
 
 	
 	worldhandler->draw();
+	
 	if(!state)
 		menu->draw();
-	//cursor->draw();
 
 	glutSwapBuffers();
 }
@@ -65,6 +63,9 @@ void CrystalPoint::update()
 	float deltaTime = frameTime - lastFrameTime;
 	lastFrameTime = frameTime;
 
+	if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
+		state = !state;
+		
 	if (state)
 	{
 		if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
@@ -73,9 +74,18 @@ void CrystalPoint::update()
 			worldhandler->NextWorld();
 		if (keyboardState.keys[27])
 			state = false;
+		
 
 		Player* player = Player::getInstance();
 
+		//testing code
+		if (keyboardState.keys['u'])
+			player->HpUp(1);
+		if (keyboardState.keys['i'])
+			player->HpDown(1);
+		if (keyboardState.keys['o'])
+			player->XpUp(1);
+
 		player->rotation.y += mouseOffset.x / 10.0f;
 		player->rotation.x += mouseOffset.y / 10.0f;
 

+ 1 - 0
CrystalPoint.vcxproj

@@ -214,6 +214,7 @@
   <ItemGroup>
     <None Include="worlds\fire.json" />
     <None Include="worlds\ice.json" />
+    <None Include="worlds\rock.json" />
     <None Include="worlds\small.json" />
     <None Include="worlds\worlds.json" />
   </ItemGroup>

+ 3 - 0
CrystalPoint.vcxproj.filters

@@ -205,6 +205,9 @@
     <None Include="worlds\small.json">
       <Filter>Source Files\json</Filter>
     </None>
+    <None Include="worlds\rock.json">
+      <Filter>Source Files\json</Filter>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Media Include="WAVE\Sound.wav">

+ 7 - 2
Enemy.cpp

@@ -5,8 +5,9 @@
 #include <iostream>
 
 Enemy::Enemy(const std::string &fileName,
+	const std::string &fileMusic,
 	const Vec3f &position,
-	Vec3f &rotation,
+	const Vec3f &rotation,
 	const float &scale)
 {
 	model = Model::load(fileName);
@@ -17,8 +18,9 @@ Enemy::Enemy(const std::string &fileName,
 	target = position;
 	speed = 1;
 	radius = 10;
+	xp = 10;
 	hasTarget = false;
-	hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false);
+	hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
 	music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
 	attack = false;
 }
@@ -26,8 +28,11 @@ Enemy::Enemy(const std::string &fileName,
 
 Enemy::~Enemy()
 {
+	
 	if (model)
 		Model::unload(model);
+
+	delete music;
 }
 
 void Enemy::draw()

+ 2 - 1
Enemy.h

@@ -8,7 +8,7 @@
 class Enemy : public Entity
 {
 public:
-	Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale);
+	Enemy(const std::string &fileName, const std::string &fileMusic, const Vec3f &position, const Vec3f &rotation, const float &scale);
 	~Enemy();
 
 	Sound* music;
@@ -16,6 +16,7 @@ public:
 	bool hasTarget;
 	Vec3f target;
 	float speed,radius;
+	int xp;
 	bool attack;
 
 	void update(float);

+ 4 - 4
Interface.cpp

@@ -60,8 +60,8 @@ void Interface::draw()
 	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);
+	glVertex2f(250 + (player->health / player->maxHp * 500), 965);
+	glVertex2f(250 + (player->health / player->maxHp * 500), 980);
 	glEnd();
 
 	//XP bar
@@ -79,8 +79,8 @@ void Interface::draw()
 	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);
+	glVertex2f(250 + (player->xp / player->maxXp * 500), 935);
+	glVertex2f(250 + (player->xp / player->maxXp * 500), 950);
 	glEnd();
 
 	//Text: level

+ 1 - 1
Main.cpp

@@ -82,7 +82,7 @@ void configureOpenGL()
 	glutInitWindowSize(800, 600);
 	//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
 	glutCreateWindow("Crystal Point");	
-	glutFullScreen();
+	//glutFullScreen();
 
 
 	//Depth testing

+ 2 - 4
Model.cpp

@@ -370,6 +370,7 @@ void Model::unload(Model* model)
 			{
 				delete m.second.first;
 				cache.erase(cache.find(m.first));
+				break;
 			}
 
 		}
@@ -378,8 +379,5 @@ void Model::unload(Model* model)
 
 Model::~Model(void)
 {
-	for (auto m : cache)
-	{
-		delete m.second.first;
-	}
+
 }

+ 1 - 1
Model.h

@@ -70,7 +70,7 @@ private:
 	Model(std::string filename);
 	~Model(void);
 
-public:
+	public:
 
 	static std::map<std::string, std::pair<Model*, int> > cache;
 	static Model* load(const std::string &fileName);

+ 48 - 3
Player.cpp

@@ -8,9 +8,11 @@ Player* Player::instance = NULL;
 Player::Player()
 {
 	speed = 10;
-	health = 50;
-	xp = 75;
-	level = 10;
+	maxHp = 100;
+	health = maxHp;
+	xp = 0;
+	maxXp = 100;
+	level = 1;
 	crystals = 0;
 
 	leftWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(4.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
@@ -70,4 +72,47 @@ void Player::setPosition(float angle, float fac, bool height)
 void Player::draw() {
 	leftWeapon->draw();
 	rightWeapon->draw();
+}
+
+void Player::HpDown(int damage)
+{
+	int newHealth = health - damage;
+	if (newHealth <= 0)
+	{
+		exit(0);
+	}
+	health = newHealth;
+}
+
+void Player::HpUp(int hp)
+{
+	if (health != maxHp)
+	{
+		int newHealth = health + hp;
+		if (newHealth >= maxHp)
+		{
+			newHealth = maxHp;
+		}
+		health = newHealth;
+	}	
+}
+
+void Player::XpUp(int xpUp)
+{
+	float newXp = xp + xpUp;
+	if (newXp >= maxXp)
+	{
+		newXp -= maxXp;		
+		levelUp();
+	}
+	xp = newXp;
+}
+
+
+void Player::levelUp()
+{
+	level++;
+	maxXp += 50;
+	maxHp += 10;
+	health = maxHp;
 }

+ 7 - 2
Player.h

@@ -6,6 +6,7 @@ class Player
 {
 private:
 	static Player* instance;
+	void levelUp();
 public:
 	Player();
 	~Player();
@@ -23,10 +24,14 @@ public:
 	Weapon* leftWeapon;
 	Weapon* rightWeapon;
 
-	float health;
-	float xp;
+	float health, maxHp;
+	float xp, maxXp;
 	int level;
 	int crystals;
 
 	float speed;
+
+	void HpUp(int);
+	void HpDown(int);
+	void XpUp(int);
 };

+ 28 - 0
Portal.cpp

@@ -15,6 +15,13 @@ Portal::Portal(const std::string &fileName,
 	this->scale = scale;
 	this->canCollide = true;
 
+	started = false;
+	delay = 0;
+
+	sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/portal.wav", false);
+	music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
+	music->SetPos(position, Vec3f());
+
 	mayEnter = false;
 	maxCrystals = 0;
 }
@@ -22,6 +29,8 @@ Portal::Portal(const std::string &fileName,
 
 Portal::~Portal()
 {
+//	Model::unload(model);
+//	delete music;
 }
 
 void Portal::collide()
@@ -32,3 +41,22 @@ void Portal::collide()
 		mayEnter = true;
 	}
 }
+
+bool Portal::enter(float deltaTime)
+{
+	if (delay > 3 && started)
+	{
+		delete music;
+		delay = 0;
+		return true;
+	}
+
+	if (delay == 0 && !started)
+	{
+		music->Play();
+		started = true;
+	}
+
+	delay += deltaTime;
+	return false;
+}

+ 8 - 0
Portal.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "Entity.h"
 #include <string>
+#include "CrystalPoint.h"
 
 class Portal :
 	public Entity
@@ -12,8 +13,15 @@ public:
 		const float &scale);
 	~Portal();
 
+	bool enter(float deltaTime);
+
 	void collide();
 	int maxCrystals;
 	bool mayEnter;
+private:
+	int sound_id;
+	Sound* music;
+	bool started;
+	float delay;
 };
 

+ 11 - 0
Sound.cpp

@@ -154,3 +154,14 @@ bool Sound::IsPlaying()
 	return (state == AL_PLAYING);
 }
 
+bool Sound::IsStopped()
+{
+	ALenum state;
+
+	alGetSourcei(source_id, AL_SOURCE_STATE, &state);
+
+	std::cout << "MUSIC STATE: " << state << std::endl;
+
+	return (state == AL_STOPPED);
+}
+

+ 1 - 0
Sound.h

@@ -14,6 +14,7 @@ public:
 	void Pause();
 	void Stop();
 	bool IsPlaying();
+	bool IsStopped();
 
 private:
 	unsigned int buffer_id;

二进制
WAVE/portal.wav


+ 28 - 5
World.cpp

@@ -11,6 +11,8 @@
 World::World(const std::string &fileName):
 	music_id(-1)
 {
+	nextworld = false;
+
 	//Store player instance
 	player = Player::getInstance();
 
@@ -121,12 +123,16 @@ World::World(const std::string &fileName):
 		if (e["file"].isNull())
 			std::cout << "Invalid world file: enemies file - " << fileName << "\n";
 
+		//Music
+		if (e["music"].isNull())
+			std::cout << "Invalid world file: enemies music - " << fileName << "\n";
+
 		//Create
 		Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
 		position.y = getHeight(position.x, position.z) + 2.0f;
 
 		maxEnemies++;
-		enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
+		enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), position, rotation, scale));
 	}
 	maxCrystals = 0;
 	if (!v["crystal"].isNull())
@@ -213,7 +219,7 @@ World::~World()
 	delete heightmap;
 	music->Stop();
 	delete music;
-	delete skybox;
+	delete skybox;	
 	delete portal;
 }
 
@@ -239,7 +245,10 @@ void World::draw()
 
 	float lightPosition[4] = { 0, 2, 1, 0 };
 	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
-	float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
+
+	GLfloat lightAmbient[] = { 0.05, 0.05, 0.05, 0 };
+	GLfloat light_diffuse[] = { 0.9, 0.9, 0.9, 0 };
+	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
 	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
 
 	skybox->draw();
@@ -260,6 +269,12 @@ void World::draw()
 
 void World::update(float elapsedTime)
 {
+	if (nextworld)
+	{
+		WorldHandler::getInstance()->NextWorld();
+		return;
+	}
+
 	music->SetPos(player->position, Vec3f());
 
 	if (music->IsPlaying() ==  false)
@@ -303,13 +318,21 @@ void World::update(float elapsedTime)
 			count++;
 	}
 
-	if(remove)
+	if (remove)
+	{
+		player->XpUp(enemies[count]->xp);
 		enemies.erase(enemies.begin() + count);
+		player->HpUp(10);		
+	}
 
 	skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
 
 	if (portal->mayEnter)
-		WorldHandler::getInstance()->NextWorld();
+	{
+		if (portal->enter(elapsedTime))
+			nextworld = true;
+	}
+		
 }
 
 void World::addLevelObject(LevelObject* obj)

+ 2 - 0
World.h

@@ -24,6 +24,8 @@ private:
 	Interface* interface;
 	Skybox* skybox;
 	Portal* portal;
+
+	bool nextworld;
 	
 	int music_id,maxCrystals,maxEnemies;
 

+ 2 - 1
worlds/rock.json

@@ -94,7 +94,8 @@
   {
       "file": "models/squid/Blooper.obj",
       "pos": [ 20, 5, 10 ],
-      "scale": 0.01
+      "scale": 0.01,
+      "music": "WAVE/enemy.wav"
   }],
   "crystal": {
     "full texture": "models/crystal/Crystal.obj",

+ 4 - 2
worlds/small.json

@@ -23,12 +23,14 @@
     {
       "file": "models/squid/Blooper.obj",
       "pos": [ 20, 5, 10 ],
-      "scale": 0.01
+      "scale": 0.01,
+      "music": "WAVE/enemy.wav"
     },
     {
       "file": "models/squid/Blooper.obj",
       "pos": [ 30, 10, 10 ],
-      "scale": 0.01
+      "scale": 0.01,
+      "music": "WAVE/enemy.wav"
   }],
   "crystal": {
     "full texture": "models/crystal/Crystal.obj",

+ 1 - 1
worlds/worlds.json

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