llevat soport per a colors amb nom

This commit is contained in:
2026-04-06 09:14:36 +02:00
parent c4a26ffa0f
commit cdf0665458
121 changed files with 676 additions and 5754 deletions

View File

@@ -10,11 +10,11 @@
#include "utils/utils.hpp"
// Constructor
TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, std::string bg_color, int conveyor_belt_direction)
TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, Uint8 bg_color, int conveyor_belt_direction)
: tile_map_(std::move(tile_map)),
tile_set_width_(tile_set_width),
tileset_surface_(std::move(tileset_surface)),
bg_color_(std::move(bg_color)),
bg_color_(bg_color),
conveyor_belt_direction_(conveyor_belt_direction) {
// Crear la surface del mapa
map_surface_ = std::make_shared<Surface>(PlayArea::WIDTH, PlayArea::HEIGHT);
@@ -62,37 +62,37 @@ static void renderDebugCollisionSurfaces(const CollisionMap* collision_map) {
// BottomSurfaces
for (auto l : collision_map->getBottomFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::BLUE));
surface->drawLine(l.x1, l.y, l.x2, l.y, 2);
}
// TopSurfaces
for (auto l : collision_map->getTopFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::RED));
surface->drawLine(l.x1, l.y, l.x2, l.y, 4);
}
// LeftSurfaces
for (auto l : collision_map->getLeftWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::GREEN));
surface->drawLine(l.x, l.y1, l.x, l.y2, 8);
}
// RightSurfaces
for (auto l : collision_map->getRightWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::MAGENTA));
surface->drawLine(l.x, l.y1, l.x, l.y2, 6);
}
// LeftSlopes
for (auto l : collision_map->getLeftSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::CYAN));
surface->drawLine(l.x1, l.y1, l.x2, l.y2, 10);
}
// RightSlopes
for (auto l : collision_map->getRightSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::YELLOW));
surface->drawLine(l.x1, l.y1, l.x2, l.y2, 12);
}
// AutoSurfaces (Conveyor Belts)
for (auto l : collision_map->getConveyorBeltFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::WHITE));
surface->drawLine(l.x1, l.y, l.x2, l.y, 14);
}
}
@@ -115,7 +115,7 @@ void TilemapRenderer::setTile(int index, int tile_value) {
// 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_));
map_surface_->fillRect(&cell, bg_color_);
// Dibujar el nuevo tile (si no es vacío ni animado)
if (tile_value > -1) {
@@ -135,10 +135,9 @@ void TilemapRenderer::setTile(int index, int tile_value) {
// Pinta el mapa estático y debug lines
void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) { // NOLINT(readability-convert-member-functions-to-static)
const Uint8 COLOR = stringToColor(bg_color_);
auto previous_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(map_surface_);
map_surface_->clear(COLOR);
map_surface_->clear(bg_color_);
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo