Trying to switch to more object-oriented

This commit is contained in:
2021-03-12 22:33:46 +01:00
parent fbe122a5b9
commit 258ce51cfe
32 changed files with 693 additions and 249 deletions
+6 -5
View File
@@ -20,11 +20,11 @@ void Scene::addObject( const std::shared_ptr< RenderObject > &obj ) {
} else {
auto rect = obj->getDoubleRect();
auto leftmost_rect = leftmost_obj->getDoubleRect();
if ( rect.first.first < leftmost_rect.first.first )
if ( rect.first.getX() < leftmost_rect.first.getX() )
leftmost_obj = obj;
auto rightmost_rect = rightmost_obj->getDoubleRect();
if ( rect.first.first + rect.second.first >
rightmost_rect.first.first + rightmost_rect.second.first )
if ( rect.first.getX() + rect.second.getX() >
rightmost_rect.first.getX() + rightmost_rect.second.getX() )
rightmost_obj = obj;
}
}
@@ -123,8 +123,9 @@ void Scene::renderScene( bool clear_renderer ) {
if ( background && background->getTexturePtr() )
SDL_RenderCopy( renderer->getRendererPtr(), background->getTexturePtr(),
NULL, NULL );
for ( const auto &x : render_objects )
for ( const auto &x : render_objects ) {
x->render();
}
}
void Scene::presentScene() {
SDL_RenderPresent( renderer->getRendererPtr() );
@@ -153,7 +154,7 @@ void Scene::moveEverything( double x, double y ) {
if ( obj->getPermanent() )
continue;
auto curPos = obj->getDoubleRect();
obj->setPos( curPos.first.first + x, curPos.first.second + y );
obj->setPos( curPos.first.getX() + x, curPos.first.getY() + y );
}
}
const std::shared_ptr< RenderObject > &Scene::leftmost() {