primera versió del editor de tiles
This commit is contained in:
@@ -134,6 +134,14 @@ void Room::resetEnemyPositions(const std::vector<Enemy::Data>& enemy_data) {
|
||||
enemy_manager_->resetPositions(enemy_data);
|
||||
}
|
||||
|
||||
// Cambia un tile y repinta la celda (para editor)
|
||||
void Room::setTile(int index, int tile_value) {
|
||||
if (index >= 0 && index < static_cast<int>(tile_map_.size())) {
|
||||
tile_map_[index] = tile_value;
|
||||
tilemap_renderer_->setTile(index, tile_value);
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia color de fondo y redibuja el mapa (para editor)
|
||||
void Room::setBgColor(const std::string& color) {
|
||||
bg_color_ = color;
|
||||
|
||||
@@ -76,6 +76,9 @@ class Room {
|
||||
auto getItemManager() -> ItemManager* { return item_manager_.get(); } // Acceso al gestor de items (para editor)
|
||||
void setBgColor(const std::string& color); // Cambia color de fondo y redibuja (para editor)
|
||||
void setItemColors(const std::string& color1, const std::string& color2); // Cambia colores de items (para editor)
|
||||
void setTile(int index, int tile_value); // Cambia un tile y redibuja (para editor)
|
||||
[[nodiscard]] auto getTileSetFile() const -> const std::string& { return tile_set_file_; }
|
||||
[[nodiscard]] auto getTileSetWidth() const -> int { return tile_set_width_; }
|
||||
#endif
|
||||
void update(float delta_time); // Actualiza las variables y objetos de la habitación
|
||||
auto getRoom(Border border) -> std::string; // Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
|
||||
@@ -100,6 +100,37 @@ static void renderDebugCollisionSurfaces(const CollisionMap* collision_map) {
|
||||
void TilemapRenderer::redrawMap(const CollisionMap* collision_map) {
|
||||
fillMapTexture(collision_map);
|
||||
}
|
||||
|
||||
// Cambia un tile y repinta solo esa celda en la map_surface
|
||||
void TilemapRenderer::setTile(int index, int tile_value) {
|
||||
if (index < 0 || index >= static_cast<int>(tile_map_.size())) { return; }
|
||||
|
||||
tile_map_[index] = tile_value;
|
||||
|
||||
int col = index % MAP_WIDTH;
|
||||
int row = index / MAP_WIDTH;
|
||||
|
||||
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(map_surface_);
|
||||
|
||||
// Borrar la celda con el color de fondo
|
||||
SDL_FRect cell = {.x = static_cast<float>(col * TILE_SIZE), .y = static_cast<float>(row * TILE_SIZE),
|
||||
.w = static_cast<float>(TILE_SIZE), .h = static_cast<float>(TILE_SIZE)};
|
||||
map_surface_->fillRect(&cell, stringToColor(bg_color_));
|
||||
|
||||
// Dibujar el nuevo tile (si no es vacío ni animado)
|
||||
if (tile_value > -1) {
|
||||
const bool IS_ANIMATED = (tile_value >= 18 * tile_set_width_) && (tile_value < 19 * tile_set_width_);
|
||||
if (!IS_ANIMATED) {
|
||||
SDL_FRect clip = {.x = static_cast<float>((tile_value % tile_set_width_) * TILE_SIZE),
|
||||
.y = static_cast<float>((tile_value / tile_set_width_) * TILE_SIZE),
|
||||
.w = static_cast<float>(TILE_SIZE), .h = static_cast<float>(TILE_SIZE)};
|
||||
tileset_surface_->render(col * TILE_SIZE, row * TILE_SIZE, &clip);
|
||||
}
|
||||
}
|
||||
|
||||
Screen::get()->setRendererSurface(previous_renderer);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Pinta el mapa estático y debug lines
|
||||
|
||||
@@ -70,6 +70,7 @@ class TilemapRenderer {
|
||||
*/
|
||||
void redrawMap(const CollisionMap* collision_map);
|
||||
void setBgColor(const std::string& color) { bg_color_ = color; }
|
||||
void setTile(int index, int tile_value); // Cambia un tile y repinta esa celda
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user