Mario editor: use visitors
This commit is contained in:
+17
-7
@@ -4,6 +4,17 @@
|
||||
#include "sprites.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
MarioBlock::MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src) : RectangleRender( x * BLOCK_SIZE, 1 - (16-y) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {}
|
||||
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
|
||||
if(!_tool && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
|
||||
destroy();
|
||||
}
|
||||
visitor.visit(*this);
|
||||
}
|
||||
void MarioBlock::setTool(bool tool) {
|
||||
_tool = tool;
|
||||
}
|
||||
|
||||
const std::vector< uint64_t > possibleBlocks = { FLOOR_ID,
|
||||
HILL_INCLINE_ID,
|
||||
HILL_DECLINE_ID,
|
||||
@@ -33,11 +44,10 @@ const std::unordered_map<uint64_t, const SDL_Rect*> block_mapping = {
|
||||
};
|
||||
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, double x, double y,
|
||||
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< SDLPP::RectangleRender >(
|
||||
x, y, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src );
|
||||
auto block = std::make_shared<MarioBlock>(x, y, renderer, texture, src);
|
||||
block->setId( id );
|
||||
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
block->setStatic();
|
||||
@@ -70,7 +80,7 @@ SDL_Rect getSourceRectByID( uint64_t id, BlockType type ) {
|
||||
}
|
||||
return ret_src;
|
||||
}
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
return createBlock( renderer, x, y, texture,
|
||||
getSourceRectByID( block_id, type ), block_id,
|
||||
collision );
|
||||
@@ -81,8 +91,8 @@ std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, B
|
||||
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createTerrainBlock( uint64_t block_id, BlockType type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, double x,
|
||||
double y, bool collision ) {
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, int x,
|
||||
int y, bool collision ) {
|
||||
return createTerrainBlock(block_id, type, renderer, x, y, g_terrain_texture, collision);
|
||||
}
|
||||
|
||||
@@ -93,7 +103,7 @@ createTerrainBlock( uint64_t block_id, BlockType type,
|
||||
return createTerrainBlock(block_id, type, renderer, g_terrain_texture, collision);
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y ) {
|
||||
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
|
||||
//TODO add type additions
|
||||
return createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user