mostra les rutes dels enemics al editor

This commit is contained in:
2026-04-02 10:36:41 +02:00
parent a2caf95005
commit 606388227c
9 changed files with 96 additions and 13 deletions

View File

@@ -8,11 +8,14 @@
#include "core/input/mouse.hpp" // Para Mouse
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "game/editor/editor_statusbar.hpp" // Para EditorStatusBar
#include "game/entities/player.hpp" // Para Player
#include "game/gameplay/room.hpp" // Para Room
#include "game/options.hpp" // Para Options
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
#include "utils/utils.hpp" // Para stringToColor
// Singleton
MapEditor* MapEditor::instance_ = nullptr;
@@ -46,6 +49,12 @@ void MapEditor::enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player
room_path_ = room_path;
scoreboard_data_ = std::move(scoreboard_data);
// Cargar una copia de los datos de la habitación (para boundaries y edición futura)
auto room_data_ptr = Resource::Cache::get()->getRoom(room_path);
if (room_data_ptr) {
room_data_ = *room_data_ptr;
}
// Guardar estado de invencibilidad y forzarla
invincible_before_editor_ = Options::cheats.invincible;
Options::cheats.invincible = Options::Cheat::State::ENABLED;
@@ -54,9 +63,6 @@ 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(), room_->getName());
// Pausar enemigos e items
room_->setPaused(true);
active_ = true;
std::cout << "MapEditor: ON (room " << room_path_ << ")\n";
}
@@ -71,9 +77,6 @@ void MapEditor::exit() {
Options::cheats.invincible = invincible_before_editor_;
player_->setColor();
// Despausar enemigos e items
room_->setPaused(false);
// Liberar recursos
statusbar_.reset();
room_.reset();
@@ -84,11 +87,14 @@ void MapEditor::exit() {
}
// Actualiza el editor
void MapEditor::update([[maybe_unused]] float delta_time) {
void MapEditor::update(float delta_time) {
// Mantener el ratón siempre visible
SDL_ShowCursor();
Mouse::last_mouse_move_time = SDL_GetTicks();
// Actualizar animaciones de enemigos e items (sin mover enemigos)
room_->updateEditorMode(delta_time);
// Actualizar posición del ratón
updateMousePosition();
@@ -102,7 +108,11 @@ void MapEditor::update([[maybe_unused]] float delta_time) {
// Renderiza el editor
void MapEditor::render() {
// El tilemap ya ha sido renderizado por Game::renderPlaying() antes de llamar aquí
// Renderizar entidades (por ahora: enemigos, items, jugador normales)
// Renderizar los marcadores de boundaries y líneas de ruta (debajo de los sprites)
renderEnemyBoundaries();
// Renderizar entidades normales: enemigos (animados en posición inicial), items, jugador
room_->renderEnemies();
room_->renderItems();
player_->render();
@@ -119,6 +129,48 @@ void MapEditor::handleEvent([[maybe_unused]] const SDL_Event& event) {
// En fases posteriores: drag & drop
}
// Dibuja marcadores de boundaries y líneas de ruta para los enemigos
void MapEditor::renderEnemyBoundaries() {
auto game_surface = Screen::get()->getRendererSurface();
if (!game_surface) { return; }
const Uint8 COLOR_BOUND1 = stringToColor("bright_cyan");
const Uint8 COLOR_BOUND2 = stringToColor("bright_yellow");
const Uint8 COLOR_ROUTE = stringToColor("bright_white");
for (const auto& enemy : room_data_.enemies) {
// Dibujar línea de ruta: boundary1 → posición inicial → boundary2
// Usamos el centro del tile como punto de referencia para las líneas
constexpr float HALF = Tile::SIZE / 2.0F;
float init_cx = enemy.x + HALF;
float init_cy = enemy.y + HALF;
float b1_cx = static_cast<float>(enemy.x1) + HALF;
float b1_cy = static_cast<float>(enemy.y1) + HALF;
float b2_cx = static_cast<float>(enemy.x2) + HALF;
float b2_cy = static_cast<float>(enemy.y2) + HALF;
// Línea de boundary1 a posición inicial
game_surface->drawLine(b1_cx, b1_cy, init_cx, init_cy, COLOR_ROUTE);
// Línea de posición inicial a boundary2
game_surface->drawLine(init_cx, init_cy, b2_cx, b2_cy, COLOR_ROUTE);
// Marcadores en las boundaries
renderBoundaryMarker(static_cast<float>(enemy.x1), static_cast<float>(enemy.y1), COLOR_BOUND1);
renderBoundaryMarker(static_cast<float>(enemy.x2), static_cast<float>(enemy.y2), COLOR_BOUND2);
}
}
// Dibuja un marcador de boundary (rectángulo pequeño) en una posición
void MapEditor::renderBoundaryMarker(float x, float y, Uint8 color) {
auto game_surface = Screen::get()->getRendererSurface();
if (!game_surface) { return; }
// Dibujar un rectángulo de 8x8 como marcador
SDL_FRect marker = {.x = x, .y = y, .w = static_cast<float>(Tile::SIZE), .h = static_cast<float>(Tile::SIZE)};
game_surface->drawRectBorder(&marker, color);
}
// Convierte coordenadas de ventana a coordenadas de juego y tile
void MapEditor::updateMousePosition() {
float mouse_x = 0.0F;

View File

@@ -37,7 +37,9 @@ class MapEditor {
MapEditor(); // Constructor
~MapEditor(); // Destructor
void updateMousePosition(); // Convierte coordenadas de ventana a coordenadas de juego y tile
void updateMousePosition(); // Convierte coordenadas de ventana a coordenadas de juego y tile
void renderEnemyBoundaries(); // Dibuja marcadores de boundaries y líneas de ruta
void renderBoundaryMarker(float x, float y, Uint8 color); // Dibuja un marcador de boundary en una posición
// Estado del editor
bool active_{false};