Mario: add option to make a block collision-less

This commit is contained in:
zv0n 2021-06-21 19:40:29 +02:00
parent a54d079fd2
commit b423ac7b8c
6 changed files with 19 additions and 2 deletions

View File

@ -155,6 +155,7 @@ const std::vector< uint64_t > possibleBlocks = {
const std::vector< uint64_t > possibleMods = { const std::vector< uint64_t > possibleMods = {
DESTRUCTIBLE_MODIFIER_ID, DESTRUCTIBLE_MODIFIER_ID,
BACKGROUND_MODIFIER_ID,
}; };
const std::vector< uint64_t > possibleCharacters = { 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 }, { CANNON_ID, &CANNON_SRC },
{ MARIO_ID, &MARIO_STANDING_SRC }, { MARIO_ID, &MARIO_STANDING_SRC },
{ DESTRUCTIBLE_MODIFIER_ID, &DESTRUCTIBLE_SRC }, { DESTRUCTIBLE_MODIFIER_ID, &DESTRUCTIBLE_SRC },
{ BACKGROUND_MODIFIER_ID, &BACKGROUND_SRC },
}; };
const std::unordered_map< uint64_t, uint64_t > block_flags = { 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 }, { POLE_BOTTOM_ID, HAS_COLLISION },
{ FLAG_ID, 0 }, { FLAG_ID, 0 },
{ STEP_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION }, { STEP_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION },
{ BRICK_ID, 0 }, { BRICK_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION },
{ BRICK_TOP_ID, 0 }, { BRICK_TOP_ID, CAN_BE_DESTROYED_FLAG | HAS_COLLISION },
{ SIDEWAY_PIPE_END_TOP_ID, HAS_COLLISION }, { SIDEWAY_PIPE_END_TOP_ID, HAS_COLLISION },
{ SIDEWAY_PIPE_END_BOTTOM_ID, HAS_COLLISION }, { SIDEWAY_PIPE_END_BOTTOM_ID, HAS_COLLISION },
{ SIDEWAY_PIPE_MIDDLE_TOP_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 }, { CANNON_ID, HAS_COLLISION },
{ MARIO_ID, 0 }, { MARIO_ID, 0 },
{ DESTRUCTIBLE_MODIFIER_ID, 0 }, { DESTRUCTIBLE_MODIFIER_ID, 0 },
{ BACKGROUND_MODIFIER_ID, 0 },
}; };
bool blockCanBeDestroyed(uint64_t id) { bool blockCanBeDestroyed(uint64_t id) {

View File

@ -111,15 +111,24 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
col->at( j ) = block; col->at( j ) = block;
} }
bool destructible = false; bool destructible = false;
bool removeCollisions = false;
if ( !editor && if ( !editor &&
block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID ) { block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID ) {
destructible = true; destructible = true;
} }
if ( !editor &&
block.getModifierId() == BACKGROUND_MODIFIER_ID ) {
destructible = false;
removeCollisions = true;
}
// TODO add modifiers to createTerrainBlock // TODO add modifiers to createTerrainBlock
if(block.getTerrainId() != 0) { if(block.getTerrainId() != 0) {
auto obj = createTerrainBlock( auto obj = createTerrainBlock(
block.getTerrainId(), block.getTerrainType(), block.getTerrainId(), block.getTerrainType(),
renderer, i, j, destructible, editor ); renderer, i, j, destructible, editor );
if(removeCollisions) {
obj->removeCollisions();
}
if ( obj != nullptr ) { if ( obj != nullptr ) {
if ( editor ) { if ( editor ) {
obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );

View File

@ -7,6 +7,8 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getId(); auto id = obj.getId();
switch ( id ) { switch ( id ) {
case FLOOR_ID: case FLOOR_ID:
case BRICK_ID:
case BRICK_TOP_ID:
case PIPE_LEFT_BOTTOM_ID: case PIPE_LEFT_BOTTOM_ID:
case PIPE_RIGHT_BOTTOM_ID: case PIPE_RIGHT_BOTTOM_ID:
case PIPE_LEFT_TOP_ID: case PIPE_LEFT_TOP_ID:

View File

@ -64,6 +64,7 @@
// modifiers // modifiers
#define DESTRUCTIBLE_MODIFIER_ID 0x01 #define DESTRUCTIBLE_MODIFIER_ID 0x01
#define BACKGROUND_MODIFIER_ID 0x02
// character IDs // character IDs
#define MARIO_ID 0x0F #define MARIO_ID 0x0F

View File

@ -80,6 +80,7 @@ const SDL_Rect CANNON_PEDESTAL_SRC = {256, 29, 16, 16};
const SDL_Rect CANNON_SRC = {256, 12, 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 DESTRUCTIBLE_SRC = {0, 0, 16, 16};
extern const SDL_Rect BACKGROUND_SRC = {16, 0, 16, 16};
const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = {0, 0}; const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = {0, 0};
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0}; const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0};

View File

@ -88,6 +88,7 @@ extern const SDL_Rect CANNON_PEDESTAL_SRC;
extern const SDL_Rect CANNON_SRC; extern const SDL_Rect CANNON_SRC;
//------------------ MODIFIERS ---------------------- //------------------ MODIFIERS ----------------------
extern const SDL_Rect DESTRUCTIBLE_SRC; extern const SDL_Rect DESTRUCTIBLE_SRC;
extern const SDL_Rect BACKGROUND_SRC;
extern const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT; extern const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT;
extern const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT; extern const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT;