Merge pull request #12 from CrystalPointA4/crystal_capturing
Crystal capturing
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
#include "Crystal.h"
|
||||
#include "Model.h"
|
||||
|
||||
|
||||
Crystal::Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale)
|
||||
{
|
||||
model = Model::load(fileName);
|
||||
this->position = position;
|
||||
this->rotation = rotation;
|
||||
this->scale = scale;
|
||||
this->canCollide = true;
|
||||
filled = true;
|
||||
}
|
||||
|
||||
|
||||
Crystal::~Crystal()
|
||||
{
|
||||
if (model)
|
||||
Model::unload(model);
|
||||
}
|
||||
|
||||
void Crystal::draw()
|
||||
{
|
||||
if (filled)
|
||||
Entity::draw();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Entity.h"
|
||||
#include <string>
|
||||
|
||||
class Crystal :
|
||||
public Entity
|
||||
{
|
||||
public:
|
||||
Crystal(const std::string &fileName, const Vec3f &position, Vec3f &rotation, const float &scale);
|
||||
~Crystal();
|
||||
|
||||
bool filled;
|
||||
void draw();
|
||||
};
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Crystal.cpp" />
|
||||
<ClCompile Include="CrystalPoint.cpp" />
|
||||
<ClCompile Include="Cursor.cpp" />
|
||||
<ClCompile Include="Enemy.cpp" />
|
||||
@@ -168,6 +169,7 @@
|
||||
<ClCompile Include="WorldHandler.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Crystal.h" />
|
||||
<ClInclude Include="CrystalPoint.h" />
|
||||
<ClInclude Include="Cursor.h" />
|
||||
<ClInclude Include="Enemy.h" />
|
||||
|
||||
@@ -69,6 +69,9 @@
|
||||
<ClCompile Include="Interface.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Crystal.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="World.h">
|
||||
@@ -119,6 +122,9 @@
|
||||
<ClInclude Include="vector.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Crystal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="worlds\worlds.json">
|
||||
|
||||
@@ -77,6 +77,23 @@ void Interface::draw()
|
||||
glColor4f(1.0f, 1.0f, 0.1f, 1.0);
|
||||
glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
|
||||
|
||||
|
||||
|
||||
int cw, ch, offset;
|
||||
cw = 20;
|
||||
ch = 50;
|
||||
offset = 5;
|
||||
for (int i = 0; i < player->crystals; i++)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::update(float deltaTime)
|
||||
|
||||
@@ -11,6 +11,7 @@ Player::Player()
|
||||
health = 50;
|
||||
xp = 75;
|
||||
level = 10;
|
||||
crystals = 0;
|
||||
}
|
||||
|
||||
Player* Player::getInstance()
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
float health;
|
||||
float xp;
|
||||
int level;
|
||||
int crystals;
|
||||
|
||||
float speed;
|
||||
};
|
||||
@@ -84,7 +84,9 @@ World::World(const std::string &fileName)
|
||||
std::cout << "Invalid world file: objects file - " << fileName << "\n";
|
||||
|
||||
//Create
|
||||
Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());
|
||||
Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());
|
||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
||||
|
||||
entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
|
||||
}
|
||||
|
||||
@@ -111,8 +113,36 @@ World::World(const std::string &fileName)
|
||||
|
||||
//Create
|
||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
||||
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
||||
|
||||
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
|
||||
}
|
||||
|
||||
for (auto e : v["crystals"])
|
||||
{
|
||||
//Rotation
|
||||
Vec3f rotation(0, 0, 0);
|
||||
if (!e["rot"].isNull())
|
||||
rotation = Vec3f(e["rot"][0].asFloat(), e["rot"][1].asFloat(), e["rot"][2].asFloat());
|
||||
|
||||
//Scale
|
||||
float scale = 1.0f;
|
||||
if (!e["scale"].isNull())
|
||||
scale = e["scale"].asFloat();
|
||||
|
||||
//Position
|
||||
if (e["pos"].isNull())
|
||||
std::cout << "Invalid world file: enemies pos - " << fileName << "\n";
|
||||
|
||||
//File
|
||||
if (e["file"].isNull())
|
||||
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
|
||||
|
||||
//Create
|
||||
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
|
||||
position.y = getHeight(position.x, position.z) + 2.0f;
|
||||
|
||||
crystals.push_back(new Crystal(e["file"].asString(), position, rotation, scale));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +184,8 @@ void World::draw()
|
||||
|
||||
for (auto &entity : entities)
|
||||
entity->draw();
|
||||
for (auto &crystal : crystals)
|
||||
crystal->draw();
|
||||
|
||||
interface->draw();
|
||||
}
|
||||
@@ -182,9 +214,20 @@ void World::update(float elapsedTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
WorldHandler* worldhandler = WorldHandler::getInstance();
|
||||
enemy->position.y = worldhandler->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Enemy.h"
|
||||
#include "LevelObject.h"
|
||||
#include "Interface.h"
|
||||
#include "Crystal.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
@@ -20,6 +21,7 @@ private:
|
||||
|
||||
std::vector<Entity*> entities;
|
||||
std::vector<Enemy*> enemies;
|
||||
std::vector<Crystal*> crystals;
|
||||
public:
|
||||
World(const std::string &fileName);
|
||||
~World();
|
||||
@@ -30,5 +32,6 @@ public:
|
||||
float getHeight(float x, float y);
|
||||
void addLevelObject(LevelObject* obj);
|
||||
std::pair<std::string, bool> getObjectFromValue(int i);
|
||||
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ void WorldHandler::ChangeWorld(int i)
|
||||
delete world;
|
||||
|
||||
world = new World(worldfiles[i]);
|
||||
worldIndex = i;
|
||||
worldIndex = i;
|
||||
loadingWorld = false;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,10 @@
|
||||
newmtl Default_Smoothing
|
||||
Ka 0 0 0
|
||||
Kd 0.784314 0.784314 0.784314
|
||||
Ks 0 0 0
|
||||
Ni 1
|
||||
Ns 400
|
||||
Tf 1 1 1
|
||||
d 1
|
||||
map_Kd sphere.bmp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+20
-11
@@ -1,23 +1,32 @@
|
||||
{
|
||||
"world": {
|
||||
"world": {
|
||||
"heightmap": "worlds/small.png",
|
||||
"object-templates": [
|
||||
{
|
||||
"color":100,
|
||||
"file": "models/boom/Boom.obj",
|
||||
"collision": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"object-templates": [
|
||||
{
|
||||
"color": 100,
|
||||
"file": "models/boom/Boom.obj",
|
||||
"collision": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"player": {
|
||||
"startposition": [ 20, 5, 20 ]
|
||||
},
|
||||
"objects": [],
|
||||
"objects": [ ],
|
||||
"enemies": [
|
||||
{
|
||||
{
|
||||
"file": "models/squid/Blooper.obj",
|
||||
"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 ]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user