diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 5c1cdd7..2e5db77 100644 --- a/CrystalPoint.cpp +++ b/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,6 +62,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]) diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj index e6702fa..b34fc2c 100644 --- a/CrystalPoint.vcxproj +++ b/CrystalPoint.vcxproj @@ -211,6 +211,7 @@ + diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters index 8a2269b..717aedc 100644 --- a/CrystalPoint.vcxproj.filters +++ b/CrystalPoint.vcxproj.filters @@ -199,6 +199,9 @@ Source Files\json + + Source Files\json + diff --git a/Enemy.cpp b/Enemy.cpp index 2367b41..1f29341 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -5,8 +5,9 @@ #include 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); @@ -19,7 +20,7 @@ Enemy::Enemy(const std::string &fileName, 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; } @@ -30,6 +31,8 @@ Enemy::~Enemy() if (model) Model::unload(model); + + delete music; } void Enemy::draw() diff --git a/Enemy.h b/Enemy.h index cf2294d..61ab4f4 100644 --- a/Enemy.h +++ b/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; diff --git a/Main.cpp b/Main.cpp index f593110..c119e64 100644 --- a/Main.cpp +++ b/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 diff --git a/Model.cpp b/Model.cpp index 8fa61d5..ffd1b00 100644 --- a/Model.cpp +++ b/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; - } + } \ No newline at end of file diff --git a/Model.h b/Model.h index e2778c3..4de546a 100644 --- a/Model.h +++ b/Model.h @@ -70,7 +70,7 @@ private: Model(std::string filename); ~Model(void); -public: + public: static std::map > cache; static Model* load(const std::string &fileName); diff --git a/Portal.cpp b/Portal.cpp index 3f689fe..fcd2f07 100644 --- a/Portal.cpp +++ b/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; +} diff --git a/Portal.h b/Portal.h index 5f5c330..370e8f1 100644 --- a/Portal.h +++ b/Portal.h @@ -1,6 +1,7 @@ #pragma once #include "Entity.h" #include +#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; }; diff --git a/Sound.cpp b/Sound.cpp index a3cc983..a387d11 100644 --- a/Sound.cpp +++ b/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); +} + diff --git a/Sound.h b/Sound.h index 02fe227..633ec42 100644 --- a/Sound.h +++ b/Sound.h @@ -14,6 +14,7 @@ public: void Pause(); void Stop(); bool IsPlaying(); + bool IsStopped(); private: unsigned int buffer_id; diff --git a/WAVE/portal.wav b/WAVE/portal.wav new file mode 100644 index 0000000..b5d2cec Binary files /dev/null and b/WAVE/portal.wav differ diff --git a/World.cpp b/World.cpp index 2617de1..b45b0a0 100644 --- a/World.cpp +++ b/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) @@ -310,7 +325,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) diff --git a/World.h b/World.h index a33385f..523c5c1 100644 --- a/World.h +++ b/World.h @@ -24,6 +24,8 @@ private: Interface* interface; Skybox* skybox; Portal* portal; + + bool nextworld; int music_id,maxCrystals,maxEnemies; diff --git a/worlds/rock.json b/worlds/rock.json index 08d3311..a62b3c0 100644 --- a/worlds/rock.json +++ b/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", diff --git a/worlds/small.json b/worlds/small.json index 606c410..fbec10a 100644 --- a/worlds/small.json +++ b/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", diff --git a/worlds/worlds.json b/worlds/worlds.json index e06bfa5..d1e8428 100644 --- a/worlds/worlds.json +++ b/worlds/worlds.json @@ -1,7 +1,7 @@ { "worlds": [ "worlds/small.json", - "worlds/rock.json", + "worlds/rock.json", "worlds/ice.json", "worlds/fire.json" ]