polimorfise d'enemics
moving platforms
This commit is contained in:
@@ -195,6 +195,7 @@ void MapEditor::enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player
|
||||
yaml_backup_ = yaml_; // Copia profunda para revert
|
||||
}
|
||||
|
||||
bool is_reenter = reenter_;
|
||||
if (!reenter_) {
|
||||
// Solo guardar estado previo en el primer enter (no en re-enter tras cambio de room)
|
||||
invincible_before_editor_ = Options::cheats.invincible;
|
||||
@@ -219,13 +220,16 @@ void MapEditor::enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player
|
||||
// Crear la barra de estado
|
||||
statusbar_ = std::make_unique<EditorStatusBar>(room_->getNumber());
|
||||
|
||||
// Resetear estado
|
||||
// Resetear estado (preservar modo de edición en re-enter)
|
||||
drag_ = {};
|
||||
selected_enemy_ = -1;
|
||||
selected_item_ = -1;
|
||||
brush_tile_ = NO_BRUSH;
|
||||
painting_ = false;
|
||||
editing_collision_ = false;
|
||||
if (!is_reenter) {
|
||||
brush_tile_ = NO_BRUSH;
|
||||
painting_ = false;
|
||||
editing_collision_ = false;
|
||||
}
|
||||
painting_ = false; // Siempre dejar de pintar al cambiar de room
|
||||
|
||||
// Asegurar que collision_tile_map tiene el tamaño correcto
|
||||
if (room_data_.collision_tile_map.size() != static_cast<size_t>(Map::WIDTH * Map::HEIGHT)) {
|
||||
@@ -1053,7 +1057,7 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
|
||||
enemy.animation_path = anim;
|
||||
try {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
enemy_mgr->getEnemy(selected_enemy_) = std::make_shared<Enemy>(enemy);
|
||||
enemy_mgr->getEnemy(selected_enemy_) = Enemy::create(enemy);
|
||||
} catch (const std::exception& e) {
|
||||
enemy.animation_path = old_anim; // Restaurar si falla
|
||||
return std::string("Error: ") + e.what();
|
||||
@@ -1096,7 +1100,7 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
|
||||
// Recrear el enemigo (flip/mirror se aplican en el constructor)
|
||||
try {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
enemy_mgr->getEnemy(selected_enemy_) = std::make_shared<Enemy>(enemy);
|
||||
enemy_mgr->getEnemy(selected_enemy_) = Enemy::create(enemy);
|
||||
} catch (const std::exception& e) {
|
||||
return std::string("Error: ") + e.what();
|
||||
}
|
||||
@@ -1112,7 +1116,7 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
|
||||
// Recrear el enemigo (flip/mirror se aplican en el constructor)
|
||||
try {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
enemy_mgr->getEnemy(selected_enemy_) = std::make_shared<Enemy>(enemy);
|
||||
enemy_mgr->getEnemy(selected_enemy_) = Enemy::create(enemy);
|
||||
} catch (const std::exception& e) {
|
||||
return std::string("Error: ") + e.what();
|
||||
}
|
||||
@@ -1147,7 +1151,7 @@ auto MapEditor::addEnemy() -> std::string {
|
||||
|
||||
// Añadir a los datos y crear el sprite vivo
|
||||
room_data_.enemies.push_back(new_enemy);
|
||||
room_->getEnemyManager()->addEnemy(std::make_shared<Enemy>(new_enemy));
|
||||
room_->getEnemyManager()->addEnemy(Enemy::create(new_enemy));
|
||||
|
||||
// Seleccionar el nuevo enemigo
|
||||
selected_enemy_ = static_cast<int>(room_data_.enemies.size()) - 1;
|
||||
@@ -1170,7 +1174,7 @@ auto MapEditor::deleteEnemy() -> std::string {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
enemy_mgr->clear();
|
||||
for (const auto& enemy_data : room_data_.enemies) {
|
||||
enemy_mgr->addEnemy(std::make_shared<Enemy>(enemy_data));
|
||||
enemy_mgr->addEnemy(Enemy::create(enemy_data));
|
||||
}
|
||||
|
||||
selected_enemy_ = -1;
|
||||
@@ -1193,7 +1197,7 @@ auto MapEditor::duplicateEnemy() -> std::string {
|
||||
|
||||
// Añadir y crear sprite vivo
|
||||
room_data_.enemies.push_back(copy);
|
||||
room_->getEnemyManager()->addEnemy(std::make_shared<Enemy>(copy));
|
||||
room_->getEnemyManager()->addEnemy(Enemy::create(copy));
|
||||
|
||||
// Seleccionar el nuevo enemigo
|
||||
selected_enemy_ = static_cast<int>(room_data_.enemies.size()) - 1;
|
||||
|
||||
@@ -112,6 +112,7 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
|
||||
out << "enemies:\n";
|
||||
for (const auto& enemy : room_data.enemies) {
|
||||
out << " - animation: " << enemy.animation_path << "\n";
|
||||
if (enemy.type != "path") { out << " type: " << enemy.type << "\n"; }
|
||||
|
||||
int pos_x = static_cast<int>(std::round(enemy.x / Tile::SIZE));
|
||||
int pos_y = static_cast<int>(std::round(enemy.y / Tile::SIZE));
|
||||
@@ -155,6 +156,33 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
|
||||
}
|
||||
}
|
||||
|
||||
// --- Plataformas ---
|
||||
if (!room_data.platforms.empty()) {
|
||||
out << "# Plataformas móviles en esta habitación\n";
|
||||
out << "platforms:\n";
|
||||
for (const auto& plat : room_data.platforms) {
|
||||
out << " - animation: " << plat.animation_path << "\n";
|
||||
|
||||
int pos_x = static_cast<int>(std::round(plat.x / Tile::SIZE));
|
||||
int pos_y = static_cast<int>(std::round(plat.y / Tile::SIZE));
|
||||
out << " position: {x: " << pos_x << ", y: " << pos_y << "}\n";
|
||||
|
||||
out << " velocity: {x: " << plat.vx << ", y: " << plat.vy << "}\n";
|
||||
|
||||
int b1_x = plat.x1 / Tile::SIZE;
|
||||
int b1_y = plat.y1 / Tile::SIZE;
|
||||
int b2_x = plat.x2 / Tile::SIZE;
|
||||
int b2_y = plat.y2 / Tile::SIZE;
|
||||
out << " boundaries:\n";
|
||||
out << " position1: {x: " << b1_x << ", y: " << b1_y << "}\n";
|
||||
out << " position2: {x: " << b2_x << ", y: " << b2_y << "}\n";
|
||||
|
||||
if (plat.frame != -1) { out << " frame: " << plat.frame << "\n"; }
|
||||
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user