From e283b3622936cd4280165d578284f0aed0ae53a8 Mon Sep 17 00:00:00 2001 From: zvon Date: Sat, 7 Aug 2021 21:59:06 +0200 Subject: [PATCH] Mario: set scene's background objects --- mario/main.cpp | 12 ++++++++++++ mario/visitors/mario_visitor.hpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mario/main.cpp b/mario/main.cpp index 9c4b3c2..2662f45 100644 --- a/mario/main.cpp +++ b/mario/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "global_vars.hpp" #include "objectids.hpp" #include "blocks.hpp" @@ -251,6 +252,17 @@ int main() { scene->moveEverything( -mario->getDoubleRect().first.getX() + 0.2, 0 ); update = true; moving_objects.push_back(mario); + + std::unordered_set background_ids = { + HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_RIGHT_ID, HILL_DOTS_LEFT_ID, + HILL_FILL_ID, HILL_TOP_ID, BUSH_LEFT_ID, BUSH_MIDDLE_ID, BUSH_RIGHT_ID, + CLOUD_LEFT_BOTTOM_ID, CLOUD_MIDDLE_BOTTOM_ID, CLOUD_RIGHT_BOTTOM_ID, + CLOUD_LEFT_TOP_ID, CLOUD_MIDDLE_TOP_ID, CLOUD_RIGHT_TOP_ID, + CASTLE_LEFT_ID, CASTLE_RIGHT_ID, CASTLE_BLACK_ID, CASTLE_ENTRY_ID, + CASTLE_TOWER_ID, CASTLE_TOWER_FILLED_ID, WATER_TOP_ID, WATER_FILL_ID }; + scene->setBackgroundObjectIDs(background_ids); + scene->updateBackgroundObjectZIndex(); + while ( !quit ) { SDL_PumpEvents(); SDL_framerateDelay( &gFPS ); diff --git a/mario/visitors/mario_visitor.hpp b/mario/visitors/mario_visitor.hpp index 9917c6d..43c58bf 100644 --- a/mario/visitors/mario_visitor.hpp +++ b/mario/visitors/mario_visitor.hpp @@ -79,7 +79,7 @@ public: // TODO remove coin_block? coin_block = coin; _scene.addObject(coin); - _scene.setZIndex(coin, 1); + _scene.moveZJustAboveBackground(coin); } bool hasCoinBlock() { @@ -96,7 +96,7 @@ public: void setMushroomBlock(std::shared_ptr &mushroom) { _scene.addObject(mushroom); - _scene.setZIndex(mushroom, 1); + _scene.moveZJustAboveBackground(mushroom); _moving_objects.push_back(mushroom); }