From 9e7d64d052eabcf40d85c3e903aaba44903a380a Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sat, 7 Oct 2017 08:03:44 +0200 Subject: Initial commit. --- src/common.hpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/common.hpp (limited to 'src/common.hpp') 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 +#include +#include +#include +#include + +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 entities; + public: + bool empty = true; + tile_t tiles[SECTOR_SIZE * SECTOR_SIZE]; + + void generate(sector_index_t index); + }; + + class world_t { + std::map 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); + }; +} -- cgit