diff --git a/mario/blocks.cpp b/mario/blocks.cpp index 05d5c31..8485966 100644 --- a/mario/blocks.cpp +++ b/mario/blocks.cpp @@ -155,6 +155,7 @@ const std::vector< uint64_t > possibleBlocks = { const std::vector< uint64_t > possibleMods = { DESTRUCTIBLE_MODIFIER_ID, + BACKGROUND_MODIFIER_ID, }; const std::vector< uint64_t > possibleCharacters = { @@ -229,6 +230,7 @@ const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = { { CANNON_ID, &CANNON_SRC }, { MARIO_ID, &MARIO_STANDING_SRC }, { DESTRUCTIBLE_MODIFIER_ID, &DESTRUCTIBLE_SRC }, + { BACKGROUND_MODIFIER_ID, &BACKGROUND_SRC }, }; const std::unordered_map< uint64_t, uint64_t > block_flags = { @@ -264,8 +266,8 @@ const std::unordered_map< uint64_t, uint64_t > block_flags = { { POLE_BOTTOM_ID, HAS_COLLISION }, { FLAG_ID, 0 }, { STEP_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION }, - { BRICK_ID, 0 }, - { BRICK_TOP_ID, 0 }, + { BRICK_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION }, + { BRICK_TOP_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION }, { SIDEWAY_PIPE_END_TOP_ID, HAS_COLLISION }, { SIDEWAY_PIPE_END_BOTTOM_ID, HAS_COLLISION }, { SIDEWAY_PIPE_MIDDLE_TOP_ID, HAS_COLLISION }, @@ -292,6 +294,7 @@ const std::unordered_map< uint64_t, uint64_t > block_flags = { { CANNON_ID, HAS_COLLISION }, { MARIO_ID, 0 }, { DESTRUCTIBLE_MODIFIER_ID, 0 }, + { BACKGROUND_MODIFIER_ID, 0 }, }; bool blockCanBeDestroyed(uint64_t id) { diff --git a/mario/maploader.cpp b/mario/maploader.cpp index dcdcab2..12c684d 100644 --- a/mario/maploader.cpp +++ b/mario/maploader.cpp @@ -111,15 +111,24 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene, col->at( j ) = block; } bool destructible = false; + bool removeCollisions = false; if ( !editor && block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID ) { destructible = true; } + if ( !editor && + block.getModifierId() == BACKGROUND_MODIFIER_ID ) { + destructible = false; + removeCollisions = true; + } // TODO add modifiers to createTerrainBlock if(block.getTerrainId() != 0) { auto obj = createTerrainBlock( block.getTerrainId(), block.getTerrainType(), renderer, i, j, destructible, editor ); + if(removeCollisions) { + obj->removeCollisions(); + } if ( obj != nullptr ) { if ( editor ) { obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); diff --git a/mario/mario_visitor.cpp b/mario/mario_visitor.cpp index 9df0cd7..79f5311 100644 --- a/mario/mario_visitor.cpp +++ b/mario/mario_visitor.cpp @@ -7,6 +7,8 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) { auto id = obj.getId(); switch ( id ) { case FLOOR_ID: + case BRICK_ID: + case BRICK_TOP_ID: case PIPE_LEFT_BOTTOM_ID: case PIPE_RIGHT_BOTTOM_ID: case PIPE_LEFT_TOP_ID: diff --git a/mario/objectids.hpp b/mario/objectids.hpp index 4c627f6..f363813 100644 --- a/mario/objectids.hpp +++ b/mario/objectids.hpp @@ -64,6 +64,7 @@ // modifiers #define DESTRUCTIBLE_MODIFIER_ID 0x01 +#define BACKGROUND_MODIFIER_ID 0x02 // character IDs #define MARIO_ID 0x0F diff --git a/mario/sprites.cpp b/mario/sprites.cpp index ca694a3..345dc31 100644 --- a/mario/sprites.cpp +++ b/mario/sprites.cpp @@ -80,6 +80,7 @@ const SDL_Rect CANNON_PEDESTAL_SRC = {256, 29, 16, 16}; const SDL_Rect CANNON_SRC = {256, 12, 16, 16}; extern const SDL_Rect DESTRUCTIBLE_SRC = {0, 0, 16, 16}; +extern const SDL_Rect BACKGROUND_SRC = {16, 0, 16, 16}; const SDLPP::Vec2D OVERWORLD_SHIFT = {0, 0}; const SDLPP::Vec2D UNDERWORLD_SHIFT = {274, 0}; diff --git a/mario/sprites.hpp b/mario/sprites.hpp index 7fb5e2c..6a1a558 100644 --- a/mario/sprites.hpp +++ b/mario/sprites.hpp @@ -88,6 +88,7 @@ extern const SDL_Rect CANNON_PEDESTAL_SRC; extern const SDL_Rect CANNON_SRC; //------------------ MODIFIERS ---------------------- extern const SDL_Rect DESTRUCTIBLE_SRC; +extern const SDL_Rect BACKGROUND_SRC; extern const SDLPP::Vec2D OVERWORLD_SHIFT; extern const SDLPP::Vec2D UNDERWORLD_SHIFT;