diff --git a/Crystal.cpp b/Crystal.cpp
index b973485..6ced677 100644
--- a/Crystal.cpp
+++ b/Crystal.cpp
@@ -5,10 +5,11 @@
Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale)
{
- this->filled = filled;
- this->empty = empty;
+ this->filled = Model::load(filled);
+ this->empty = Model::load(empty);
+ model = this->filled;
+
- model = Model::load(this->filled);
this->position = position;
this->rotation = rotation;
this->scale = scale;
@@ -20,6 +21,15 @@ Crystal::~Crystal()
{
if (model)
Model::unload(model);
+
+ //if isfilled, means model is model filled, so model empty has to been deleted.
+ //if is not filled, means model is model empty, so model filled has to been deleted.
+ if (isFilled)
+ if(empty)
+ Model::unload(empty);
+ else
+ if(filled)
+ Model::unload(filled);
}
void Crystal::draw()
@@ -33,6 +43,6 @@ void Crystal::collide()
{
Player::getInstance()->crystals++;
isFilled = false;
- model = Model::load(empty);
+ model = empty;
}
}
diff --git a/Crystal.h b/Crystal.h
index 6b8ab1a..1f9a54f 100644
--- a/Crystal.h
+++ b/Crystal.h
@@ -14,6 +14,7 @@ public:
void draw();
void collide();
private:
- std::string filled, empty;
+ Model* filled;
+ Model* empty;
};
diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj
index a14f55a..65167a2 100644
--- a/CrystalPoint.vcxproj
+++ b/CrystalPoint.vcxproj
@@ -165,6 +165,7 @@
+
@@ -186,6 +187,7 @@
+
diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters
index df8bece..b76db86 100644
--- a/CrystalPoint.vcxproj.filters
+++ b/CrystalPoint.vcxproj.filters
@@ -79,10 +79,13 @@
Source Files
- Source Files
+ Source Files
- Source Files
+ Source Files
+
+
+ Source Files
@@ -138,7 +141,7 @@
Header Files
- Header Files
+ Header Files
Header Files
@@ -146,6 +149,9 @@
Header Files
+
+ Header Files
+
diff --git a/Enemy.cpp b/Enemy.cpp
index 5dbf5e4..3c802b2 100644
--- a/Enemy.cpp
+++ b/Enemy.cpp
@@ -20,6 +20,7 @@ Enemy::Enemy(const std::string &fileName,
radius = 10;
hasTarget = false;
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Sound.wav", false);
+ attack = false;
}
@@ -83,6 +84,8 @@ void Enemy::update(float delta)
length = sqrt(dx*dx + dz*dz);
if (length > 1)
{
+ attack = false;
+
dx /= length;
dz /= length;
@@ -92,6 +95,11 @@ void Enemy::update(float delta)
position.x += dx;
position.z += dz;
}
+ else
+ {
+ attack = true;
+ }
+
rotation.y = atan2f(dx, dz) * 180 / M_PI;
}
@@ -101,4 +109,4 @@ void Enemy::update(float delta)
sound->SetPos(position, Vec3f());
sound->Play();
}
-}
+}
\ No newline at end of file
diff --git a/Enemy.h b/Enemy.h
index 94f3a06..4908738 100644
--- a/Enemy.h
+++ b/Enemy.h
@@ -13,6 +13,7 @@ public:
bool hasTarget;
Vec3f target;
float speed,radius;
+ bool attack;
void update(float);
void draw();
diff --git a/Interface.cpp b/Interface.cpp
index c97602a..c5ee6ba 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -14,6 +14,15 @@ Interface::Interface()
crystalWidth = 20;
crystalHeight = 50;
crystalOffset = 5;
+ maxCrystals = 0;
+}
+
+Interface::Interface(int maxCrystal)
+{
+ crystalWidth = 20;
+ crystalHeight = 50;
+ crystalOffset = 5;
+ maxCrystals = maxCrystal;
}
@@ -80,18 +89,23 @@ void Interface::draw()
glColor4f(1.0f, 1.0f, 0.1f, 1.0);
glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
- int cw, ch, offset;
- cw = 20;
- ch = 50;
- offset = 5;
- for (int i = 0; i < player->crystals; i++)
+ for (int i = 0; i < maxCrystals; i++)
{
glBegin(GL_QUADS);
- glColor4f(0, 1.0f, 1.0f, 1.0f);
+
+ if(i < player->crystals)
+ glColor4f(0, 1.0f, 1.0f, 1.0f);
+ else
+ glColor4f(0, 0.4f, 0.4f, 1.0f);
+
glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
- glColor4f(0, 0.8f, 0.8f, 1.0f);
+ if (i < player->crystals)
+ glColor4f(0, 0.7f, 0.7f, 1.0f);
+ else
+ glColor4f(0, 0.2f, 0.2f, 1.0f);
+
glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
glEnd();
diff --git a/Interface.h b/Interface.h
index 434a1b3..9f9e33d 100644
--- a/Interface.h
+++ b/Interface.h
@@ -3,11 +3,13 @@ class Interface
{
public:
Interface();
+ Interface(int);
~Interface();
void draw(void);
void update(float deltaTime);
int crystalWidth, crystalHeight, crystalOffset;
+ int maxCrystals;
};
diff --git a/Main.cpp b/Main.cpp
index 2660258..53ea361 100644
--- a/Main.cpp
+++ b/Main.cpp
@@ -64,7 +64,8 @@ void configureOpenGL()
//Init window and glut display mode
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);
- glutCreateWindow("Crystal Point");
+ //glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
+ glutCreateWindow("Crystal Point");
glutFullScreen();
//Depth testing
diff --git a/Portal.cpp b/Portal.cpp
new file mode 100644
index 0000000..3f689fe
--- /dev/null
+++ b/Portal.cpp
@@ -0,0 +1,34 @@
+#include "Portal.h"
+#include "Model.h"
+#include
+#include "Player.h"
+#include "WorldHandler.h"
+
+Portal::Portal(const std::string &fileName,
+ const Vec3f &position,
+ Vec3f &rotation,
+ const float &scale)
+{
+ model = Model::load(fileName);
+ this->position = position;
+ this->rotation = rotation;
+ this->scale = scale;
+ this->canCollide = true;
+
+ mayEnter = false;
+ maxCrystals = 0;
+}
+
+
+Portal::~Portal()
+{
+}
+
+void Portal::collide()
+{
+ if (maxCrystals == (Player::getInstance()->crystals) && !mayEnter)
+ {
+ canCollide = false;
+ mayEnter = true;
+ }
+}
diff --git a/Portal.h b/Portal.h
new file mode 100644
index 0000000..5f5c330
--- /dev/null
+++ b/Portal.h
@@ -0,0 +1,19 @@
+#pragma once
+#include "Entity.h"
+#include
+
+class Portal :
+ public Entity
+{
+public:
+ Portal(const std::string &fileName,
+ const Vec3f &position,
+ Vec3f &rotation,
+ const float &scale);
+ ~Portal();
+
+ void collide();
+ int maxCrystals;
+ bool mayEnter;
+};
+
diff --git a/Skybox.cpp b/Skybox.cpp
index 1d268ab..2b30899 100644
--- a/Skybox.cpp
+++ b/Skybox.cpp
@@ -4,6 +4,7 @@
#include "stb_image.h"
#include "Skybox.h"
#include
+#include
enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM};
GLuint skybox[6];
@@ -12,6 +13,9 @@ Skybox::Skybox(const float &size, const std::string &folder)
{
this->size = size;
this->folder = folder;
+
+ brightness = 80;
+ targetBrightness = 80;
}
Skybox::~Skybox()
@@ -31,6 +35,8 @@ void Skybox::init()
void Skybox::draw()
{
+ glColor4f(brightness/255, brightness/255, brightness/255, 1);
+
bool b1 = glIsEnabled(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
@@ -114,6 +120,16 @@ void Skybox::draw()
glDisable(GL_TEXTURE_2D);
}
+void Skybox::update(float deltaTime, int curr, int max)
+{
+ targetBrightness = 80 + ((255 - 80) / max) * curr;
+
+ if (targetBrightness > brightness)
+ {
+ brightness += 20 * deltaTime;
+ }
+}
+
GLuint Skybox::loadTexture(const std::string & fileName) //load the filename named texture
{
int width, height, bpp;
diff --git a/Skybox.h b/Skybox.h
index 5b51fbb..84c5a98 100644
--- a/Skybox.h
+++ b/Skybox.h
@@ -6,11 +6,14 @@ class Skybox
private:
float size;
std::string folder;
+ float brightness;
+ float targetBrightness;
public:
Skybox(const float &size, const std::string &folder);
~Skybox();
void init();
void draw();
+ void update(float deltaTime, int, int);
GLuint loadTexture(const std::string &fileName);
};
diff --git a/World.cpp b/World.cpp
index c3d0911..00d6bf9 100644
--- a/World.cpp
+++ b/World.cpp
@@ -6,6 +6,7 @@
#include "CrystalPoint.h"
#include
#include
+#include
#include "WorldHandler.h"
World::World(const std::string &fileName):
@@ -94,11 +95,12 @@ World::World(const std::string &fileName):
//Create
Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());
- position.y = getHeight(position.x, position.z) + 2.0f;
+ position.y = getHeight(position.x, position.z);
entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
}
+ maxEnemies = 0;
//Load and place enemies into world
for (auto e : v["enemies"])
{
@@ -124,9 +126,10 @@ World::World(const std::string &fileName):
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));
}
-
+ maxCrystals = 0;
if (!v["crystal"].isNull())
{
std::string filled = "unknown";
@@ -164,11 +167,12 @@ World::World(const std::string &fileName):
scale = instance["scale"].asFloat();
position.y = getHeight(position.x, position.z);
-
+ maxCrystals++;
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
entities.push_back(c);
}
+ interface->maxCrystals = maxCrystals;
}
}
@@ -180,6 +184,30 @@ World::World(const std::string &fileName):
music->Play();
}
+ if (!v["portal"].isNull())
+ {
+ Vec3f pos(0, 0, 0);
+ if (!v["portal"]["pos"].isNull())
+ pos = Vec3f(v["portal"]["pos"][0].asFloat(),
+ v["portal"]["pos"][1].asFloat(),
+ v["portal"]["pos"][0].asFloat());
+
+ pos.y = getHeight(pos.x, pos.z);
+
+ Vec3f rot(0, 0, 0);
+ if (!v["portal"]["rot"].isNull())
+ pos = Vec3f(v["portal"]["rot"][0].asFloat(),
+ v["portal"]["rot"][1].asFloat(),
+ v["portal"]["rot"][0].asFloat());
+
+ float scale = 1.0f;
+ if (!v["portal"]["scale"].isNull())
+ scale = !v["portal"]["scale"].asFloat();
+
+ portal = new Portal(v["portal"]["file"], pos, rot, scale);
+ entities.push_back(portal);
+ portal->maxCrystals = maxCrystals;
+ }
}
@@ -214,8 +242,6 @@ void World::draw()
float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
- glColor4f(1, 1, 1, 1);
-
skybox->draw();
heightmap->Draw();
@@ -234,6 +260,9 @@ void World::update(float elapsedTime)
for (auto &entity : entities)
entity->update(elapsedTime);
+ int count = 0;
+ int remove = false;
+
for (auto &enemy : enemies)
{
@@ -252,9 +281,26 @@ void World::update(float elapsedTime)
break;
}
}
+
+ if (enemy->attack)
+ {
+ remove = true;
+ continue;
+ }
}
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
+
+ if(!remove)
+ count++;
}
+
+ if(remove)
+ enemies.erase(enemies.begin() + count);
+
+ skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
+
+ if (portal->mayEnter)
+ WorldHandler::getInstance()->NextWorld();
}
void World::addLevelObject(LevelObject* obj)
diff --git a/World.h b/World.h
index 9ffb908..f12d1e2 100644
--- a/World.h
+++ b/World.h
@@ -8,6 +8,7 @@
#include "Interface.h"
#include "Crystal.h"
#include "Skybox.h"
+#include "Portal.h"
class Entity;
@@ -20,8 +21,9 @@ private:
HeightMap* heightmap;
Interface* interface;
Skybox* skybox;
+ Portal* portal;
- int music_id;
+ int music_id,maxCrystals,maxEnemies;
std::vector entities;
std::vector enemies;
diff --git a/WorldHandler.cpp b/WorldHandler.cpp
index 08f9ba0..0b3fe21 100644
--- a/WorldHandler.cpp
+++ b/WorldHandler.cpp
@@ -126,6 +126,7 @@ void WorldHandler::NextWorld()
if (!loadingWorld)
{
ChangeWorld(worldIndex + 1);
+ Player::getInstance()->crystals = 0;
}
}
@@ -134,5 +135,6 @@ void WorldHandler::PreviousWorld()
if (!loadingWorld)
{
ChangeWorld(worldIndex - 1);
+ Player::getInstance()->crystals = 0;
}
}
\ No newline at end of file
diff --git a/worlds/ice.json b/worlds/ice.json
index 201b269..fec0051 100644
--- a/worlds/ice.json
+++ b/worlds/ice.json
@@ -1,33 +1,43 @@
{
- "world": {
+ "world": {
"heightmap": "worlds/hmcs.png",
- "texture": "worlds/hmcstexture.png",
+ "texture": "hmcstexture.png",
+ "skybox": "skyboxes/peaceful/",
"object-templates": [
- {
- "color":100,
- "file": "models/boom/Boom.obj",
- "collision": false
- }
- ]
- },
+ {
+ "color": 100,
+ "file": "models/boom/Boom.obj",
+ "collision": true
+ }
+ ],
+ "music": "WAVE/bond.wav"
+ },
"player": {
- "startposition": [ 0, 1.7, 0]
+ "startposition": [ 1, 5, 20 ]
+ },
+ "objects": [ ],
+ "portal": {
+ "file": "models/Teleporter/Teleporter.obj",
+ "pos": [ 10, 5, 10 ]
},
- "objects": [
- {
- "file": "models/boom/Boom.obj",
- "pos": [ 10, 0, -4 ]
- },
- {
- "file": "models/Teleporter/Teleporter.obj",
- "pos": [ 0, 0, -4 ]
- }
- ],
"enemies": [
- {
+ {
"file": "models/squid/Blooper.obj",
- "pos": [ 10, 2, -10 ],
+ "pos": [ 20, 5, 10 ],
"scale": 0.01
- }
- ]
+ }],
+ "crystal": {
+ "full texture": "models/crystal/Crystal.obj",
+ "empty texture": "models/crystal/PickedUpCrystal.obj",
+ "instances": [
+ {
+ "pos": [ 31, 5, 33 ],
+ "rot": [ 0, 0, 0 ]
+ },
+ {
+ "pos": [ 40, 5, 40 ],
+ "rot": [ 0, 0, 0 ]
+ }
+ ]
+ }
}
\ No newline at end of file
diff --git a/worlds/small.json b/worlds/small.json
index 422b331..af4cecf 100644
--- a/worlds/small.json
+++ b/worlds/small.json
@@ -15,11 +15,20 @@
"startposition": [ 20, 5, 20 ]
},
"objects": [ ],
+ "portal": {
+ "file": "models/Teleporter/Teleporter.obj",
+ "pos": [ 10, 5, 10 ]
+ },
"enemies": [
- {
+ {
"file": "models/squid/Blooper.obj",
"pos": [ 20, 5, 10 ],
"scale": 0.01
+ },
+ {
+ "file": "models/squid/Blooper.obj",
+ "pos": [ 30, 10, 10 ],
+ "scale": 0.01
}],
"crystal": {
"full texture": "models/crystal/Crystal.obj",