Merge pull request #14 from CrystalPointA4/feature/refactor_crystals
Feature/refactor crystals
This commit is contained in:
+18
-6
@@ -1,18 +1,21 @@
|
|||||||
#include "Crystal.h"
|
#include "Crystal.h"
|
||||||
#include "Model.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->position = position;
|
||||||
this->rotation = rotation;
|
this->rotation = rotation;
|
||||||
this->scale = scale;
|
this->scale = scale;
|
||||||
this->canCollide = true;
|
this->canCollide = true;
|
||||||
filled = true;
|
isFilled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Crystal::~Crystal()
|
Crystal::~Crystal()
|
||||||
{
|
{
|
||||||
if (model)
|
if (model)
|
||||||
@@ -21,6 +24,15 @@ Crystal::~Crystal()
|
|||||||
|
|
||||||
void Crystal::draw()
|
void Crystal::draw()
|
||||||
{
|
{
|
||||||
if (filled)
|
Entity::draw();
|
||||||
Entity::draw();
|
}
|
||||||
|
|
||||||
|
void Crystal::collide()
|
||||||
|
{
|
||||||
|
if (isFilled)
|
||||||
|
{
|
||||||
|
Player::getInstance()->crystals++;
|
||||||
|
isFilled = false;
|
||||||
|
model = Model::load(empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ class Crystal :
|
|||||||
public Entity
|
public Entity
|
||||||
{
|
{
|
||||||
public:
|
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();
|
~Crystal();
|
||||||
|
|
||||||
bool filled;
|
bool isFilled;
|
||||||
void draw();
|
void draw();
|
||||||
|
void collide();
|
||||||
|
private:
|
||||||
|
std::string filled, empty;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public:
|
|||||||
|
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
virtual void update(float elapsedTime) {};
|
virtual void update(float elapsedTime) {};
|
||||||
|
virtual void collide() {};
|
||||||
|
|
||||||
Vec3f position;
|
Vec3f position;
|
||||||
Vec3f rotation;
|
Vec3f rotation;
|
||||||
float scale;
|
float scale;
|
||||||
|
|||||||
+8
-4
@@ -11,6 +11,9 @@ void glutBitmapString(std::string str, int x, int y);
|
|||||||
|
|
||||||
Interface::Interface()
|
Interface::Interface()
|
||||||
{
|
{
|
||||||
|
crystalWidth = 20;
|
||||||
|
crystalHeight = 50;
|
||||||
|
crystalOffset = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,11 +88,12 @@ void Interface::draw()
|
|||||||
{
|
{
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor4f(0, 1.0f, 1.0f, 1.0f);
|
glColor4f(0, 1.0f, 1.0f, 1.0f);
|
||||||
glVertex2f(975 - cw / 2, offset*i + ch*i);
|
glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
|
||||||
glVertex2f(975 - cw , ch / 2 + offset*i + ch*i);
|
glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
|
||||||
|
|
||||||
glColor4f(0, 0.8f, 0.8f, 1.0f);
|
glColor4f(0, 0.8f, 0.8f, 1.0f);
|
||||||
glVertex2f(975 - cw / 2, ch + offset*i + ch*i);
|
glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
|
||||||
glVertex2f(975 , ch / 2 + offset*i + ch*i);
|
glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ public:
|
|||||||
|
|
||||||
void draw(void);
|
void draw(void);
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
|
|
||||||
|
int crystalWidth, crystalHeight, crystalOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -127,31 +127,49 @@ World::World(const std::string &fileName):
|
|||||||
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto e : v["crystals"])
|
if (!v["crystal"].isNull())
|
||||||
{
|
{
|
||||||
//Rotation
|
std::string filled = "unknown";
|
||||||
Vec3f rotation(0, 0, 0);
|
std::string empty = "unknown";
|
||||||
if (!e["rot"].isNull())
|
|
||||||
rotation = Vec3f(e["rot"][0].asFloat(), e["rot"][1].asFloat(), e["rot"][2].asFloat());
|
|
||||||
|
|
||||||
//Scale
|
if(!v["crystal"]["full texture"].isNull())
|
||||||
float scale = 1.0f;
|
filled = v["crystal"]["full texture"].asString();
|
||||||
if (!e["scale"].isNull())
|
|
||||||
scale = e["scale"].asFloat();
|
|
||||||
|
|
||||||
//Position
|
if(!v["crystal"]["empty texture"].isNull())
|
||||||
if (e["pos"].isNull())
|
empty = v["crystal"]["empty texture"].asString();
|
||||||
std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
|
|
||||||
|
|
||||||
//File
|
if (!v["crystal"]["instances"].isNull())
|
||||||
if (e["file"].isNull())
|
{
|
||||||
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
for (auto instance : v["crystal"]["instances"])
|
||||||
|
{
|
||||||
|
Vec3f position(0, 0, 0);
|
||||||
|
Vec3f rotation(0, 0, 0);
|
||||||
|
float scale = 1.0f;
|
||||||
|
|
||||||
//Create
|
if (!instance["pos"].isNull())
|
||||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
{
|
||||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
position.x = instance["pos"][0];
|
||||||
|
position.y = instance["pos"][1];
|
||||||
|
position.z = instance["pos"][2];
|
||||||
|
}
|
||||||
|
|
||||||
crystals.push_back(new Crystal(e["file"].asString(), position, rotation, scale));
|
if (!instance["rot"].isNull())
|
||||||
|
{
|
||||||
|
rotation.x = instance["rot"][0];
|
||||||
|
rotation.y = instance["rot"][1];
|
||||||
|
rotation.z = instance["rot"][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
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())
|
if (!v["world"]["music"].isNull())
|
||||||
@@ -207,8 +225,6 @@ void World::draw()
|
|||||||
|
|
||||||
for (auto &entity : entities)
|
for (auto &entity : entities)
|
||||||
entity->draw();
|
entity->draw();
|
||||||
for (auto &crystal : crystals)
|
|
||||||
crystal->draw();
|
|
||||||
|
|
||||||
interface->draw();
|
interface->draw();
|
||||||
}
|
}
|
||||||
@@ -237,20 +253,7 @@ void World::update(float elapsedTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
|
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()
|
bool World::isPlayerPositionValid()
|
||||||
{
|
{
|
||||||
for (auto e : entities)
|
for (auto &e : entities)
|
||||||
{
|
{
|
||||||
if (e->canCollide && e->inObject(player->position))
|
if (e->canCollide && e->inObject(player->position))
|
||||||
|
{
|
||||||
|
e->collide();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ private:
|
|||||||
|
|
||||||
std::vector<Entity*> entities;
|
std::vector<Entity*> entities;
|
||||||
std::vector<Enemy*> enemies;
|
std::vector<Enemy*> enemies;
|
||||||
std::vector<Crystal*> crystals;
|
//std::vector<Crystal*> crystals;
|
||||||
public:
|
public:
|
||||||
World(const std::string &fileName);
|
World(const std::string &fileName);
|
||||||
~World();
|
~World();
|
||||||
|
|||||||
@@ -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
@@ -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
@@ -21,14 +21,18 @@
|
|||||||
"pos": [ 20, 5, 10 ],
|
"pos": [ 20, 5, 10 ],
|
||||||
"scale": 0.01
|
"scale": 0.01
|
||||||
}],
|
}],
|
||||||
"crystals": [
|
"crystal": {
|
||||||
{
|
"full texture": "models/crystal/Crystal.obj",
|
||||||
"file": "models/sphere/sphere.obj",
|
"empty texture": "models/crystal/PickedUpCrystal.obj",
|
||||||
"pos": [ 33, 2, 31 ]
|
"instances": [
|
||||||
},
|
{
|
||||||
{
|
"pos": [ 31, 5, 33 ],
|
||||||
"file": "models/sphere/sphere.obj",
|
"rot": [ 0, 0, 0 ]
|
||||||
"pos": [ 45, 2, 31 ]
|
},
|
||||||
}
|
{
|
||||||
]
|
"pos": [ 40, 5, 40 ],
|
||||||
|
"rot": [ 0, 0, 0 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user