Bugfixes, added sound to portal and enemy in JSON
This commit is contained in:
+4
-5
@@ -17,8 +17,6 @@ int CrystalPoint::height = 0;
|
|||||||
SoundSystem CrystalPoint::sound_system;
|
SoundSystem CrystalPoint::sound_system;
|
||||||
bool state = false;
|
bool state = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CrystalPoint::init()
|
void CrystalPoint::init()
|
||||||
{
|
{
|
||||||
player = Player::getInstance();
|
player = Player::getInstance();
|
||||||
@@ -51,9 +49,9 @@ void CrystalPoint::draw()
|
|||||||
|
|
||||||
|
|
||||||
worldhandler->draw();
|
worldhandler->draw();
|
||||||
|
|
||||||
if(!state)
|
if(!state)
|
||||||
menu->draw();
|
menu->draw();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,14 +62,15 @@ void CrystalPoint::update()
|
|||||||
float deltaTime = frameTime - lastFrameTime;
|
float deltaTime = frameTime - lastFrameTime;
|
||||||
lastFrameTime = frameTime;
|
lastFrameTime = frameTime;
|
||||||
|
|
||||||
|
if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
|
||||||
|
state = !state;
|
||||||
|
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
|
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
|
||||||
worldhandler->PreviousWorld();
|
worldhandler->PreviousWorld();
|
||||||
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.keys[27])
|
|
||||||
state = false;
|
|
||||||
|
|
||||||
Player* player = Player::getInstance();
|
Player* player = Player::getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="worlds\fire.json" />
|
<None Include="worlds\fire.json" />
|
||||||
<None Include="worlds\ice.json" />
|
<None Include="worlds\ice.json" />
|
||||||
|
<None Include="worlds\rock.json" />
|
||||||
<None Include="worlds\small.json" />
|
<None Include="worlds\small.json" />
|
||||||
<None Include="worlds\worlds.json" />
|
<None Include="worlds\worlds.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -199,6 +199,9 @@
|
|||||||
<None Include="worlds\small.json">
|
<None Include="worlds\small.json">
|
||||||
<Filter>Source Files\json</Filter>
|
<Filter>Source Files\json</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="worlds\rock.json">
|
||||||
|
<Filter>Source Files\json</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Media Include="WAVE\Sound.wav">
|
<Media Include="WAVE\Sound.wav">
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Enemy::Enemy(const std::string &fileName,
|
Enemy::Enemy(const std::string &fileName,
|
||||||
|
const std::string &fileMusic,
|
||||||
const Vec3f &position,
|
const Vec3f &position,
|
||||||
Vec3f &rotation,
|
const Vec3f &rotation,
|
||||||
const float &scale)
|
const float &scale)
|
||||||
{
|
{
|
||||||
model = Model::load(fileName);
|
model = Model::load(fileName);
|
||||||
@@ -18,7 +19,7 @@ Enemy::Enemy(const std::string &fileName,
|
|||||||
speed = 1;
|
speed = 1;
|
||||||
radius = 10;
|
radius = 10;
|
||||||
hasTarget = false;
|
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);
|
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
||||||
attack = false;
|
attack = false;
|
||||||
}
|
}
|
||||||
@@ -28,6 +29,8 @@ Enemy::~Enemy()
|
|||||||
{
|
{
|
||||||
if (model)
|
if (model)
|
||||||
Model::unload(model);
|
Model::unload(model);
|
||||||
|
|
||||||
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::draw()
|
void Enemy::draw()
|
||||||
|
|||||||
@@ -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);
|
Enemy(const std::string &fileName, const std::string &fileMusic, const Vec3f &position, const Vec3f &rotation, const float &scale);
|
||||||
~Enemy();
|
~Enemy();
|
||||||
|
|
||||||
Sound* music;
|
Sound* music;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void configureOpenGL()
|
|||||||
glutInitWindowSize(800, 600);
|
glutInitWindowSize(800, 600);
|
||||||
//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
|
//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
|
||||||
glutCreateWindow("Crystal Point");
|
glutCreateWindow("Crystal Point");
|
||||||
glutFullScreen();
|
//glutFullScreen();
|
||||||
|
|
||||||
|
|
||||||
//Depth testing
|
//Depth testing
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ void Model::unload(Model* model)
|
|||||||
{
|
{
|
||||||
delete m.second.first;
|
delete m.second.first;
|
||||||
cache.erase(cache.find(m.first));
|
cache.erase(cache.find(m.first));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -377,8 +378,5 @@ void Model::unload(Model* model)
|
|||||||
|
|
||||||
Model::~Model(void)
|
Model::~Model(void)
|
||||||
{
|
{
|
||||||
for (auto m : cache)
|
|
||||||
{
|
|
||||||
delete m.second.first;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ private:
|
|||||||
Model(std::string filename);
|
Model(std::string filename);
|
||||||
~Model(void);
|
~Model(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static std::map<std::string, std::pair<Model*, int> > cache;
|
static std::map<std::string, std::pair<Model*, int> > cache;
|
||||||
static Model* load(const std::string &fileName);
|
static Model* load(const std::string &fileName);
|
||||||
|
|||||||
+28
@@ -15,6 +15,13 @@ Portal::Portal(const std::string &fileName,
|
|||||||
this->scale = scale;
|
this->scale = scale;
|
||||||
this->canCollide = true;
|
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;
|
mayEnter = false;
|
||||||
maxCrystals = 0;
|
maxCrystals = 0;
|
||||||
}
|
}
|
||||||
@@ -22,6 +29,8 @@ Portal::Portal(const std::string &fileName,
|
|||||||
|
|
||||||
Portal::~Portal()
|
Portal::~Portal()
|
||||||
{
|
{
|
||||||
|
// Model::unload(model);
|
||||||
|
// delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Portal::collide()
|
void Portal::collide()
|
||||||
@@ -32,3 +41,22 @@ void Portal::collide()
|
|||||||
mayEnter = true;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "CrystalPoint.h"
|
||||||
|
|
||||||
class Portal :
|
class Portal :
|
||||||
public Entity
|
public Entity
|
||||||
@@ -12,8 +13,15 @@ public:
|
|||||||
const float &scale);
|
const float &scale);
|
||||||
~Portal();
|
~Portal();
|
||||||
|
|
||||||
|
bool enter(float deltaTime);
|
||||||
|
|
||||||
void collide();
|
void collide();
|
||||||
int maxCrystals;
|
int maxCrystals;
|
||||||
bool mayEnter;
|
bool mayEnter;
|
||||||
|
private:
|
||||||
|
int sound_id;
|
||||||
|
Sound* music;
|
||||||
|
bool started;
|
||||||
|
float delay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -154,3 +154,14 @@ bool Sound::IsPlaying()
|
|||||||
return (state == AL_PLAYING);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
void Pause();
|
void Pause();
|
||||||
void Stop();
|
void Stop();
|
||||||
bool IsPlaying();
|
bool IsPlaying();
|
||||||
|
bool IsStopped();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int buffer_id;
|
unsigned int buffer_id;
|
||||||
|
|||||||
Binary file not shown.
@@ -11,6 +11,8 @@
|
|||||||
World::World(const std::string &fileName):
|
World::World(const std::string &fileName):
|
||||||
music_id(-1)
|
music_id(-1)
|
||||||
{
|
{
|
||||||
|
nextworld = false;
|
||||||
|
|
||||||
//Store player instance
|
//Store player instance
|
||||||
player = Player::getInstance();
|
player = Player::getInstance();
|
||||||
|
|
||||||
@@ -121,12 +123,16 @@ World::World(const std::string &fileName):
|
|||||||
if (e["file"].isNull())
|
if (e["file"].isNull())
|
||||||
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
||||||
|
|
||||||
|
//Music
|
||||||
|
if (e["music"].isNull())
|
||||||
|
std::cout << "Invalid world file: enemies music - " << fileName << "\n";
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
||||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
position.y = getHeight(position.x, position.z) + 2.0f;
|
||||||
|
|
||||||
maxEnemies++;
|
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;
|
maxCrystals = 0;
|
||||||
if (!v["crystal"].isNull())
|
if (!v["crystal"].isNull())
|
||||||
@@ -213,7 +219,7 @@ World::~World()
|
|||||||
delete heightmap;
|
delete heightmap;
|
||||||
music->Stop();
|
music->Stop();
|
||||||
delete music;
|
delete music;
|
||||||
delete skybox;
|
delete skybox;
|
||||||
delete portal;
|
delete portal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +245,10 @@ void World::draw()
|
|||||||
|
|
||||||
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.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);
|
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
|
||||||
|
|
||||||
skybox->draw();
|
skybox->draw();
|
||||||
@@ -257,6 +266,12 @@ void World::draw()
|
|||||||
|
|
||||||
void World::update(float elapsedTime)
|
void World::update(float elapsedTime)
|
||||||
{
|
{
|
||||||
|
if (nextworld)
|
||||||
|
{
|
||||||
|
WorldHandler::getInstance()->NextWorld();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
music->SetPos(player->position, Vec3f());
|
music->SetPos(player->position, Vec3f());
|
||||||
|
|
||||||
if (music->IsPlaying() == false)
|
if (music->IsPlaying() == false)
|
||||||
@@ -306,7 +321,11 @@ void World::update(float elapsedTime)
|
|||||||
skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
|
skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
|
||||||
|
|
||||||
if (portal->mayEnter)
|
if (portal->mayEnter)
|
||||||
WorldHandler::getInstance()->NextWorld();
|
{
|
||||||
|
if (portal->enter(elapsedTime))
|
||||||
|
nextworld = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::addLevelObject(LevelObject* obj)
|
void World::addLevelObject(LevelObject* obj)
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ private:
|
|||||||
Interface* interface;
|
Interface* interface;
|
||||||
Skybox* skybox;
|
Skybox* skybox;
|
||||||
Portal* portal;
|
Portal* portal;
|
||||||
|
|
||||||
|
bool nextworld;
|
||||||
|
|
||||||
int music_id,maxCrystals,maxEnemies;
|
int music_id,maxCrystals,maxEnemies;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -94,7 +94,8 @@
|
|||||||
{
|
{
|
||||||
"file": "models/squid/Blooper.obj",
|
"file": "models/squid/Blooper.obj",
|
||||||
"pos": [ 20, 5, 10 ],
|
"pos": [ 20, 5, 10 ],
|
||||||
"scale": 0.01
|
"scale": 0.01,
|
||||||
|
"music": "WAVE/enemy.wav"
|
||||||
}],
|
}],
|
||||||
"crystal": {
|
"crystal": {
|
||||||
"full texture": "models/crystal/Crystal.obj",
|
"full texture": "models/crystal/Crystal.obj",
|
||||||
|
|||||||
+4
-2
@@ -23,12 +23,14 @@
|
|||||||
{
|
{
|
||||||
"file": "models/squid/Blooper.obj",
|
"file": "models/squid/Blooper.obj",
|
||||||
"pos": [ 20, 5, 10 ],
|
"pos": [ 20, 5, 10 ],
|
||||||
"scale": 0.01
|
"scale": 0.01,
|
||||||
|
"music": "WAVE/enemy.wav"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "models/squid/Blooper.obj",
|
"file": "models/squid/Blooper.obj",
|
||||||
"pos": [ 30, 10, 10 ],
|
"pos": [ 30, 10, 10 ],
|
||||||
"scale": 0.01
|
"scale": 0.01,
|
||||||
|
"music": "WAVE/enemy.wav"
|
||||||
}],
|
}],
|
||||||
"crystal": {
|
"crystal": {
|
||||||
"full texture": "models/crystal/Crystal.obj",
|
"full texture": "models/crystal/Crystal.obj",
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"worlds": [
|
"worlds": [
|
||||||
"worlds/small.json",
|
"worlds/small.json",
|
||||||
"worlds/rock.json",
|
"worlds/rock.json",
|
||||||
"worlds/ice.json",
|
"worlds/ice.json",
|
||||||
"worlds/fire.json"
|
"worlds/fire.json"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user