From f2fbdbf7866d01d8fec6548f354f91ae565ce89e Mon Sep 17 00:00:00 2001
From: Alfred Burgess <alfred.burgess95@gmail.com>
Date: Sun, 7 Jan 2024 19:12:09 +0800
Subject: [PATCH] Added mouse control

---
 include/game-engine.h  |  2 ++
 src/entity-manager.cpp |  9 +++++++--
 src/game-engine.cpp    | 13 +++++++++----
 src/window.cpp         | 10 +++++++++-
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/include/game-engine.h b/include/game-engine.h
index e57b83f..c71d298 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 b19b6ea..1630431 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 18e695b..44b5ce8 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 abe9cd5..68f69dc 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 )
-- 
GitLab