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",