picking up crystal(sphere)

This commit is contained in:
Remco
2016-06-08 12:41:33 +02:00
parent 527394f635
commit bba0a2e2a0
12 changed files with 1959 additions and 16 deletions
+26
View File
@@ -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();
}
+15
View File
@@ -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();
};
+2
View File
@@ -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" />
+6
View File
@@ -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">
+43 -4
View File
@@ -6,6 +6,7 @@
#include "CrystalPoint.h"
#include <fstream>
#include <iostream>
#include "WorldHandler.h"
World::World(const std::string &fileName)
{
@@ -83,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));
}
@@ -110,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));
}
}
@@ -153,6 +184,8 @@ void World::draw()
for (auto &entity : entities)
entity->draw();
for (auto &crystal : crystals)
crystal->draw();
interface->draw();
}
@@ -183,9 +216,15 @@ void World::update(float elapsedTime)
break;
}
}
}
//tot hier
}
}
for(auto &crystal : crystals)
if (crystal->canCollide && crystal->inObject(player->position))
{
crystal->filled = false;
break;
}
}
void World::addLevelObject(LevelObject* obj)
+3
View File
@@ -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
View File
@@ -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

+10
View File
@@ -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
+19 -11
View File
@@ -1,17 +1,25 @@
{
"world": {
"world": {
"heightmap": "worlds/small.png",
"object-templates": [
{
"color":100,
"file": "models/boom/Boom.obj",
"collision": false
}
]
},
"object-templates": [
{
"color": 100,
"file": "models/boom/Boom.obj",
"collision": true
}
]
},
"player": {
"startposition": [ 20, 5, 20 ]
},
"objects": [],
"enemies": []
"objects": [ ],
"enemies": [ ],
"crystals": [
{
"file": "models/sphere/sphere.obj",
"pos": [ 33, 2, 31 ],
"collide": "true"
}
]
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB