diff --git a/include/game-engine.h b/include/game-engine.h index e57b83f5974c342b951c4d109098b49f06c7392e..c71d2987dd9e17120930bc0d58725890f159b0b9 100644 --- a/include/game-engine.h +++ b/include/game-engine.h @@ -53,6 +53,8 @@ class GameEngine std::time_t _frametime = 0; EntityManager _entityManager; Logger& _logger; + int m_mX = 0; + int m_mY = 0; bool _paused = false; diff --git a/src/entity-manager.cpp b/src/entity-manager.cpp index b19b6ea46acecd8de0eb82c6d3cc63c5dd3dde9e..163043110c2ed7e87f6c841193d197e457b0ca81 100644 --- a/src/entity-manager.cpp +++ b/src/entity-manager.cpp @@ -5,13 +5,18 @@ EntityManager::EntityManager() { this->_logger.info( "Creating entity manager" ); } EntityManager::~EntityManager() { - // while( auto entity = ) - // { delete entity; } + while( this->_entities.size() ) + { + auto entity = this->_entities.back(); + this->_entities.pop_back(); + delete &entity; + } this->_logger.info( "Deleting entity manager" ); } std::shared_ptr<Entity> EntityManager::addEntity( const std::string& tag ) { + this->_logger.info( "Adding entity with tag "+tag ); auto entity = std::shared_ptr< Entity >( new Entity( tag, this->nextId() ) ); this->_entitiesToAdd.push_back( entity ); return entity; diff --git a/src/game-engine.cpp b/src/game-engine.cpp index 18e695b6d9ff953110ef32e054e140ae94a1431c..44b5ce8cb57e03cee12ab7a09fcfe5da4c5a2b73 100644 --- a/src/game-engine.cpp +++ b/src/game-engine.cpp @@ -59,11 +59,11 @@ void GameEngine::update() if ( ++this->_frame % 1 == 0 ) { std::time_t cTime = std::chrono::high_resolution_clock::to_time_t(now); - size_t delTime = cTime - this->_frametime; + // size_t delTime = cTime - this->_frametime; this->_frametime = cTime; - std::cout << cTime << std::endl; + // std::cout << cTime << std::endl; // printf( "Frame: %i at %.2f fps\n", this->_frame, delTime == 0 ? 0.0 : 1.0 / delTime ); - printf( "Frame: %i at %.2f fps over %i s\n", this->_frame, delTime == 0 ? 0.0 : 1.0 / delTime, delTime ); + // printf( "Frame: %i at %.2f fps over %i s\n", this->_frame, delTime == 0 ? 0.0 : 1.0 / delTime, delTime ); } this->_window->update(); } @@ -81,6 +81,11 @@ void GameEngine::handleInput() case SDL_QUIT: this->close(); break; case SDLK_ESCAPE: this->close(); break; } - } + } else if( + e.type == SDL_MOUSEMOTION || + e.type == SDL_MOUSEBUTTONDOWN || + e.type == SDL_MOUSEBUTTONUP + ) { SDL_GetMouseState( &(this->m_mX), &(this->m_mY) ); } } + } diff --git a/src/window.cpp b/src/window.cpp index abe9cd5ca098fdfdeb9f48164a4dffa13e2a367c..68f69dc59981ce92864655a6f24506db524c4ee0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -21,7 +21,7 @@ Window::Window() this->_fontFile = new cFontfile(); this->_textureSprite = new cTexture(); - this->_screenModulation = Colour( 0x88, 0x88, 0x88, 0xFF ); + this->_screenModulation = Colour( 0x88, 0x99, 0xff, 0xFF ); } Window::~Window() { @@ -95,6 +95,8 @@ void Window::loadMedia() this->_fontFile->setColour( 255, 255, 0 ); if( this->_water->loadFromFile( "assets/water_animated.png" ) ) { + this->_water->setAlpha( 164 ); + // Set Frame 1 this->_waterTicks[ 0 ].x = 0; this->_waterTicks[ 0 ].y = 0; @@ -121,29 +123,35 @@ void Window::loadMedia() } if( this->_textureSprite->loadFromFile( "assets/texture_test.png" ) ) { + this->_textureSprite->setAlpha( 128 ); + //Set top left sprite this->_sprites[ 0 ].x = 0; this->_sprites[ 0 ].y = 0; this->_sprites[ 0 ].w = 100; this->_sprites[ 0 ].h = 100; + // this->_sprites[ 0 ].setAlpha( 64 ); //Set top right sprite this->_sprites[ 1 ].x = 100; this->_sprites[ 1 ].y = 0; this->_sprites[ 1 ].w = 100; this->_sprites[ 1 ].h = 100; + // this->_sprites[ 1 ].setAlpha( 128 ); //Set bottom left sprite this->_sprites[ 2 ].x = 0; this->_sprites[ 2 ].y = 100; this->_sprites[ 2 ].w = 100; this->_sprites[ 2 ].h = 100; + // this->_sprites[ 2 ].setAlpha( 192 ); //Set bottom right sprite this->_sprites[ 3 ].x = 100; this->_sprites[ 3 ].y = 100; this->_sprites[ 3 ].w = 100; this->_sprites[ 3 ].h = 100; + // this->_sprites[ 3 ].setAlpha( 255 ); } } void Window::loadMedia( std::string path )