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

Added mouse control

parent 7bc739ec
Branches
No related merge requests found
......@@ -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;
......
......@@ -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;
......
......@@ -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) ); }
}
}
......@@ -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 )
......
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