4 #include "../graphics/const.h"
9 World::World(Vector<int> size)
11 , count(size.x * size.y)
19 void World::Update(float dt) {
20 for (Entity &e : entities) {
21 e.Update(dt, gravity, terminal);
24 const AABB &b = e.bounds;
26 // world bounds collision
28 e.Move(Vector<float>(0, -b.Top()));
31 if (b.Right() > size.x) {
32 e.Move(Vector<float>(size.x - b.Right(), 0));
35 if (b.Bottom() > size.y) {
36 e.Move(Vector<float>(0, size.y - b.Bottom()));
41 e.Move(Vector<float>(-b.Left(), 0));
45 const Vector<int> cBegin(b.Left(), b.Top());
46 const Vector<int> cEnd(b.Right() + 1, b.Bottom() + 1);
51 for (Vector<int> pos(cBegin); pos.y < cEnd.y; ++pos.y) {
52 for (pos.x = cBegin.x; pos.x < cEnd.x; ++pos.x) {
53 if (!TileAt(pos).IsSolid()) continue;
54 const AABB &tBounds = TileShapeAt(pos);
56 if (!e.bounds.Intersects(tBounds, coll)) {
59 if (coll.depth.x < min.x) min.x = coll.depth.x;
60 if (coll.depth.x > max.x) max.x = coll.depth.x;
61 if (coll.depth.y < min.y) min.y = coll.depth.y;
62 if (coll.depth.y > max.y) max.y = coll.depth.y;
95 const AABB &World::TileShapeAt(Vector<int> pos) const {
96 tileShape = AABB(pos, Vector<float>(1, 1));
101 Entity &World::AddEntity(const Entity &e) {
102 entities.emplace_back(e);
103 return entities.back();