Added enemy -> brightness skybox
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
bool hasTarget;
|
||||
Vec3f target;
|
||||
float speed,radius;
|
||||
bool attack;
|
||||
|
||||
void update(float);
|
||||
void draw();
|
||||
|
||||
+16
@@ -4,6 +4,7 @@
|
||||
#include "stb_image.h"
|
||||
#include "Skybox.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "CrystalPoint.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ private:
|
||||
Skybox* skybox;
|
||||
Portal* portal;
|
||||
|
||||
int music_id,maxCrystals;
|
||||
int music_id,maxCrystals,maxEnemies;
|
||||
|
||||
std::vector<Entity*> entities;
|
||||
std::vector<Enemy*> enemies;
|
||||
|
||||
+6
-1
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user