X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorld.cpp;h=7276ece6fdaa5b16519e3e24c0724e16a6b2d7f8;hb=962405ec344818a7f6850d243feca7989ae5d41b;hp=f4d80f95476beab74a2e32eac354f5f10c062659;hpb=dbc08d84d9de1a77cba0dd97e4701f4ac99d056e;p=orbi.git diff --git a/src/world/World.cpp b/src/world/World.cpp index f4d80f9..7276ece 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -1,5 +1,6 @@ #include "World.h" +#include "Collision.h" #include "../graphics/const.h" @@ -50,17 +51,15 @@ void World::Update(float dt) { for (Vector pos(cBegin); pos.y < cEnd.y; ++pos.y) { for (pos.x = cBegin.x; pos.x < cEnd.x; ++pos.x) { if (!TileAt(pos).IsSolid()) continue; - const AABB tBounds(pos, Vector(1, 1)); - Vector pos; - Vector norm; - Vector depth; - if (!e.bounds.Intersects(tBounds, pos, norm, depth)) { + const AABB &tBounds = TileShapeAt(pos); + Collision coll; + if (!e.bounds.Intersects(tBounds, coll)) { continue; } - if (depth.x < min.x) min.x = depth.x; - if (depth.x > max.x) max.x = depth.x; - if (depth.y < min.y) min.y = depth.y; - if (depth.y > max.y) max.y = depth.y; + if (coll.depth.x < min.x) min.x = coll.depth.x; + if (coll.depth.x > max.x) max.x = coll.depth.x; + if (coll.depth.y < min.y) min.y = coll.depth.y; + if (coll.depth.y > max.y) max.y = coll.depth.y; } } @@ -93,6 +92,12 @@ void World::Update(float dt) { } +const AABB &World::TileShapeAt(Vector pos) const { + tileShape = AABB(pos, Vector(1, 1)); + return tileShape; +} + + Entity &World::AddEntity(const Entity &e) { entities.emplace_back(e); return entities.back();