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 42c1a0b..ed1b343 100644 --- a/World.cpp +++ b/World.cpp @@ -201,7 +201,7 @@ void World::update(float elapsedTime) //Al deze code zou in enemy moeten staan enemy->inEyeSight(player->position); - + enemy->update(elapsedTime); if (enemy->hasTarget) { @@ -209,23 +209,26 @@ 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; } + } } void World::addLevelObject(LevelObject* obj) diff --git a/worlds/small.json b/worlds/small.json index 685c370..66c7acc 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -13,7 +13,12 @@ "startposition": [ 20, 5, 20 ] }, "objects": [ ], - "enemies": [ ], + "enemies": [ + { + "file": "models/squid/Blooper.obj", + "pos": [ 20, 5, 10 ], + "scale": 0.01 + }], "crystals": [ { "file": "models/sphere/sphere.obj", @@ -21,7 +26,7 @@ }, { "file": "models/sphere/sphere.obj", - "pos": [ 45, 2, 31 ] + "pos": [ 45, 2, 31 ] } ] } \ No newline at end of file