summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-07 08:03:44 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-07 08:03:44 +0200
commit9e7d64d052eabcf40d85c3e903aaba44903a380a (patch)
tree0a3a2c7f53884bd035b54812a77d493be058f43c /src/common.hpp
Initial commit.
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/common.hpp b/src/common.hpp
new file mode 100644
index 0000000..aaf1cad
--- /dev/null
+++ b/src/common.hpp
@@ -0,0 +1,70 @@
+#include <iostream>
+#include <cstdint>
+#include <cmath>
+#include <map>
+#include <SFML/Graphics.hpp>
+
+namespace game {
+ class entity_t {
+ virtual void render(sf::RenderWindow *window) = 0;
+ };
+}
+
+namespace world {
+ #define SECTOR_SIZE 16
+
+ class tile_t {
+ public:
+ char type;
+ };
+
+ class sector_index_t {
+ public:
+ int64_t x, y;
+
+ sector_index_t ();
+ sector_index_t (int64_t x_, int64_t y_);
+ bool operator<(sector_index_t B) const;
+ };
+
+ class sector_t {
+ std::vector<game::entity_t*> entities;
+ public:
+ bool empty = true;
+ tile_t tiles[SECTOR_SIZE * SECTOR_SIZE];
+
+ void generate(sector_index_t index);
+ };
+
+ class world_t {
+ std::map<sector_index_t, sector_t> sectors;
+
+ public:
+ sector_t *get_sector(sector_index_t index);
+ tile_t *get_tile(ssize_t x, ssize_t y);
+
+ void link(game::entity_t *entity);
+ void unlink(game::entity_t *entity);
+ void render(sf::RenderWindow *window);
+ };
+}
+
+namespace interface {
+ class state_t {
+ struct {
+ sf::Vector2f center;
+ int target_zoom = 3;
+ float zoom = 3.0f;
+ bool dragging = false;
+ sf::Vector2f drag_ref;
+ } camera;
+
+ public:
+ sf::RenderWindow *window;
+ world::world_t *world;
+
+ state_t(sf::RenderWindow *window_, world::world_t *world_);
+ void tick(void);
+ void render(void);
+ };
+}