Parcourir la source

Bugfixes, added sound to portal and enemy in JSON

Kenneth van Ewijk il y a 9 ans
Parent
commit
8700aa90af
18 fichiers modifiés avec 98 ajouts et 22 suppressions
  1. 4 5
      CrystalPoint.cpp
  2. 1 0
      CrystalPoint.vcxproj
  3. 3 0
      CrystalPoint.vcxproj.filters
  4. 5 2
      Enemy.cpp
  5. 1 1
      Enemy.h
  6. 1 1
      Main.cpp
  7. 2 4
      Model.cpp
  8. 1 1
      Model.h
  9. 28 0
      Portal.cpp
  10. 8 0
      Portal.h
  11. 11 0
      Sound.cpp
  12. 1 0
      Sound.h
  13. BIN
      WAVE/portal.wav
  14. 23 4
      World.cpp
  15. 2 0
      World.h
  16. 2 1
      worlds/rock.json
  17. 4 2
      worlds/small.json
  18. 1 1
      worlds/worlds.json

+ 4 - 5
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();
-
 	glutSwapBuffers();
 }
 
@@ -64,14 +62,15 @@ 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])
 			worldhandler->PreviousWorld();
 		if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
 			worldhandler->NextWorld();
-		if (keyboardState.keys[27])
-			state = false;
 
 		Player* player = Player::getInstance();
 

+ 1 - 0
CrystalPoint.vcxproj

@@ -211,6 +211,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

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

+ 5 - 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);
@@ -18,7 +19,7 @@ Enemy::Enemy(const std::string &fileName,
 	speed = 1;
 	radius = 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;
 }
@@ -28,6 +29,8 @@ Enemy::~Enemy()
 {
 	if (model)
 		Model::unload(model);
+
+	delete music;
 }
 
 void Enemy::draw()

+ 1 - 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;

+ 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

@@ -369,6 +369,7 @@ void Model::unload(Model* model)
 			{
 				delete m.second.first;
 				cache.erase(cache.find(m.first));
+				break;
 			}
 
 		}
@@ -377,8 +378,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);

+ 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;

BIN
WAVE/portal.wav


+ 23 - 4
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();
@@ -257,6 +266,12 @@ void World::draw()
 
 void World::update(float elapsedTime)
 {
+	if (nextworld)
+	{
+		WorldHandler::getInstance()->NextWorld();
+		return;
+	}
+
 	music->SetPos(player->position, Vec3f());
 
 	if (music->IsPlaying() ==  false)
@@ -306,7 +321,11 @@ void World::update(float elapsedTime)
 	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"
   ]