Mario editor: don't delete characters when changing terrain

This commit is contained in:
zvon 2021-05-02 14:43:15 +02:00
parent 8b8f3b7f06
commit ad7f737e16
3 changed files with 16 additions and 7 deletions

View File

@ -6,7 +6,8 @@
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 ) {} 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 ) { void MarioBlock::visit( SDLPP::Visitor &visitor ) {
if(!_tool && visitor.getVisitorType() == TOOL_VISITOR_TYPE) { // TODO if character don't
if(!_tool && !_character && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
destroy(); destroy();
} }
visitor.visit(*this); visitor.visit(*this);
@ -14,6 +15,9 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
void MarioBlock::setTool(bool tool) { void MarioBlock::setTool(bool tool) {
_tool = tool; _tool = tool;
} }
void MarioBlock::setCharacter(bool character) {
_character = character;
}
const std::vector< uint64_t > possibleBlocks = { FLOOR_ID, const std::vector< uint64_t > possibleBlocks = { FLOOR_ID,
HILL_INCLINE_ID, HILL_INCLINE_ID,
@ -105,5 +109,7 @@ createTerrainBlock( uint64_t block_id, BlockType type,
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) { std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
//TODO add type additions //TODO add type additions
return createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true ); auto mario = createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
dynamic_cast<MarioBlock&>(*mario).setCharacter();
return mario;
} }

View File

@ -9,8 +9,10 @@ public:
MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src); MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src);
void visit( SDLPP::Visitor &visitor ) override; void visit( SDLPP::Visitor &visitor ) override;
void setTool(bool tool = true); void setTool(bool tool = true);
void setCharacter(bool character = true);
private: private:
bool _tool = false; bool _tool = false;
bool _character = false;
}; };
extern const std::vector<uint64_t> possibleBlocks; extern const std::vector<uint64_t> possibleBlocks;

View File

@ -126,13 +126,14 @@ void pollEvents( SDLPP::Scene &scene ) {
ToolVisitor visitor; ToolVisitor visitor;
visitor.setVisitorType(TOOL_VISITOR_TYPE); visitor.setVisitorType(TOOL_VISITOR_TYPE);
scene.visitCollisions(*current_tool, visitor); scene.visitCollisions(*current_tool, visitor);
if(visitor.removeBlock()) { if(visitor.removeBlock() && !visitor.addBlock()) {
// TODO check if modifier // TODO check if modifier
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, 0, 0, 0, 0, 0}; auto prev = objects[current_start_index + current_box.getX()][current_box.getY()];
} objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, 0, std::get<2>(prev), std::get<3>(prev), 0, 0};
if(visitor.addBlock()) { } else if(visitor.addBlock()) {
// TODO check if modifier // TODO check if modifier
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, current_tool->getId(), 0, 0, 0, 0}; auto prev = objects[current_start_index + current_box.getX()][current_box.getY()];
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, current_tool->getId(), std::get<2>(prev), std::get<3>(prev), 0, 0};
auto obj = createTerrainBlock(current_tool->getId(), OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY(), true); auto obj = createTerrainBlock(current_tool->getId(), OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY(), true);
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID); obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
scene.addObject(obj); scene.addObject(obj);