Merge pull request #14 from CrystalPointA4/feature/refactor_crystals

Feature/refactor crystals
This commit is contained in:
2016-06-09 13:05:11 +02:00
12 changed files with 4790 additions and 58 deletions
+18 -6
View File
@@ -1,18 +1,21 @@
#include "Crystal.h"
#include "Model.h"
#include "Player.h"
Crystal::Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale)
Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale)
{
model = Model::load(fileName);
this->filled = filled;
this->empty = empty;
model = Model::load(this->filled);
this->position = position;
this->rotation = rotation;
this->scale = scale;
this->canCollide = true;
filled = true;
isFilled = true;
}
Crystal::~Crystal()
{
if (model)
@@ -20,7 +23,16 @@ Crystal::~Crystal()
}
void Crystal::draw()
{
Entity::draw();
}
void Crystal::collide()
{
if (filled)
Entity::draw();
if (isFilled)
{
Player::getInstance()->crystals++;
isFilled = false;
model = Model::load(empty);
}
}
+6 -2
View File
@@ -6,10 +6,14 @@ class Crystal :
public Entity
{
public:
Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale);
Crystal(const std::string &filled, const std::string &empty,
const Vec3f &position, Vec3f &rotation, const float &scale);
~Crystal();
bool filled;
bool isFilled;
void draw();
void collide();
private:
std::string filled, empty;
};
+2
View File
@@ -13,6 +13,8 @@ public:
virtual void draw();
virtual void update(float elapsedTime) {};
virtual void collide() {};
Vec3f position;
Vec3f rotation;
float scale;
+8 -4
View File
@@ -11,6 +11,9 @@ void glutBitmapString(std::string str, int x, int y);
Interface::Interface()
{
crystalWidth = 20;
crystalHeight = 50;
crystalOffset = 5;
}
@@ -85,11 +88,12 @@ void Interface::draw()
{
glBegin(GL_QUADS);
glColor4f(0, 1.0f, 1.0f, 1.0f);
glVertex2f(975 - cw / 2, offset*i + ch*i);
glVertex2f(975 - cw , ch / 2 + offset*i + ch*i);
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);
glVertex2f(975 - cw / 2, ch + offset*i + ch*i);
glVertex2f(975 , ch / 2 + offset*i + ch*i);
glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
glEnd();
}
+2
View File
@@ -7,5 +7,7 @@ public:
void draw(void);
void update(float deltaTime);
int crystalWidth, crystalHeight, crystalOffset;
};
+41 -35
View File
@@ -127,31 +127,49 @@ World::World(const std::string &fileName):
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
}
for (auto e : v["crystals"])
if (!v["crystal"].isNull())
{
//Rotation
Vec3f rotation(0, 0, 0);
if (!e["rot"].isNull())
rotation = Vec3f(e["rot"][0].asFloat(), e["rot"][1].asFloat(), e["rot"][2].asFloat());
std::string filled = "unknown";
std::string empty = "unknown";
//Scale
float scale = 1.0f;
if (!e["scale"].isNull())
scale = e["scale"].asFloat();
if(!v["crystal"]["full texture"].isNull())
filled = v["crystal"]["full texture"].asString();
//Position
if (e["pos"].isNull())
std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
if(!v["crystal"]["empty texture"].isNull())
empty = v["crystal"]["empty texture"].asString();
//File
if (e["file"].isNull())
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
if (!v["crystal"]["instances"].isNull())
{
for (auto instance : v["crystal"]["instances"])
{
Vec3f position(0, 0, 0);
Vec3f rotation(0, 0, 0);
float scale = 1.0f;
//Create
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
position.y = getHeight(position.x, position.z) + 2.0f;
if (!instance["pos"].isNull())
{
position.x = instance["pos"][0];
position.y = instance["pos"][1];
position.z = instance["pos"][2];
}
if (!instance["rot"].isNull())
{
rotation.x = instance["rot"][0];
rotation.y = instance["rot"][1];
rotation.z = instance["rot"][2];
}
crystals.push_back(new Crystal(e["file"].asString(), position, rotation, scale));
if (!instance["scale"].isNull())
scale = instance["scale"].asFloat();
position.y = getHeight(position.x, position.z);
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
entities.push_back(c);
}
}
}
if (!v["world"]["music"].isNull())
@@ -207,8 +225,6 @@ void World::draw()
for (auto &entity : entities)
entity->draw();
for (auto &crystal : crystals)
crystal->draw();
interface->draw();
}
@@ -237,20 +253,7 @@ void World::update(float elapsedTime)
}
}
}
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
//tot hier
}
for(auto &crystal : crystals)
{
if (crystal->canCollide && crystal->inObject(player->position) && crystal->filled)
{
crystal->filled = false;
player->crystals++;
break;
}
}
}
@@ -261,10 +264,13 @@ void World::addLevelObject(LevelObject* obj)
bool World::isPlayerPositionValid()
{
for (auto e : entities)
for (auto &e : entities)
{
if (e->canCollide && e->inObject(player->position))
{
e->collide();
return false;
}
}
return true;
}
+1 -1
View File
@@ -25,7 +25,7 @@ private:
std::vector<Entity*> entities;
std::vector<Enemy*> enemies;
std::vector<Crystal*> crystals;
//std::vector<Crystal*> crystals;
public:
World(const std::string &fileName);
~World();
+92
View File
@@ -0,0 +1,92 @@
newmtl SpringIsComing:Material_007
illum 4
Kd 0.75 0.80 0.80
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl initialShadingGroup
illum 4
Kd 0.34 0.34 0.34
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl rock3:Material_016
illum 4
Kd 0.64 0.64 0.64
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
File diff suppressed because it is too large Load Diff
+92
View File
@@ -0,0 +1,92 @@
newmtl SpringIsComing:Material_007
illum 4
Kd 0.75 0.80 0.80
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl initialShadingGroup
illum 4
Kd 0.34 0.34 0.34
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl rock3:Material_016
illum 4
Kd 0.64 0.64 0.64
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
File diff suppressed because it is too large Load Diff
+14 -10
View File
@@ -21,14 +21,18 @@
"pos": [ 20, 5, 10 ],
"scale": 0.01
}],
"crystals": [
{
"file": "models/sphere/sphere.obj",
"pos": [ 33, 2, 31 ]
},
{
"file": "models/sphere/sphere.obj",
"pos": [ 45, 2, 31 ]
}
]
"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 ]
}
]
}
}