Mario: destructible blocks

This commit is contained in:
2021-05-24 00:07:40 +02:00
parent bea479bf72
commit b75b44201a
4 changed files with 28 additions and 19 deletions
+17 -12
View File
@@ -8,9 +8,11 @@
MarioBlock::MarioBlock( int x, int y,
std::shared_ptr< SDLPP::Renderer > renderer,
std::shared_ptr< SDLPP::Texture > texture,
SDL_Rect src )
SDL_Rect src, bool destructible )
: RectangleRender( x * BLOCK_SIZE, 1 - ( 16 - y ) * BLOCK_SIZE,
BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {}
BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {
_destructible = destructible;
}
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
if ( !_tool && _terrain &&
visitor.getVisitorType() == VisitorType::Terrain ) {
@@ -20,6 +22,9 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
visitor.getVisitorType() == VisitorType::Modifier ) {
destroy();
}
if(visitor.getFromId() == MARIO_TOP_DETECT && _destructible) {
destroy();
}
visitor.visit( *this );
}
void MarioBlock::setTool( bool tool ) {
@@ -157,8 +162,8 @@ const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = {
std::shared_ptr< SDLPP::RectangleRender >
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src,
uint64_t id, bool collision = false ) {
auto block = std::make_shared< MarioBlock >( x, y, renderer, texture, src );
uint64_t id, bool collision = false, bool destructible = false ) {
auto block = std::make_shared< MarioBlock >( x, y, renderer, texture, src, destructible );
block->setId( id );
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
block->setStatic();
@@ -195,34 +200,34 @@ std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
std::shared_ptr< SDLPP::Texture > texture,
bool collision ) {
bool collision, bool destructible ) {
return createBlock( renderer, x, y, texture,
getSourceRectByID( block_id, type ), block_id,
collision );
collision, destructible );
}
std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer,
std::shared_ptr< SDLPP::Texture > texture,
bool collision ) {
bool collision, bool destructible ) {
return createTerrainBlock( block_id, type, renderer, 0, 0, texture,
collision );
collision, destructible );
}
std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
bool collision ) {
bool collision, bool destructible ) {
return createTerrainBlock( block_id, type, renderer, x, y,
g_terrain_texture, collision );
g_terrain_texture, collision, destructible );
}
std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer,
bool collision ) {
bool collision, bool destructible ) {
return createTerrainBlock( block_id, type, renderer, g_terrain_texture,
collision );
collision, destructible );
}
std::shared_ptr< SDLPP::RectangleRender >