Map is an array of HexTiles
This commit is contained in:
1 parent
3bcf26fc20
commit
013f0f30ab
4 files changed
+41
-16
No files matched your search
@@ -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;
|
||||
|
||||
+27
-9
@@ -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<bool>(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<HexTile> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -3,18 +3,22 @@
|
||||
#define MAP_H
|
||||
|
||||
#include <vector>
|
||||
#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<HexTile> 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
|
||||
Reference in new issue
Block a user