]> git.localhorst.tv Git - orbi.git/blob - src/world/World.h
038f9dcce39db83362bea625a72f13384f041ef8
[orbi.git] / src / world / World.h
1 #ifndef ORBI_WORLD_H_
2 #define ORBI_WORLD_H_
3
4 #include "AABB.h"
5 #include "Entity.h"
6 #include "Tile.h"
7 #include "../graphics/Vector.h"
8
9 #include <list>
10 #include <vector>
11
12
13 namespace orbi {
14
15 class World {
16
17 public:
18         World(Vector<int> size);
19
20 public:
21         Vector<int> Size() const { return size; }
22
23 public:
24         void Update(float dt);
25
26         bool InBounds(Vector<int> pos) const
27                 { return pos.x > 0 && pos.y > 0 && pos.x < size.x && pos.y < size.y; }
28         int Index(Vector<int> pos) const { return pos.y * size.x + pos.x; }
29
30         Tile &TileAt(Vector<int> pos) { return tiles[Index(pos)]; }
31         const Tile &TileAt(Vector<int> pos) const { return tiles[Index(pos)]; }
32         void SetTile(Vector<int> pos, const Tile &t) { tiles[Index(pos)] = t; }
33         const AABB &TileShapeAt(Vector<int> pos) const;
34
35         const std::list<Entity> &Entities() const { return entities; }
36         Entity &AddEntity(const Entity &);
37
38 private:
39         void BoundsCollision(Entity &, float dt);
40         void TileCollision(Entity &, float dt);
41
42 private:
43         Vector<int> size;
44         int count;
45
46         Vector<float> gravity;
47         Vector<float> terminal;
48         float fixSpeed;
49
50         std::vector<Tile> tiles;
51
52         std::list<Entity> entities;
53
54         mutable AABB tileShape;
55
56 };
57
58 }
59
60 #endif