Added enemy -> brightness skybox

This commit is contained in:
2016-06-10 11:55:57 +02:00
parent 0ca94aef4d
commit 348b53c027
7 changed files with 56 additions and 5 deletions
+9 -1
View File
@@ -20,6 +20,7 @@ Enemy::Enemy(const std::string &fileName,
radius = 10; radius = 10;
hasTarget = false; hasTarget = false;
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Sound.wav", 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); length = sqrt(dx*dx + dz*dz);
if (length > 1) if (length > 1)
{ {
attack = false;
dx /= length; dx /= length;
dz /= length; dz /= length;
@@ -92,6 +95,11 @@ void Enemy::update(float delta)
position.x += dx; position.x += dx;
position.z += dz; position.z += dz;
} }
else
{
attack = true;
}
rotation.y = atan2f(dx, dz) * 180 / M_PI; rotation.y = atan2f(dx, dz) * 180 / M_PI;
} }
@@ -101,4 +109,4 @@ void Enemy::update(float delta)
sound->SetPos(position, Vec3f()); sound->SetPos(position, Vec3f());
sound->Play(); sound->Play();
} }
} }
+1
View File
@@ -13,6 +13,7 @@ public:
bool hasTarget; bool hasTarget;
Vec3f target; Vec3f target;
float speed,radius; float speed,radius;
bool attack;
void update(float); void update(float);
void draw(); void draw();
+16
View File
@@ -4,6 +4,7 @@
#include "stb_image.h" #include "stb_image.h"
#include "Skybox.h" #include "Skybox.h"
#include <string> #include <string>
#include <iostream>
enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM}; enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM};
GLuint skybox[6]; GLuint skybox[6];
@@ -12,6 +13,9 @@ Skybox::Skybox(const float &size, const std::string &folder)
{ {
this->size = size; this->size = size;
this->folder = folder; this->folder = folder;
brightness = 80;
targetBrightness = 80;
} }
Skybox::~Skybox() Skybox::~Skybox()
@@ -31,6 +35,8 @@ void Skybox::init()
void Skybox::draw() void Skybox::draw()
{ {
glColor4f(brightness/255, brightness/255, brightness/255, 1);
bool b1 = glIsEnabled(GL_TEXTURE_2D); bool b1 = glIsEnabled(GL_TEXTURE_2D);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@@ -114,6 +120,16 @@ void Skybox::draw()
glDisable(GL_TEXTURE_2D); 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 GLuint Skybox::loadTexture(const std::string & fileName) //load the filename named texture
{ {
int width, height, bpp; int width, height, bpp;
+3
View File
@@ -6,11 +6,14 @@ class Skybox
private: private:
float size; float size;
std::string folder; std::string folder;
float brightness;
float targetBrightness;
public: public:
Skybox(const float &size, const std::string &folder); Skybox(const float &size, const std::string &folder);
~Skybox(); ~Skybox();
void init(); void init();
void draw(); void draw();
void update(float deltaTime, int, int);
GLuint loadTexture(const std::string &fileName); GLuint loadTexture(const std::string &fileName);
}; };
+20 -2
View File
@@ -6,6 +6,7 @@
#include "CrystalPoint.h" #include "CrystalPoint.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <algorithm>
#include "WorldHandler.h" #include "WorldHandler.h"
World::World(const std::string &fileName): 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)); entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
} }
maxEnemies = 0;
//Load and place enemies into world //Load and place enemies into world
for (auto e : v["enemies"]) 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()); 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++;
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale)); enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
} }
maxCrystals = 0; maxCrystals = 0;
@@ -239,8 +242,6 @@ void World::draw()
float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 }; float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glColor4f(1, 1, 1, 1);
skybox->draw(); skybox->draw();
heightmap->Draw(); heightmap->Draw();
@@ -259,6 +260,9 @@ void World::update(float elapsedTime)
for (auto &entity : entities) for (auto &entity : entities)
entity->update(elapsedTime); entity->update(elapsedTime);
int count = 0;
int remove = false;
for (auto &enemy : enemies) for (auto &enemy : enemies)
{ {
@@ -277,10 +281,24 @@ void World::update(float elapsedTime)
break; break;
} }
} }
if (enemy->attack)
{
remove = true;
continue;
}
} }
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f; 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) if (portal->mayEnter)
WorldHandler::getInstance()->NextWorld(); WorldHandler::getInstance()->NextWorld();
} }
+1 -1
View File
@@ -23,7 +23,7 @@ private:
Skybox* skybox; Skybox* skybox;
Portal* portal; Portal* portal;
int music_id,maxCrystals; int music_id,maxCrystals,maxEnemies;
std::vector<Entity*> entities; std::vector<Entity*> entities;
std::vector<Enemy*> enemies; std::vector<Enemy*> enemies;
+6 -1
View File
@@ -20,10 +20,15 @@
"pos": [ 10, 5, 10 ] "pos": [ 10, 5, 10 ]
}, },
"enemies": [ "enemies": [
{ {
"file": "models/squid/Blooper.obj", "file": "models/squid/Blooper.obj",
"pos": [ 20, 5, 10 ], "pos": [ 20, 5, 10 ],
"scale": 0.01 "scale": 0.01
},
{
"file": "models/squid/Blooper.obj",
"pos": [ 30, 10, 10 ],
"scale": 0.01
}], }],
"crystal": { "crystal": {
"full texture": "models/crystal/Crystal.obj", "full texture": "models/crystal/Crystal.obj",