Skip to content
Snippets Groups Projects
Commit e9c193f4 authored by Alfred Burgess's avatar Alfred Burgess
Browse files

Created ability to move into a chunk location and visualise it as well

parent f6699243
Branches
No related merge requests found
......@@ -20,6 +20,7 @@ class Chunk
Chunk( int x, int y, int z );
~Chunk();
void generate();
void visualise() const;
std::string getString() const;
std::string getString( ChunkQuery format ) const;
std::string getLocationString() const;
......
......@@ -20,7 +20,9 @@ class WorldHex2D
~WorldHex2D();
void generateWorld();
Chunk* createChunkAtPoint( int s, int q, int r );
Chunk* getChunk( int chunkS, int chunkQ, int chunkR );
Chunk* moveInto( int chunkS, int chunkQ, int chunkR );
Chunk* getMidChunk();
int getMidS();
......
......@@ -4,7 +4,7 @@
CXX = g++
# Compiler flags
CXXFLAGS = -std=c++17 -Wall -Wreorder
CXXFLAGS = -std=c++17 -Wall -Wreorder -g
# Source directory
SRC_DIR = src
......@@ -50,6 +50,7 @@ clean:
run_tests: $(TEST_OBJ_FILES)
$(CC) $(CFLAGS) $(INC_DIRS) -o test_runner $^
./test_runner
$(BUILD_DIR)/%.o: $(TEST_DIR)/%.test.cpp
@mkdir -p $(@D)
......
......@@ -48,6 +48,7 @@ std::string Chunk::getAgeString() const { return std::to_string(this->age); }
std::string Chunk::getString( ChunkQuery format ) const
{return "rest";}
void Chunk::visualise() const { std::cout << this->getString() << std::endl; }
std::string Chunk::getString() const
{
std::string str = "Chunk Details:"
......
......@@ -20,7 +20,9 @@ int main() {
// Chunk* chunk = map.getMidChunk();
// std::cout << chunk->getString() << std::endl;
map.showChunk( 0, 0, 0 );
map.showChunk( -2, 1, 1 );
map.moveInto( -2, 1, 1 );
map.moveInto( -3, 2, 1 );
map.moveInto( 5, -2, -3 )->visualise();
map.visualise();
// Menu Loop
......
......@@ -14,6 +14,7 @@ WorldHex2D::WorldHex2D( uint8_t width, uint8_t height, uint8_t depth)
this->_logger.info( "Creating Hex Map" );
this->generateWorld();
}
WorldHex2D::~WorldHex2D()
{
this->_logger.info( "Cleaning world" );
......@@ -46,15 +47,28 @@ void WorldHex2D::generateWorld()
for( int r = this->_minR; r < this->_maxR; r++ )
{
if( s + q + r == 0 )
{
Chunk* chunk = new Chunk( s, q, r );
this->chunks_[s][q][r] = chunk;
}
{ this->createChunkAtPoint( s, q, r ); }
}
}
}
}
Chunk* WorldHex2D::createChunkAtPoint( int s, int q, int r )
{
Chunk* chunk = new Chunk( s, q, r );
this->chunks_[s][q][r] = chunk;
if( s < this->_minS ) this->_minS = s;
if( q < this->_minQ ) this->_minQ = q;
if( r < this->_minR ) this->_minR = r;
if( s > this->_maxS ) this->_maxS = s;
if( q > this->_maxQ ) this->_maxQ = q;
if( r > this->_maxR ) this->_maxR = r;
return chunk;
}
Chunk* WorldHex2D::showChunk( int s, int q, int r )
{
Chunk* chunk = this->getChunk( s, q, r );
......@@ -124,6 +138,27 @@ Chunk* WorldHex2D::getChunk( int chunkS, int chunkQ, int chunkR )
return nullptr;
}
Chunk* WorldHex2D::moveInto( int s, int q, int r )
{
Chunk * core = this->getChunk( s, q, r );
Chunk * tr = this->getChunk( s+1, q, r-1 );
Chunk * xr = this->getChunk( s, q+1, r-1 );
Chunk * br = this->getChunk( s-1, q+1, r );
Chunk * bl = this->getChunk( s-1, q, r+1 );
Chunk * xl = this->getChunk( s, q-1, r+1 );
Chunk * tl = this->getChunk( s+1, q-1, r );
if( !core ) core = this->createChunkAtPoint( s, q, r );
if( !tr )tr = this->createChunkAtPoint( s+1, q, r-1 );
if( !xr ) xr = this->createChunkAtPoint( s, q+1, r-1 );
if( !br ) br = this->createChunkAtPoint( s-1, q+1, r );
if( !bl ) bl = this->createChunkAtPoint( s-1, q, r+1 );
if( !xl ) xl = this->createChunkAtPoint( s, q-1, r+1 );
if( !tl ) tl = this->createChunkAtPoint( s+1, q-1, r );
return core;
}
int WorldHex2D::getMidS(){ return this->_width / 2; }
int WorldHex2D::getMidQ(){ return this->_height / 2; }
int WorldHex2D::getMidR(){ return this->_depth / 2; }
......@@ -137,13 +172,6 @@ Chunk* WorldHex2D::getMidChunk(){
void WorldHex2D::visualise()
{
this->_minS = this->_width / -2; // s
this->_minQ = this->_height / -2; // q
this->_minR = this->_depth / -2; // r
this->_maxS = ( this->_width / 2 ) + ( this->_width % 2 == 0 ? 0 : 1 );
this->_maxQ = ( this->_height / 2 ) + ( this->_height % 2 == 0 ? 0 : 1 );
this->_maxR = ( this->_depth / 2 ) + ( this->_depth % 2 == 0 ? 0 : 1 );
for( int s = this->_maxS; s >= this->_minS; s-- )
{
for( int i = abs(s); i > 0; i-- )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment