Mario editor: use visitors

This commit is contained in:
2021-05-02 14:14:11 +02:00
parent 34324d3054
commit 96857a99af
11 changed files with 268 additions and 100 deletions
+6 -9
View File
@@ -38,7 +38,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, std::shared_ptr<SDLPP::Rectan
collision = true;
}
// TODO add modifiers to createTerrainBlock
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE, collision);
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i, j, collision);
if(obj != nullptr)
scene->addObject(obj);
if(character) {
@@ -51,6 +51,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, std::shared_ptr<SDLPP::Rectan
scene->moveZTop(mario);
}
// editor loader
void loadMap(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file, std::shared_ptr<SDLPP::Renderer> &renderer, std::vector<std::array<std::tuple<uint8_t, uint16_t, uint8_t, uint8_t, uint8_t, uint8_t>,16>> &objects) {
std::ifstream map_file;
map_file.open(file, std::ios::in | std::ios::binary);
@@ -81,17 +82,13 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file, std:
}
}
col[j] = {type, id, character_type, character, modifier_type, modifier_data};
bool collision = false;
if(id == FLOOR_ID) {
collision = true;
}
// TODO add modifiers to createTerrainBlock
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE, collision);
if(obj != nullptr)
scene->addObject(obj);
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i, j, true);
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
scene->addObject(obj);
if(character) {
if(character == MARIO_ID) {
scene->addObject(createMario(static_cast<BlockType>(character_type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE));
scene->addObject(createMario(static_cast<BlockType>(character_type), renderer, i, j));
}
}
}