diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp
index a22821e..8e9c54b 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();
- //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;
diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj
index 28dc29f..be3dfa5 100644
--- a/CrystalPoint.vcxproj
+++ b/CrystalPoint.vcxproj
@@ -214,6 +214,7 @@
+
diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters
index 2811cbc..b98b867 100644
--- a/CrystalPoint.vcxproj.filters
+++ b/CrystalPoint.vcxproj.filters
@@ -205,6 +205,9 @@
Source Files\json
+
+ Source Files\json
+
diff --git a/Enemy.cpp b/Enemy.cpp
index 36c3f44..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);
@@ -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()
diff --git a/Enemy.h b/Enemy.h
index d1376c8..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;
@@ -16,6 +16,7 @@ public:
bool hasTarget;
Vec3f target;
float speed,radius;
+ int xp;
bool attack;
void update(float);
diff --git a/Interface.cpp b/Interface.cpp
index 0f912de..db016ee 100644
--- a/Interface.cpp
+++ b/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
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 e2eaf91..f664111 100644
--- a/Model.cpp
+++ b/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;
- }
+
}
\ 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/Player.cpp b/Player.cpp
index b23b7fb..303a9d4 100644
--- a/Player.cpp
+++ b/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;
}
\ No newline at end of file
diff --git a/Player.h b/Player.h
index f2b24f6..8d171d4 100644
--- a/Player.h
+++ b/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);
};
\ No newline at end of file
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 62801ce..d40efd3 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();
@@ -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)
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"
]