]> git.localhorst.tv Git - orbi.git/blob - src/world/World.h
cdfc5d5d807072e2ba546639e9d3b0fe9b10d479
[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         void EntityCollision();
42
43 private:
44         Vector<int> size;
45         int count;
46
47         Vector<float> gravity;
48         Vector<float> terminal;
49         float fixSpeed;
50
51         std::vector<Tile> tiles;
52
53         std::list<Entity> entities;
54
55         mutable AABB tileShape;
56
57 };
58
59 }
60
61 #endif