Mario: add block's land type when creating block

This commit is contained in:
zvon 2021-05-31 16:07:55 +02:00
parent 808f392119
commit 26cbdd0f8e

View File

@ -229,11 +229,12 @@ const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = {
std::shared_ptr< SDLPP::RectangleRender > std::shared_ptr< SDLPP::RectangleRender >
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y, createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src, std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src,
uint64_t id, bool collision = false, bool destructible = false ) { uint64_t id, LandType::Value land_type, bool collision = false, bool destructible = false ) {
auto block = std::make_shared< MarioBlock >( x, y, renderer, texture, src, destructible ); auto block = std::make_shared< MarioBlock >( x, y, renderer, texture, src, destructible );
block->setId( id ); block->setId( id );
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ); block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
block->setStatic(); block->setStatic();
block->setType(land_type);
if ( collision ) if ( collision )
block->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) ); block->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
return block; return block;
@ -269,7 +270,7 @@ createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Texture > texture, std::shared_ptr< SDLPP::Texture > texture,
bool collision, bool destructible ) { bool collision, bool destructible ) {
return createBlock( renderer, x, y, texture, return createBlock( renderer, x, y, texture,
getSourceRectByID( block_id, type ), block_id, getSourceRectByID( block_id, type ), block_id, type,
collision, destructible ); collision, destructible );
} }
std::shared_ptr< SDLPP::RectangleRender > std::shared_ptr< SDLPP::RectangleRender >
@ -302,7 +303,7 @@ createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer,
int x, int y ) { int x, int y ) {
// TODO add type additions // TODO add type additions
auto mario = createBlock( renderer, x, y, g_mario_texture, auto mario = createBlock( renderer, x, y, g_mario_texture,
MARIO_STANDING_SRC, MARIO_ID, true ); MARIO_STANDING_SRC, MARIO_ID, type, true );
dynamic_cast< MarioBlock & >( *mario ).setTerrain( false ); dynamic_cast< MarioBlock & >( *mario ).setTerrain( false );
return mario; return mario;
} }