From 912a2234a3c6f12ab4adcbae3e743d89f19da850 Mon Sep 17 00:00:00 2001 From: Remco Date: Thu, 9 Jun 2016 17:47:34 +0200 Subject: [PATCH 1/4] crystals will be displayed, when not get with darker icons, when picked up crystals get colors --- Crystal.cpp | 18 ++++++++++++++---- Crystal.h | 3 ++- Interface.cpp | 28 +++++++++++++++++++++------- Interface.h | 2 ++ World.cpp | 7 ++++--- World.h | 2 +- worlds/small.json | 7 ++++++- 7 files changed, 50 insertions(+), 17 deletions(-) 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/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/World.cpp b/World.cpp index c3d0911..3db2f3d 100644 --- a/World.cpp +++ b/World.cpp @@ -94,7 +94,7 @@ 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)); } @@ -126,7 +126,7 @@ World::World(const std::string &fileName): enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale)); } - + maxCrystals = 0; if (!v["crystal"].isNull()) { std::string filled = "unknown"; @@ -164,11 +164,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; } } diff --git a/World.h b/World.h index 9ffb908..17d362a 100644 --- a/World.h +++ b/World.h @@ -21,7 +21,7 @@ private: Interface* interface; Skybox* skybox; - int music_id; + int music_id,maxCrystals; std::vector entities; std::vector enemies; diff --git a/worlds/small.json b/worlds/small.json index 422b331..826848b 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -14,7 +14,12 @@ "player": { "startposition": [ 20, 5, 20 ] }, - "objects": [ ], + "objects": [ + { + "file": "models/Teleporter/Teleporter.obj", + "pos": [ 10, 5, 10 ] + } + ], "enemies": [ { "file": "models/squid/Blooper.obj", From 0ca94aef4d1154a520d4e9feaf21f1eeb5f361a4 Mon Sep 17 00:00:00 2001 From: Remco Date: Fri, 10 Jun 2016 10:56:54 +0200 Subject: [PATCH 2/4] when collected all crystals it is possible to move to the next level, by stepping in the portal --- CrystalPoint.vcxproj | 2 ++ CrystalPoint.vcxproj.filters | 12 ++++++-- Main.cpp | 3 +- Portal.cpp | 34 +++++++++++++++++++++ Portal.h | 19 ++++++++++++ World.cpp | 27 +++++++++++++++++ World.h | 2 ++ worlds/ice.json | 58 +++++++++++++++++++++--------------- worlds/small.json | 11 ++++--- 9 files changed, 134 insertions(+), 34 deletions(-) create mode 100644 Portal.cpp create mode 100644 Portal.h 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/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/World.cpp b/World.cpp index 3db2f3d..a89cc56 100644 --- a/World.cpp +++ b/World.cpp @@ -181,6 +181,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; + } } @@ -256,6 +280,9 @@ void World::update(float elapsedTime) } enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f; } + + if (portal->mayEnter) + WorldHandler::getInstance()->NextWorld(); } void World::addLevelObject(LevelObject* obj) diff --git a/World.h b/World.h index 17d362a..06df243 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,6 +21,7 @@ private: HeightMap* heightmap; Interface* interface; Skybox* skybox; + Portal* portal; int music_id,maxCrystals; 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 826848b..6566982 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -14,12 +14,11 @@ "player": { "startposition": [ 20, 5, 20 ] }, - "objects": [ - { - "file": "models/Teleporter/Teleporter.obj", - "pos": [ 10, 5, 10 ] - } - ], + "objects": [ ], + "portal": { + "file": "models/Teleporter/Teleporter.obj", + "pos": [ 10, 5, 10 ] + }, "enemies": [ { "file": "models/squid/Blooper.obj", From 71801a30f28105696e65ff786d6bb352e86b588d Mon Sep 17 00:00:00 2001 From: Remco Date: Fri, 10 Jun 2016 11:06:39 +0200 Subject: [PATCH 3/4] player crystals refresh --- WorldHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) 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 From 348b53c027a74a4abc06ec4785f24d76d6709c0a Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 10 Jun 2016 11:55:57 +0200 Subject: [PATCH 4/4] Added enemy -> brightness skybox --- Enemy.cpp | 10 +++++++++- Enemy.h | 1 + Skybox.cpp | 16 ++++++++++++++++ Skybox.h | 3 +++ World.cpp | 22 ++++++++++++++++++++-- World.h | 2 +- worlds/small.json | 7 ++++++- 7 files changed, 56 insertions(+), 5 deletions(-) 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/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 a89cc56..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): @@ -99,6 +100,7 @@ World::World(const std::string &fileName): 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,6 +126,7 @@ 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; @@ -239,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(); @@ -259,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) { @@ -277,10 +281,24 @@ 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(); } diff --git a/World.h b/World.h index 06df243..f12d1e2 100644 --- a/World.h +++ b/World.h @@ -23,7 +23,7 @@ private: Skybox* skybox; Portal* portal; - int music_id,maxCrystals; + int music_id,maxCrystals,maxEnemies; std::vector entities; std::vector enemies; diff --git a/worlds/small.json b/worlds/small.json index 6566982..af4cecf 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -20,10 +20,15 @@ "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",