optimiasted crystal, entity now has a collide methode, which will be called when an entity collison has with the player.
This commit is contained in:
+8
-3
@@ -1,5 +1,6 @@
|
|||||||
#include "Crystal.h"
|
#include "Crystal.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
|
||||||
Crystal::Crystal(const std::string & filled, const std::string & empty, 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)
|
||||||
@@ -26,8 +27,12 @@ void Crystal::draw()
|
|||||||
Entity::draw();
|
Entity::draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Crystal::pickUp()
|
void Crystal::collide()
|
||||||
{
|
{
|
||||||
isFilled = false;
|
if (isFilled)
|
||||||
model = Model::load(empty);
|
{
|
||||||
|
Player::getInstance()->crystals++;
|
||||||
|
isFilled = false;
|
||||||
|
model = Model::load(empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
|
|
||||||
bool isFilled;
|
bool isFilled;
|
||||||
void draw();
|
void draw();
|
||||||
void pickUp();
|
void collide();
|
||||||
private:
|
private:
|
||||||
std::string filled, empty;
|
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;
|
||||||
|
|||||||
+4
-4
@@ -90,12 +90,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 - crystalWidth / 2, crystalOffset*i + crystalHeight*i);
|
glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
|
||||||
glVertex2f(975 - crystalWidth, crystalHeight / 2 + crystalOffset*i + crystalHeight*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 - crystalWidth / 2, crystalHeight + crystalOffset*i + crystalHeight*i);
|
glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
|
||||||
glVertex2f(975, crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
|
glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,9 +157,8 @@ World::World(const std::string &fileName)
|
|||||||
position.y = getHeight(position.x, position.z);
|
position.y = getHeight(position.x, position.z);
|
||||||
|
|
||||||
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
|
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
|
||||||
|
|
||||||
crystals.push_back(c);
|
entities.push_back(c);
|
||||||
//entities.push_back(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,8 +202,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();
|
||||||
}
|
}
|
||||||
@@ -247,18 +244,8 @@ 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))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto & c : crystals)
|
|
||||||
{
|
|
||||||
if (c->canCollide && c->inObject(player->position))
|
|
||||||
{
|
{
|
||||||
if (c->isFilled)
|
e->collide();
|
||||||
{
|
|
||||||
c->pickUp();
|
|
||||||
player->crystals++;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,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();
|
||||||
|
|||||||
Reference in New Issue
Block a user