diff --git a/src/client/Client.cc b/src/client/Client.cc index 1735b7f..c8e818c 100755 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -51,8 +51,8 @@ Client::Client(bool fullscreen, bool compatibility_context, initgl(); resize_window(m_window->getSize().x, m_window->getSize().y); m_player = new Player(); - m_player->x = 1250; - m_player->y = 1000; + m_player->x = 0; + m_player->y = 0; m_player->direction = M_PI_2; GLProgram::AttributeBinding obj_attrib_bindings[] = { {0, "pos"}, @@ -262,8 +262,8 @@ void Client::draw_map() if (m_map.tile_present(x, y)) { m_modelview.push(); - float cx = x * tile_size * HEX_WIDTH_TO_HEIGHT * 0.75; - float cy = (y + ((x & 1) ? 0.5 : 0.0)) * tile_size; + float cx = m_map.get_tile(x, y)->get_x(); + float cy = m_map.get_tile(x, y)->get_y(); m_modelview.translate(cx, cy, 0); m_modelview.to_uniform(uniform_locations[6]); for (map::iterator it = diff --git a/src/common/HexTile.h b/src/common/HexTile.h index 982876e..b4c1beb 100644 --- a/src/common/HexTile.h +++ b/src/common/HexTile.h @@ -9,6 +9,9 @@ class HexTile public: HexTile(float x, float y, float size); bool point_within(float x, float y); + float get_x() { return m_x; } + float get_y() { return m_y; } + float get_size() { return m_size; } protected: float m_x; float m_y; diff --git a/src/common/Map.cc b/src/common/Map.cc index 3f4bbc7..ea901b3 100755 --- a/src/common/Map.cc +++ b/src/common/Map.cc @@ -4,20 +4,38 @@ using namespace std; -Map::Map(int width, int height) +Map::Map(int width, int height, float tile_size) { m_width = width; m_height = height; - m_grid = vector< vector< bool > >(height, vector(width)); + m_tile_size = tile_size; + + /* construction of default map */ + float span_x = HEX_WIDTH_TO_HEIGHT * 0.75 * tile_size; + float offset_x = -span_x * (width / 2.0); + float offset_y = -tile_size * (height / 2.0); + + HexTile outer_out(0, 0, 0.85 * span_x * width); + HexTile outer_in(0, 0, 0.5 * span_x * width); + HexTile inner_out(0, 0, 0.30 * span_x * width); - /* construction of default map - temporary */ - HexTile ht(width / 2.0, height / 2.0, 0.8 * height / 2.0); for (int i = 0; i < height; i++) + { + m_grid.push_back(vector< refptr< HexTile > >()); for (int j = 0; j < width; j++) - m_grid[i][j] = ht.point_within(j + 0.5, i + 0.5); -} + { + refptr ht; + float x = j * span_x + offset_x; + float y = (i + ((j & 1) ? 0.5 : 0.0)) * tile_size + offset_y; -bool Map::tile_present(int x, int y) -{ - return m_grid[y][x]; + if (inner_out.point_within(y, x) + || (outer_out.point_within(y, x) + && !outer_in.point_within(y, x))) + { + ht = new HexTile(x, y, tile_size); + } + + m_grid[i].push_back(ht); + } + } } diff --git a/src/common/Map.h b/src/common/Map.h index d9a2327..64e898d 100755 --- a/src/common/Map.h +++ b/src/common/Map.h @@ -3,18 +3,22 @@ #define MAP_H #include +#include "refptr.h" +#include "HexTile.h" class Map { public: - Map(int width=50, int height=50); - bool tile_present(int x, int y); + Map(int width=21, int height=21, float tile_size=50); + bool tile_present(int x, int y) { return !m_grid[y][x].isNull(); } + refptr get_tile(int x, int y) { return m_grid[y][x]; } int get_width() { return m_width; } int get_height() { return m_height; } protected: int m_width; int m_height; - std::vector< std::vector< bool > > m_grid; + float m_tile_size; + std::vector< std::vector< refptr< HexTile > > > m_grid; }; #endif