diff --git a/include/window.h b/include/window.h index d1acdcf2c80f366325c21f6880017950422f1955..9c99ba2a06a304b3d1b41333396abb58958e3de4 100644 --- a/include/window.h +++ b/include/window.h @@ -64,6 +64,7 @@ class Window // void _drawLine( Vec2 from, Vec2 to ); void _drawPoint( Vec2 point ); // void _drawPoint( int16_t x, int16_t y ); + void _drawHex( Vec2 point, uint16_t radius ); SDL_Rect _createViewport( int16_t x, int16_t y, int16_t w, int16_t h ); diff --git a/src/window.cpp b/src/window.cpp index 944591cf45888a1ca58b1ffeb08711c3d3520b10..118b7284e4c0704c4cd179cd82be9bdc065df369 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -93,7 +93,9 @@ void Window::update() { SDL_Rect bg = this->_createViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); this->_background->render( {0,0}, this->_renderer ); this->_character->render( {SCREEN_HEIGHT/3,SCREEN_HEIGHT/3}, this->_renderer ); + SDL_Rect core = this->_createViewport( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); + // Render Example Primatives this->_drawRect( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); this->_drawRect( 0, 0, 10, 10 ); @@ -103,7 +105,22 @@ void Window::update() { this->_drawPoint( { SCREEN_WIDTH / 2, i } ); } - // SDL_Rect overlay = this->_createViewport( SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); + SDL_Rect overlay = this->_createViewport( 0, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); + const int hexRad = 10; + const int hexSpacing = 1; + const int drawHexRad = hexRad + hexSpacing; + for( int i = 0; i < 20; i++ ) + { + for( int j = 0; j < 20; j++ ) + { + this->_drawHex( { + i * ( drawHexRad * sqrt(3) ) + ( j % 2 == 0 ? 0 : ( drawHexRad * sqrt(3) ) / 2 ), + j * ( drawHexRad * 3 / 2 ) + } , hexRad ); + + } + + } // SDL_RenderCopy( this->_renderer, this->_activeTexture, NULL, NULL ); @@ -131,6 +148,18 @@ void Window::_drawPoint( Vec2 point ) SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0xFF, 0x00, 0xFF ); SDL_RenderDrawPoint( this->_renderer, point.x, point.y ); } +void Window::_drawHex( Vec2 point, uint16_t radius ) +{ + const float halfWidth = (sqrt(3) * radius) / 2.0; + const float quaterHeight = radius / 2.0; + this->_drawLine( (int)point.x, (int)point.y + radius, (int)point.x + halfWidth, (int)point.y + quaterHeight ); + this->_drawLine( (int)point.x + halfWidth, (int)point.y + quaterHeight, (int)point.x + halfWidth, (int)point.y - quaterHeight ); + this->_drawLine( (int)point.x + halfWidth, (int)point.y - quaterHeight, (int)point.x, (int)point.y - radius ); + + this->_drawLine( (int)point.x, (int)point.y + radius, (int)point.x - halfWidth, (int)point.y + quaterHeight ); + this->_drawLine( (int)point.x - halfWidth, (int)point.y + quaterHeight, (int)point.x - halfWidth, (int)point.y - quaterHeight ); + this->_drawLine( (int)point.x - halfWidth, (int)point.y - quaterHeight, (int)point.x, (int)point.y - radius ); +} void Window::spawn()