diff --git a/Enemy.cpp b/Enemy.cpp index 2864fb8..9d77229 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -59,9 +59,14 @@ void Enemy::inEyeSight(Vec3f & TargetPosition) hasTarget = false; } -bool Enemy::hasCollison(Vec3f &) +void Enemy::collide(const Entity * entity) { - + 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) @@ -75,7 +80,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; diff --git a/Enemy.h b/Enemy.h index 44aec67..e0cabd7 100644 --- a/Enemy.h +++ b/Enemy.h @@ -18,6 +18,6 @@ public: void draw(); void inEyeSight(Vec3f &); - bool hasCollison(Vec3f &); + void collide(const Entity *entity); }; diff --git a/World.cpp b/World.cpp index 57a5347..5faf4dc 100644 --- a/World.cpp +++ b/World.cpp @@ -6,6 +6,7 @@ #include "CrystalPoint.h" #include #include +#include "WorldHandler.h" World::World(const std::string &fileName) { @@ -168,7 +169,7 @@ void World::update(float elapsedTime) //Al deze code zou in enemy moeten staan enemy->inEyeSight(player->position); - + enemy->update(elapsedTime); if (enemy->hasTarget) { @@ -176,14 +177,13 @@ 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; } } - } + } + WorldHandler* worldhandler = WorldHandler::getInstance(); + enemy->position.y = worldhandler->getHeight(enemy->position.x, enemy->position.z) + 2.0f; //tot hier } } diff --git a/worlds/small.json b/worlds/small.json index 466db7c..b46e927 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -5,7 +5,7 @@ { "color":100, "file": "models/boom/Boom.obj", - "collision": false + "collision": true } ] }, @@ -13,5 +13,11 @@ "startposition": [ 20, 5, 20 ] }, "objects": [], - "enemies": [] + "enemies": [ + { + "file": "models/squid/Blooper.obj", + "pos": [ 20, 5, 10 ], + "scale": 0.01 + } + ] } \ No newline at end of file