Merge branch 'developer' into feature/OpenAL
# Conflicts: # CrystalPoint.vcxproj.filters # Enemy.cpp # Enemy.h # worlds/small.json
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();
|
||||
};
|
||||
|
||||
@@ -154,6 +154,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Crystal.cpp" />
|
||||
<ClCompile Include="CrystalPoint.cpp" />
|
||||
<ClCompile Include="Cursor.cpp" />
|
||||
<ClCompile Include="Enemy.cpp" />
|
||||
@@ -173,6 +174,7 @@
|
||||
<ClCompile Include="WorldHandler.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Crystal.h" />
|
||||
<ClInclude Include="CrystalPoint.h" />
|
||||
<ClInclude Include="Cursor.h" />
|
||||
<ClInclude Include="Enemy.h" />
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Sound.cpp">
|
||||
<ClCompile Include="Crystal.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@@ -129,6 +130,7 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Sound.h">
|
||||
<ClInclude Include="Crystal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -59,9 +59,14 @@ void Enemy::inEyeSight(Vec3f & TargetPosition)
|
||||
hasTarget = false;
|
||||
}
|
||||
|
||||
bool Enemy::hasCollison(Vec3f &)
|
||||
void Enemy::collide(const Entity * entity)
|
||||
{
|
||||
return false;
|
||||
Vec3f difference = position - entity->position; //zou misschien omgedraait moeten worden
|
||||
difference.y = 0;
|
||||
difference.Normalize();
|
||||
difference = difference * (entity->model->radius + 0.01f);
|
||||
position.x = difference.x + entity->position.x;
|
||||
position.z = difference.z + entity->position.z;
|
||||
}
|
||||
|
||||
void Enemy::update(float delta)
|
||||
@@ -76,7 +81,7 @@ void Enemy::update(float delta)
|
||||
dz = target.z - position.z;
|
||||
|
||||
length = sqrt(dx*dx + dz*dz);
|
||||
if (length > 0.03)
|
||||
if (length > 1)
|
||||
{
|
||||
dx /= length;
|
||||
dz /= length;
|
||||
|
||||
@@ -18,8 +18,7 @@ public:
|
||||
void draw();
|
||||
|
||||
void inEyeSight(Vec3f &);
|
||||
bool hasCollison(Vec3f &);
|
||||
|
||||
void collide(const Entity *entity);
|
||||
private:
|
||||
int hit_sound_id;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "CrystalPoint.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "WorldHandler.h"
|
||||
|
||||
World::World(const std::string &fileName):
|
||||
music_id(-1)
|
||||
@@ -84,7 +85,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 +114,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));
|
||||
}
|
||||
|
||||
if (!v["world"]["music"].isNull())
|
||||
@@ -163,6 +194,8 @@ void World::draw()
|
||||
|
||||
for (auto &entity : entities)
|
||||
entity->draw();
|
||||
for (auto &crystal : crystals)
|
||||
crystal->draw();
|
||||
|
||||
interface->draw();
|
||||
}
|
||||
@@ -178,7 +211,7 @@ void World::update(float elapsedTime)
|
||||
//Al deze code zou in enemy moeten staan
|
||||
enemy->inEyeSight(player->position);
|
||||
|
||||
|
||||
|
||||
enemy->update(elapsedTime);
|
||||
if (enemy->hasTarget)
|
||||
{
|
||||
@@ -186,15 +219,25 @@ void World::update(float elapsedTime)
|
||||
{
|
||||
if (e->canCollide && e->inObject(enemy->position))
|
||||
{
|
||||
Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden
|
||||
difference.Normalize();
|
||||
difference = difference * (e->model->radius + 0.01f);
|
||||
enemy->position = e->position + difference;
|
||||
enemy->collide(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -21,6 +22,7 @@ private:
|
||||
|
||||
std::vector<Entity*> entities;
|
||||
std::vector<Enemy*> enemies;
|
||||
std::vector<Crystal*> crystals;
|
||||
public:
|
||||
World(const std::string &fileName);
|
||||
~World();
|
||||
@@ -31,5 +33,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
+31
-16
@@ -1,18 +1,33 @@
|
||||
{
|
||||
"world": {
|
||||
"heightmap": "worlds/small.png",
|
||||
"object-templates": [
|
||||
{
|
||||
"color": 100,
|
||||
"file": "models/boom/Boom.obj",
|
||||
"collision": false
|
||||
}
|
||||
],
|
||||
"music": "WAVE/bond.wav"
|
||||
},
|
||||
"player": {
|
||||
"startposition": [ 20, 5, 20 ]
|
||||
},
|
||||
"objects": [],
|
||||
"enemies": []
|
||||
"world": {
|
||||
"heightmap": "worlds/small.png",
|
||||
"object-templates": [
|
||||
{
|
||||
"color": 100,
|
||||
"file": "models/boom/Boom.obj",
|
||||
"collision": true
|
||||
}
|
||||
],
|
||||
"music": "WAVE/bond.wav"
|
||||
},
|
||||
"player": {
|
||||
"startposition": [ 20, 5, 20 ]
|
||||
},
|
||||
"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