3 #include "../graphics/const.h"
8 World::World(Vector<int> size)
10 , count(size.x * size.y)
18 void World::Update(float dt) {
19 for (Entity &e : entities) {
20 e.Update(dt, gravity, terminal);
23 const AABB &b = e.bounds;
25 // world bounds collision
27 e.Move(Vector<float>(0, -b.Top()));
30 if (b.Right() > size.x) {
31 e.Move(Vector<float>(size.x - b.Right(), 0));
34 if (b.Bottom() > size.y) {
35 e.Move(Vector<float>(0, size.y - b.Bottom()));
40 e.Move(Vector<float>(-b.Left(), 0));
44 const Vector<int> cBegin(b.Left(), b.Top());
45 const Vector<int> cEnd(b.Right() + 1, b.Bottom() + 1);
50 for (Vector<int> pos(cBegin); pos.y < cEnd.y; ++pos.y) {
51 for (pos.x = cBegin.x; pos.x < cEnd.x; ++pos.x) {
52 if (!TileAt(pos).IsSolid()) continue;
53 const AABB tBounds(pos, Vector<float>(1, 1));
57 if (!e.bounds.Intersects(tBounds, pos, norm, depth)) {
60 if (depth.x < min.x) min.x = depth.x;
61 if (depth.x > max.x) max.x = depth.x;
62 if (depth.y < min.y) min.y = depth.y;
63 if (depth.y > max.y) max.y = depth.y;
96 Entity &World::AddEntity(const Entity &e) {
97 entities.emplace_back(e);
98 return entities.back();