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,14 +10,13 @@
#include "core/rendering/text.hpp" // Para Text
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "game/options.hpp" // Para Options::game
#include "utils/defines.hpp" // Para Tile::SIZE
#include "utils/utils.hpp" // Para stringToColor, toLower
#include "utils/utils.hpp" // Para toLower
// Constructor
EditorStatusBar::EditorStatusBar(std::string room_number)
: room_number_(std::move(room_number)) {
const float SURFACE_WIDTH = Options::game.width;
constexpr float SURFACE_HEIGHT = 6.0F * Tile::SIZE; // 48 pixels, igual que el scoreboard
constexpr float SURFACE_HEIGHT = 24.0F; // 3 líneas de 8px
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
@@ -48,16 +47,26 @@ void EditorStatusBar::fillTexture() {
auto previous_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(surface_);
surface_->clear(stringToColor("black"));
surface_->clear(0);
auto text = Resource::Cache::get()->getText("8bithud");
const Uint8 LABEL_COLOR = stringToColor("bright_cyan");
const Uint8 VALUE_COLOR = stringToColor("white");
const Uint8 DETAIL_COLOR = stringToColor("bright_yellow");
const Uint8 LABEL_COLOR = 11;
const Uint8 VALUE_COLOR = 14;
const Uint8 DETAIL_COLOR = 13;
const Uint8 COORD_COLOR = 9;
const int RIGHT_X = static_cast<int>(Options::game.width) - LEFT_X;
// Línea 1: Número de la habitación
// Línea 1: Room number (izq) + line4 extra (centro) + tile coords + line5 drag info (der)
text->writeColored(LEFT_X, LINE1_Y, toLower(room_number_), LABEL_COLOR);
// Tile coords + drag info a la derecha
const std::string TILE_X_STR = (mouse_tile_x_ < 10 ? "0" : "") + std::to_string(mouse_tile_x_);
const std::string TILE_Y_STR = (mouse_tile_y_ < 10 ? "0" : "") + std::to_string(mouse_tile_y_);
std::string right_part = TILE_X_STR + "," + TILE_Y_STR;
if (!line5_.empty()) { right_part += " " + line5_; }
if (!line4_.empty()) { right_part = toLower(line4_) + " " + right_part; }
text->writeColored(RIGHT_X - text->length(right_part), LINE1_Y, right_part, COORD_COLOR);
// Línea 2: Propiedades de room o info de enemigo
if (!line2_.empty()) {
text->writeColored(LEFT_X, LINE2_Y, toLower(line2_), DETAIL_COLOR);
@@ -68,20 +77,6 @@ void EditorStatusBar::fillTexture() {
text->writeColored(LEFT_X, LINE3_Y, toLower(line3_), VALUE_COLOR);
}
// Línea 4: Extra
if (!line4_.empty()) {
text->writeColored(LEFT_X, LINE4_Y, toLower(line4_), DETAIL_COLOR);
}
// Línea 5: Tile coords + drag info
const std::string TILE_X_STR = (mouse_tile_x_ < 10 ? "0" : "") + std::to_string(mouse_tile_x_);
const std::string TILE_Y_STR = (mouse_tile_y_ < 10 ? "0" : "") + std::to_string(mouse_tile_y_);
std::string line5 = "tile:" + TILE_X_STR + "," + TILE_Y_STR;
if (!line5_.empty()) {
line5 += " " + line5_;
}
text->writeColored(LEFT_X, LINE5_Y, toLower(line5), stringToColor("bright_green"));
Screen::get()->setRendererSurface(previous_renderer);
}

View File

@@ -25,13 +25,11 @@ class EditorStatusBar {
private:
void fillTexture(); // Dibuja los elementos en la surface
// Constantes de posición (en pixels dentro de la surface de 256x48)
// Font 8bithud lowercase = 6px alto → 5 líneas con 8px de separación
static constexpr int LINE1_Y = 2; // Nombre de la habitación
static constexpr int LINE2_Y = 10; // Propiedades de room / enemy info
static constexpr int LINE3_Y = 18; // Conexiones+items / enemy detail
static constexpr int LINE4_Y = 26; // Extra
static constexpr int LINE5_Y = 34; // Tile coords + drag info
// Constantes de posición (en pixels dentro de la surface de 256x24)
// Font 8bithud lowercase = 6px alto → 3 líneas con 8px de separación
static constexpr int LINE1_Y = 1; // Room number + tile coords + extra
static constexpr int LINE2_Y = 9; // Propiedades de room / enemy info
static constexpr int LINE3_Y = 17; // Conexiones+items / enemy detail
static constexpr int LEFT_X = 4; // Margen izquierdo
// Objetos
@@ -44,8 +42,8 @@ class EditorStatusBar {
int mouse_tile_y_{0}; // Coordenada Y del ratón en tiles
std::string line2_; // Contenido de la línea 2
std::string line3_; // Contenido de la línea 3
std::string line4_; // Contenido de la línea 4
std::string line5_; // Contenido de la línea 5
std::string line4_; // Contenido de la línea 4 (mostrado en la línea 1 a la derecha)
std::string line5_; // Contenido de la línea 5 (mostrado en la línea 1 al centro)
};
#endif // _DEBUG

View File

@@ -28,7 +28,7 @@
#include "game/options.hpp" // Para Options
#include "game/ui/console.hpp" // Para Console
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Singleton
MapEditor* MapEditor::instance_ = nullptr;
@@ -70,17 +70,17 @@ void MapEditor::loadSettings() {
if (yaml.contains("grid")) { settings_.grid = yaml["grid"].get_value<bool>(); }
if (yaml.contains("show_render_info")) { settings_.show_render_info = yaml["show_render_info"].get_value<bool>(); }
if (yaml.contains("minimap_bg")) {
if (yaml["minimap_bg"].is_string()) {
settings_.minimap_bg = yaml["minimap_bg"].get_value<std::string>();
} else if (yaml["minimap_bg"].is_integer()) {
settings_.minimap_bg = std::to_string(yaml["minimap_bg"].get_value<int>());
if (yaml["minimap_bg"].is_integer()) {
settings_.minimap_bg = static_cast<Uint8>(yaml["minimap_bg"].get_value<int>());
} else if (yaml["minimap_bg"].is_string()) {
settings_.minimap_bg = static_cast<Uint8>(safeStoi(yaml["minimap_bg"].get_value<std::string>(), 2));
}
}
if (yaml.contains("minimap_conn")) {
if (yaml["minimap_conn"].is_string()) {
settings_.minimap_conn = yaml["minimap_conn"].get_value<std::string>();
} else if (yaml["minimap_conn"].is_integer()) {
settings_.minimap_conn = std::to_string(yaml["minimap_conn"].get_value<int>());
if (yaml["minimap_conn"].is_integer()) {
settings_.minimap_conn = static_cast<Uint8>(yaml["minimap_conn"].get_value<int>());
} else if (yaml["minimap_conn"].is_string()) {
settings_.minimap_conn = static_cast<Uint8>(safeStoi(yaml["minimap_conn"].get_value<std::string>(), 14));
}
}
} catch (...) {
@@ -99,8 +99,8 @@ void MapEditor::saveSettings() const {
file << "# Map Editor Settings\n";
file << "grid: " << (settings_.grid ? "true" : "false") << "\n";
file << "show_render_info: " << (settings_.show_render_info ? "true" : "false") << "\n";
file << "minimap_bg: " << settings_.minimap_bg << "\n";
file << "minimap_conn: " << settings_.minimap_conn << "\n";
file << "minimap_bg: " << static_cast<int>(settings_.minimap_bg) << "\n";
file << "minimap_conn: " << static_cast<int>(settings_.minimap_conn) << "\n";
file.close();
}
@@ -121,16 +121,14 @@ auto MapEditor::showGrid(bool show) -> std::string {
return show ? "Grid ON" : "Grid OFF";
}
// Parsea un color por nombre o índice numérico
// Parsea un color como índice numérico
static auto parseColor(const std::string& value) -> Uint8 {
try {
return static_cast<Uint8>(std::stoi(value));
} catch (...) { return stringToColor(value); }
return static_cast<Uint8>(safeStoi(value, 0));
}
void MapEditor::toggleMiniMap() {
if (!mini_map_) {
mini_map_ = std::make_unique<MiniMap>(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
mini_map_ = std::make_unique<MiniMap>(settings_.minimap_bg, settings_.minimap_conn);
mini_map_->on_navigate = [this](const std::string& room_name) {
mini_map_visible_ = false;
reenter_ = true;
@@ -143,7 +141,7 @@ void MapEditor::toggleMiniMap() {
mini_map_visible_ = !mini_map_visible_;
if (mini_map_visible_) {
// Reconstruir el minimapa (pueden haber cambiado rooms, conexiones, tiles)
mini_map_ = std::make_unique<MiniMap>(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
mini_map_ = std::make_unique<MiniMap>(settings_.minimap_bg, settings_.minimap_conn);
mini_map_->on_navigate = [this](const std::string& room_name) {
mini_map_visible_ = false;
reenter_ = true;
@@ -157,21 +155,21 @@ void MapEditor::toggleMiniMap() {
}
auto MapEditor::setMiniMapBg(const std::string& color) -> std::string {
settings_.minimap_bg = toLower(color);
settings_.minimap_bg = static_cast<Uint8>(safeStoi(color, 2));
saveSettings();
if (mini_map_) {
mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
mini_map_->rebuild(settings_.minimap_bg, settings_.minimap_conn);
}
return "minimap bg: " + settings_.minimap_bg;
return "minimap bg: " + std::to_string(settings_.minimap_bg);
}
auto MapEditor::setMiniMapConn(const std::string& color) -> std::string {
settings_.minimap_conn = toLower(color);
settings_.minimap_conn = static_cast<Uint8>(safeStoi(color, 14));
saveSettings();
if (mini_map_) {
mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn));
mini_map_->rebuild(settings_.minimap_bg, settings_.minimap_conn);
}
return "minimap conn: " + settings_.minimap_conn;
return "minimap conn: " + std::to_string(settings_.minimap_conn);
}
// Entra en modo editor
@@ -286,7 +284,7 @@ auto MapEditor::revert() -> std::string {
// Refrescar visuales de la habitación
room_->setBgColor(room_data_.bg_color);
Screen::get()->setBorderColor(stringToColor(room_data_.border_color));
Screen::get()->setBorderColor(room_data_.border_color);
// Restaurar el tilemap completo
for (int i = 0; i < static_cast<int>(room_data_.tile_map.size()); ++i) {
@@ -435,7 +433,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
tile_picker_.on_select = [this](int tile) {
brush_tile_ = tile;
};
tile_picker_.open(room_->getTileSetFile(), current, stringToColor(room_data_.bg_color));
tile_picker_.open(room_->getTileSetFile(), current, room_data_.bg_color);
return;
}
@@ -692,7 +690,7 @@ void MapEditor::renderSelectionHighlight() {
.y = enemy_rect.y - 1,
.w = enemy_rect.w + 2,
.h = enemy_rect.h + 2};
game_surface->drawRectBorder(&border, stringToColor("bright_green"));
game_surface->drawRectBorder(&border, 9);
}
// Highlight del item seleccionado (persistente, color bright_green)
@@ -703,13 +701,13 @@ void MapEditor::renderSelectionHighlight() {
.y = item_rect.y - 1,
.w = item_rect.w + 2,
.h = item_rect.h + 2};
game_surface->drawRectBorder(&border, stringToColor("bright_green"));
game_surface->drawRectBorder(&border, 9);
}
// Highlight del drag activo (temporal, color bright_white)
if (drag_.target == DragTarget::NONE || !drag_.moved) { return; }
const Uint8 DRAG_COLOR = stringToColor("bright_white");
const Uint8 DRAG_COLOR = 15;
SDL_FRect highlight_rect{};
switch (drag_.target) {
@@ -757,9 +755,9 @@ 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");
const Uint8 COLOR_BOUND1 = 11;
const Uint8 COLOR_BOUND2 = 13;
const Uint8 COLOR_ROUTE = 15;
for (int i = 0; i < static_cast<int>(room_data_.enemies.size()); ++i) {
const auto& enemy = room_data_.enemies[i];
@@ -878,7 +876,7 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
auto dot = anim.rfind('.');
if (dot != std::string::npos) { anim = anim.substr(0, dot); }
line2 = "enemy " + std::to_string(selected_enemy_) + ": " + anim + " " + e.color;
line2 = "enemy " + std::to_string(selected_enemy_) + ": " + anim + " c:" + std::to_string(e.color);
line3 = "vx:" + std::to_string(static_cast<int>(e.vx)) +
" vy:" + std::to_string(static_cast<int>(e.vy));
if (e.flip) { line3 += " flip"; }
@@ -898,10 +896,10 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
conv = "right";
}
line2 = "bg:" + room_data_.bg_color + " brd:" + room_data_.border_color + " conv:" + conv;
line2 = "bg:" + std::to_string(room_data_.bg_color) + " brd:" + std::to_string(room_data_.border_color) + " conv:" + conv;
line3 = "u:" + conn(room_data_.upper_room) + " d:" + conn(room_data_.lower_room) +
" l:" + conn(room_data_.left_room) + " r:" + conn(room_data_.right_room) +
" itm:" + room_data_.item_color1 + "/" + room_data_.item_color2;
" itm:" + std::to_string(room_data_.item_color1) + "/" + std::to_string(room_data_.item_color2);
}
// Línea 4: brush activo
@@ -971,10 +969,10 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
}
if (property == "COLOR") {
std::string color = toLower(value);
auto color = static_cast<Uint8>(safeStoi(value, 14));
// Intentar recrear el enemigo con el nuevo color
std::string old_color = enemy.color;
Uint8 old_color = enemy.color;
enemy.color = color;
try {
auto* enemy_mgr = room_->getEnemyManager();
@@ -985,7 +983,7 @@ auto MapEditor::setEnemyProperty(const std::string& property, const std::string&
}
autosave();
return "color: " + color;
return "color: " + std::to_string(color);
}
if (property == "VX") {
@@ -1063,7 +1061,7 @@ auto MapEditor::addEnemy() -> std::string {
new_enemy.y1 = static_cast<int>(CENTER_Y);
new_enemy.x2 = static_cast<int>(CENTER_X + ROUTE_HALF);
new_enemy.y2 = static_cast<int>(CENTER_Y);
new_enemy.color = "white";
new_enemy.color = 14;
new_enemy.flip = true;
new_enemy.frame = -1;
@@ -1131,35 +1129,35 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
std::string val = toLower(value);
if (property == "BGCOLOR") {
val = colorToString(stringToColor(val)); // Normaliza a nombre canónico (acepta nombres e índices)
room_data_.bg_color = val;
room_->setBgColor(val);
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.bg_color = color;
room_->setBgColor(color);
autosave();
return "bgcolor: " + val;
return "bgcolor: " + std::to_string(color);
}
if (property == "BORDER") {
val = colorToString(stringToColor(val));
room_data_.border_color = val;
Screen::get()->setBorderColor(stringToColor(val));
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.border_color = color;
Screen::get()->setBorderColor(color);
autosave();
return "border: " + val;
return "border: " + std::to_string(color);
}
if (property == "ITEMCOLOR1") {
val = colorToString(stringToColor(val));
room_data_.item_color1 = val;
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.item_color1 = color;
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
autosave();
return "itemcolor1: " + val;
return "itemcolor1: " + std::to_string(color);
}
if (property == "ITEMCOLOR2") {
val = colorToString(stringToColor(val));
room_data_.item_color2 = val;
auto color = static_cast<Uint8>(safeStoi(val, 0));
room_data_.item_color2 = color;
room_->setItemColors(room_data_.item_color1, room_data_.item_color2);
autosave();
return "itemcolor2: " + val;
return "itemcolor2: " + std::to_string(color);
}
if (property == "CONVEYOR") {
@@ -1320,11 +1318,11 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
// Crear Room::Data por defecto con conexión recíproca
Room::Data new_room;
new_room.number = std::string(name_buf).substr(0, std::string(name_buf).find('.'));
new_room.bg_color = "black";
new_room.border_color = "magenta";
new_room.bg_color = 0;
new_room.border_color = 6;
new_room.tile_set_file = "standard.gif";
new_room.item_color1 = "bright_cyan";
new_room.item_color2 = "yellow";
new_room.item_color1 = 11;
new_room.item_color2 = 12;
new_room.upper_room = "0";
new_room.lower_room = "0";
new_room.left_room = "0";
@@ -1531,9 +1529,7 @@ void MapEditor::openTilePicker(const std::string& tileset_name, int current_tile
autosave();
};
// Pasar color de fondo de la habitación + color de sustitución del item
int bg = stringToColor(room_data_.bg_color);
int item_color = stringToColor(room_data_.item_color1);
tile_picker_.open(tileset_name, current_tile, bg, 1, item_color);
tile_picker_.open(tileset_name, current_tile, room_data_.bg_color, 1, room_data_.item_color1);
}
// Crea un nuevo item con valores por defecto, centrado en la habitación
@@ -1546,8 +1542,8 @@ auto MapEditor::addItem() -> std::string {
new_item.x = PlayArea::CENTER_X;
new_item.y = PlayArea::CENTER_Y;
new_item.counter = 0;
new_item.color1 = stringToColor(room_data_.item_color1);
new_item.color2 = stringToColor(room_data_.item_color2);
new_item.color1 = room_data_.item_color1;
new_item.color2 = room_data_.item_color2;
room_data_.items.push_back(new_item);
room_->getItemManager()->addItem(std::make_shared<Item>(new_item));
@@ -1600,7 +1596,7 @@ auto MapEditor::duplicateItem() -> std::string {
// Elige un color de grid que contraste con el fondo
// Empieza con bright_black (1), si coincide con el bg en la paleta activa, sube índices
static auto pickGridColor(Uint8 bg, const std::shared_ptr<Surface>& surface) -> Uint8 {
auto grid = static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
Uint8 grid = 1;
Uint32 bg_argb = surface->getPaletteColor(bg);
// Si bright_black es igual al bg, buscar el siguiente color distinto
@@ -1616,7 +1612,7 @@ void MapEditor::renderGrid() const {
auto game_surface = Screen::get()->getRendererSurface();
if (!game_surface) { return; }
const Uint8 COLOR = pickGridColor(stringToColor(room_data_.bg_color), game_surface);
const Uint8 COLOR = pickGridColor(room_data_.bg_color, game_surface);
// Líneas verticales (cada 8 pixels)
for (int x = Tile::SIZE; x < PlayArea::WIDTH; x += Tile::SIZE) {

View File

@@ -74,8 +74,8 @@ class MapEditor {
struct Settings {
bool grid{false};
bool show_render_info{false};
std::string minimap_bg{"blue"};
std::string minimap_conn{"white"};
Uint8 minimap_bg{2};
Uint8 minimap_conn{14};
};
Settings settings_;
void loadSettings();

View File

@@ -15,7 +15,7 @@
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "game/gameplay/room.hpp" // Para Room::Data
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Constructor: construye todo el minimapa
MiniMap::MiniMap(Uint8 bg_color, Uint8 conn_color)
@@ -129,6 +129,7 @@ void MiniMap::layoutRooms() {
for (const auto& [neighbor_name, dx, dy] : neighbors) {
if (neighbor_name == "0" || neighbor_name.empty()) { continue; }
if (visited.contains(neighbor_name)) { continue; }
if (!room_map.contains(neighbor_name)) { continue; } // Room no existe en cache
GridPos neighbor_pos = {.x = pos.x + dx, .y = pos.y + dy};
auto nkey = std::make_pair(neighbor_pos.x, neighbor_pos.y);
@@ -169,14 +170,19 @@ void MiniMap::buildRoomSurfaces() {
// Genera la mini-surface de una room: 1 pixel por tile, color predominante
auto MiniMap::getRoomMiniSurface(const std::string& room_name) -> std::shared_ptr<Surface> {
auto room_data = Resource::Cache::get()->getRoom(room_name);
std::shared_ptr<Room::Data> room_data;
try {
room_data = Resource::Cache::get()->getRoom(room_name);
} catch (...) {
return nullptr; // Room no existe en cache
}
if (!room_data) { return nullptr; }
auto surface = std::make_shared<Surface>(ROOM_W, ROOM_H);
auto prev = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(surface);
surface->clear(stringToColor(room_data->bg_color));
surface->clear(room_data->bg_color);
const auto& tile_map = room_data->tile_map;
for (int y = 0; y < ROOM_H; ++y) {
@@ -318,7 +324,7 @@ void MiniMap::render(const std::string& current_room) {
auto cur_h = static_cast<float>(CELL_H + 2);
if (cur_x >= 0 && cur_y >= 0 && cur_x + cur_w <= PlayArea::WIDTH && cur_y + cur_h <= PlayArea::HEIGHT) {
SDL_FRect highlight = {.x = cur_x, .y = cur_y, .w = cur_w, .h = cur_h};
game_surface->drawRectBorder(&highlight, stringToColor("bright_white"));
game_surface->drawRectBorder(&highlight, 15);
}
}
}

View File

@@ -43,8 +43,8 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
// --- Sección room ---
out << "room:\n";
out << " bgColor: " << room_data.bg_color << "\n";
out << " border: " << room_data.border_color << "\n";
out << " bgColor: " << static_cast<int>(room_data.bg_color) << "\n";
out << " border: " << static_cast<int>(room_data.border_color) << "\n";
out << " tileSetFile: " << room_data.tile_set_file << "\n";
// Conexiones
@@ -59,31 +59,29 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
// Colores de items
out << "\n";
out << " # Colores de los objetos\n";
out << " itemColor1: " << (room_data.item_color1.empty() ? "yellow" : room_data.item_color1) << "\n";
out << " itemColor2: " << (room_data.item_color2.empty() ? "magenta" : room_data.item_color2) << "\n";
out << " itemColor1: " << static_cast<int>(room_data.item_color1) << "\n";
out << " itemColor2: " << static_cast<int>(room_data.item_color2) << "\n";
// Conveyor belt
out << "\n";
out << " # Dirección de la cinta transportadora: left, none, right\n";
out << " conveyorBelt: " << conveyorBeltToString(room_data.conveyor_belt_direction) << "\n";
// --- Tilemap (16 filas × 32 columnas, formato flow) ---
// --- Tilemap (MAP_HEIGHT filas × MAP_WIDTH columnas, formato flow) ---
out << "\n";
out << "# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile)\n";
out << "# Tilemap: " << Map::HEIGHT << " filas x " << Map::WIDTH << " columnas @ " << Tile::SIZE << "px/tile\n";
out << "# Índices de tiles (-1 = vacío)\n";
out << "tilemap:\n";
constexpr int MAP_WIDTH = 32;
constexpr int MAP_HEIGHT = 16;
for (int row = 0; row < MAP_HEIGHT; ++row) {
for (int row = 0; row < Map::HEIGHT; ++row) {
out << " - [";
for (int col = 0; col < MAP_WIDTH; ++col) {
int index = (row * MAP_WIDTH) + col;
for (int col = 0; col < Map::WIDTH; ++col) {
int index = (row * Map::WIDTH) + col;
if (index < static_cast<int>(room_data.tile_map.size())) {
out << room_data.tile_map[index];
} else {
out << -1;
}
if (col < MAP_WIDTH - 1) { out << ", "; }
if (col < Map::WIDTH - 1) { out << ", "; }
}
out << "]\n";
}
@@ -110,8 +108,8 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
out << " position1: {x: " << b1_x << ", y: " << b1_y << "}\n";
out << " position2: {x: " << b2_x << ", y: " << b2_y << "}\n";
if (!enemy.color.empty() && enemy.color != "white") {
out << " color: " << enemy.color << "\n";
if (enemy.color != 14) {
out << " color: " << static_cast<int>(enemy.color) << "\n";
}
if (enemy.flip) { out << " flip: true\n"; }
if (enemy.mirror) { out << " mirror: true\n"; }

View File

@@ -8,7 +8,7 @@
#include "core/rendering/surface.hpp" // Para Surface
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Margen del borde alrededor del tileset (en pixels)
static constexpr int BORDER_PAD = 3;
@@ -51,14 +51,14 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
auto prev = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(frame_surface_);
Uint8 fill_color = (bg_color >= 0) ? static_cast<Uint8>(bg_color) : stringToColor("black");
Uint8 fill_color = (bg_color >= 0) ? static_cast<Uint8>(bg_color) : 0;
frame_surface_->clear(fill_color);
// Borde doble
SDL_FRect outer = {.x = 0, .y = 0, .w = static_cast<float>(frame_w), .h = static_cast<float>(frame_h)};
frame_surface_->drawRectBorder(&outer, stringToColor("bright_white"));
frame_surface_->drawRectBorder(&outer, 15);
SDL_FRect inner = {.x = 1, .y = 1, .w = static_cast<float>(frame_w - 2), .h = static_cast<float>(frame_h - 2)};
frame_surface_->drawRectBorder(&inner, stringToColor("white"));
frame_surface_->drawRectBorder(&inner, 14);
// Renderizar cada tile individualmente
constexpr auto TS = static_cast<float>(Tile::SIZE);
@@ -153,7 +153,7 @@ void TilePicker::render() {
float hy = tileset_screen_y + static_cast<float>(row * out_cell);
if (hy >= 0 && hy + TS <= visible_height_) {
SDL_FRect highlight = {.x = hx, .y = hy, .w = TS, .h = TS};
game_surface->drawRectBorder(&highlight, stringToColor("bright_white"));
game_surface->drawRectBorder(&highlight, 15);
}
}
@@ -165,7 +165,7 @@ void TilePicker::render() {
float cy = tileset_screen_y + static_cast<float>(row * out_cell);
if (cy >= 0 && cy + TS <= visible_height_) {
SDL_FRect cur_rect = {.x = cx, .y = cy, .w = TS, .h = TS};
game_surface->drawRectBorder(&cur_rect, stringToColor("bright_green"));
game_surface->drawRectBorder(&cur_rect, 9);
}
}
}

View File

@@ -6,12 +6,11 @@
#include "core/rendering/sprite/animated_sprite.hpp" // Para SAnimatedSprite
#include "core/resources/resource_cache.hpp" // Para Resource
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Constructor
Enemy::Enemy(const Data& enemy)
: sprite_(std::make_shared<AnimatedSprite>(Resource::Cache::get()->getAnimationData(enemy.animation_path))),
color_string_(enemy.color),
x1_(enemy.x1),
x2_(enemy.x2),
y1_(enemy.y1),
@@ -30,7 +29,7 @@ Enemy::Enemy(const Data& enemy)
collider_ = getRect();
color_ = stringToColor(color_string_);
color_ = enemy.color;
// Coloca un frame al azar o el designado
sprite_->setCurrentAnimationFrame((enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame);

View File

@@ -21,7 +21,7 @@ class Enemy {
bool flip{false}; // Indica si el enemigo hace flip al terminar su ruta
bool mirror{false}; // Indica si el enemigo está volteado verticalmente
int frame{0}; // Frame inicial para la animación del enemigo
std::string color; // Color del enemigo
Uint8 color{14}; // Color del enemigo (default: white=14)
};
explicit Enemy(const Data& enemy); // Constructor
@@ -44,7 +44,6 @@ class Enemy {
// Variables
Uint8 color_{0}; // Color del enemigo
std::string color_string_; // Color del enemigo en formato texto
int x1_{0}; // Limite izquierdo de la ruta en el eje X
int x2_{0}; // Limite derecho de la ruta en el eje X
int y1_{0}; // Limite superior de la ruta en el eje Y

View File

@@ -35,8 +35,8 @@ void Player::render() {
sprite_->render(1, color_);
#ifdef _DEBUG
if (Debug::get()->isEnabled()) {
Screen::get()->getRendererSurface()->putPixel(under_right_foot_.x, under_right_foot_.y, static_cast<Uint8>(PaletteColor::GREEN));
Screen::get()->getRendererSurface()->putPixel(under_left_foot_.x, under_left_foot_.y, static_cast<Uint8>(PaletteColor::GREEN));
Screen::get()->getRendererSurface()->putPixel(under_right_foot_.x, under_right_foot_.y, 8);
Screen::get()->getRendererSurface()->putPixel(under_left_foot_.x, under_left_foot_.y, 8);
}
#endif
}
@@ -566,14 +566,14 @@ void Player::setColor(Uint8 color) {
if (Options::game.player_color >= 0) {
color_ = static_cast<Uint8>(Options::game.player_color);
} else {
color_ = static_cast<Uint8>(PaletteColor::WHITE);
color_ = 14;
}
// Si el color coincide con el fondo de la habitación, usar fallback
if (room_ != nullptr && color_ == room_->getBGColor()) {
color_ = (room_->getBGColor() != static_cast<Uint8>(PaletteColor::WHITE))
? static_cast<Uint8>(PaletteColor::WHITE)
: static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
color_ = (room_->getBGColor() != 14)
? 14
: 1;
}
}

View File

@@ -4,6 +4,7 @@
#include <vector> // Para vector
#include "utils/defines.hpp" // Para Tile::SIZE, Map::WIDTH, Map::HEIGHT
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
/**
@@ -83,9 +84,9 @@ class CollisionMap {
private:
// --- Constantes ---
static constexpr int TILE_SIZE = 8; // Tamaño del tile en pixels
static constexpr int MAP_WIDTH = 32; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = 16; // Alto del mapa en tiles
static constexpr int TILE_SIZE = ::Tile::SIZE; // Tamaño del tile en pixels
static constexpr int MAP_WIDTH = ::Map::WIDTH; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = ::Map::HEIGHT; // Alto del mapa en tiles
// --- Datos de la habitación ---
std::vector<int> tile_map_; // Índices de tiles de la habitación

View File

@@ -14,7 +14,7 @@
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
#include "game/gameplay/tilemap_renderer.hpp" // Para TilemapRenderer
#include "utils/defines.hpp" // Para TILE_SIZE
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Constructor
Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
@@ -35,7 +35,7 @@ Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
tilemap_renderer_ = std::make_unique<TilemapRenderer>(tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_);
tilemap_renderer_->initialize(collision_map_.get()); // Inicializa (crea map_surface, pinta tiles, busca animados)
Screen::get()->setBorderColor(stringToColor(border_color_)); // Establece el color del borde
Screen::get()->setBorderColor(border_color_); // Establece el color del borde
}
// Destructor
@@ -46,8 +46,8 @@ void Room::initializeRoom(const Data& room) {
number_ = room.number;
bg_color_ = room.bg_color;
border_color_ = room.border_color;
item_color1_ = room.item_color1.empty() ? "yellow" : room.item_color1;
item_color2_ = room.item_color2.empty() ? "magenta" : room.item_color2;
item_color1_ = room.item_color1;
item_color2_ = room.item_color2;
upper_room_ = room.upper_room;
lower_room_ = room.lower_room;
left_room_ = room.left_room;
@@ -71,8 +71,8 @@ void Room::initializeRoom(const Data& room) {
if (!ItemTracker::get()->hasBeenPicked(room.number, ITEM_POS)) {
// Crear una copia local de los datos del item
Item::Data item_copy = item;
item_copy.color1 = stringToColor(item_color1_);
item_copy.color2 = stringToColor(item_color2_);
item_copy.color1 = item_color1_;
item_copy.color2 = item_color2_;
// Crear el objeto Item usando la copia modificada
item_manager_->addItem(std::make_shared<Item>(item_copy));
@@ -142,21 +142,19 @@ void Room::setTile(int index, int tile_value) {
}
// Cambia color de fondo y redibuja el mapa (para editor)
void Room::setBgColor(const std::string& color) {
void Room::setBgColor(Uint8 color) {
bg_color_ = color;
tilemap_renderer_->setBgColor(color);
tilemap_renderer_->redrawMap(collision_map_.get());
}
// Cambia colores de items en vivo (para editor)
void Room::setItemColors(const std::string& color1, const std::string& color2) {
void Room::setItemColors(Uint8 color1, Uint8 color2) {
item_color1_ = color1;
item_color2_ = color2;
Uint8 c1 = stringToColor(color1);
Uint8 c2 = stringToColor(color2);
auto* item_mgr = item_manager_.get();
for (int i = 0; i < item_mgr->getCount(); ++i) {
item_mgr->getItem(i)->setColors(c1, c2);
item_mgr->getItem(i)->setColors(color1, color2);
}
}
#endif

View File

@@ -9,6 +9,7 @@
#include "game/entities/enemy.hpp" // Para EnemyData
#include "game/entities/item.hpp" // Para ItemData
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
#include "utils/defines.hpp" // Para Tile::SIZE, Map::WIDTH, Map::HEIGHT
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
class Sprite; // lines 12-12
class Surface; // lines 13-13
@@ -40,10 +41,10 @@ class Room {
struct Data {
std::string number; // Numero de la habitación
std::string bg_color; // Color de fondo de la habitación
std::string border_color; // Color del borde de la pantalla
std::string item_color1; // Color 1 para los items de la habitación
std::string item_color2; // Color 2 para los items de la habitación
Uint8 bg_color{0}; // Color de fondo de la habitación
Uint8 border_color{0}; // Color del borde de la pantalla
Uint8 item_color1{12}; // Color 1 para los items de la habitación
Uint8 item_color2{6}; // Color 2 para los items de la habitación
std::string upper_room; // Identificador de la habitación que se encuentra arriba
std::string lower_room; // Identificador de la habitación que se encuentra abajo
std::string left_room; // Identificador de la habitación que se encuentra a la izquierda
@@ -61,8 +62,8 @@ class Room {
// --- Funciones ---
[[nodiscard]] auto getNumber() const -> const std::string& { return number_; } // Devuelve el numero de la habitación
[[nodiscard]] auto getBGColor() const -> Uint8 { return stringToColor(bg_color_); } // Devuelve el color de la habitación
[[nodiscard]] auto getBorderColor() const -> Uint8 { return stringToColor(border_color_); } // Devuelve el color del borde
[[nodiscard]] auto getBGColor() const -> Uint8 { return bg_color_; } // Devuelve el color de la habitación
[[nodiscard]] auto getBorderColor() const -> Uint8 { return border_color_; } // Devuelve el color del borde
void renderMap(); // Dibuja el mapa en pantalla
void renderEnemies(); // Dibuja los enemigos en pantalla
void renderItems(); // Dibuja los objetos en pantalla
@@ -72,8 +73,8 @@ class Room {
void resetEnemyPositions(const std::vector<Enemy::Data>& enemy_data); // Resetea enemigos a posiciones iniciales
auto getEnemyManager() -> EnemyManager* { return enemy_manager_.get(); } // Acceso al gestor de enemigos (para editor)
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 setBgColor(Uint8 color); // Cambia color de fondo y redibuja (para editor)
void setItemColors(Uint8 color1, Uint8 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_; }
@@ -106,9 +107,9 @@ class Room {
private:
// Constantes
static constexpr int TILE_SIZE = 8; // Ancho del tile en pixels
static constexpr int MAP_WIDTH = 32; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = 16; // Alto del mapa en tiles
static constexpr int TILE_SIZE = ::Tile::SIZE; // Ancho del tile en pixels
static constexpr int MAP_WIDTH = ::Map::WIDTH; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = ::Map::HEIGHT; // Alto del mapa en tiles
// Objetos y punteros
std::unique_ptr<EnemyManager> enemy_manager_; // Gestor de enemigos de la habitación
@@ -120,10 +121,10 @@ class Room {
// --- Variables ---
std::string number_; // Numero de la habitación
std::string bg_color_; // Color de fondo de la habitación
std::string border_color_; // Color del borde de la pantalla
std::string item_color1_; // Color 1 para los items de la habitación
std::string item_color2_; // Color 2 para los items de la habitación
Uint8 bg_color_{0}; // Color de fondo de la habitación
Uint8 border_color_{0}; // Color del borde de la pantalla
Uint8 item_color1_{12}; // Color 1 para los items de la habitación
Uint8 item_color2_{6}; // Color 2 para los items de la habitación
std::string upper_room_; // Identificador de la habitación que se encuentra arriba
std::string lower_room_; // Identificador de la habitación que se encuentra abajp
std::string left_room_; // Identificador de la habitación que se encuentra a la izquierda

View File

@@ -6,7 +6,7 @@
#include "core/resources/resource_helper.hpp" // Para Resource::Helper
#include "external/fkyaml_node.hpp" // Para fkyaml::node
#include "utils/defines.hpp" // Para Tile::SIZE
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Convierte room connection de YAML a formato interno
auto RoomLoader::convertRoomConnection(const std::string& value) -> std::string { // NOLINT(readability-convert-member-functions-to-static)
@@ -20,11 +20,11 @@ auto RoomLoader::convertRoomConnection(const std::string& value) -> std::string
return value + ".yaml";
}
// Lee un nodo de color tolerando tanto string ("red", "bright_blue") como entero (índice de paleta)
static auto readColorNode(const fkyaml::node& node) -> std::string {
if (node.is_string()) { return node.get_value<std::string>(); }
if (node.is_integer()) { return std::to_string(node.get_value<int>()); }
return "black";
// Lee un nodo de color como Uint8 (acepta entero directo o string numérico)
static auto readColorNode(const fkyaml::node& node) -> Uint8 {
if (node.is_integer()) { return static_cast<Uint8>(node.get_value<int>()); }
if (node.is_string()) { return static_cast<Uint8>(safeStoi(node.get_value<std::string>(), 0)); }
return 0;
}
// Convierte string de autoSurface a int
@@ -47,7 +47,7 @@ auto RoomLoader::convertAutoSurface(const fkyaml::node& node) -> int { // NOLIN
// Convierte un tilemap 2D a vector 1D flat
auto RoomLoader::flattenTilemap(const std::vector<std::vector<int>>& tilemap_2d) -> std::vector<int> { // NOLINT(readability-convert-member-functions-to-static, readability-named-parameter)
std::vector<int> tilemap_flat;
tilemap_flat.reserve(512); // 16 rows × 32 cols
tilemap_flat.reserve(Map::WIDTH * Map::HEIGHT);
for (const auto& row : tilemap_2d) {
for (int tile : row) {
@@ -86,13 +86,13 @@ void RoomLoader::parseRoomConfig(const fkyaml::node& yaml, Room::Data& room, con
}
// Item colors
room.item_color1 = room_node.contains("itemColor1")
? readColorNode(room_node["itemColor1"])
: "yellow";
if (room_node.contains("itemColor1")) {
room.item_color1 = readColorNode(room_node["itemColor1"]);
}
room.item_color2 = room_node.contains("itemColor2")
? readColorNode(room_node["itemColor2"])
: "magenta";
if (room_node.contains("itemColor2")) {
room.item_color2 = readColorNode(room_node["itemColor2"]);
}
// Dirección de la cinta transportadora (left/none/right)
room.conveyor_belt_direction = room_node.contains("conveyorBelt")
@@ -130,11 +130,11 @@ void RoomLoader::parseTilemap(const fkyaml::node& yaml, Room::Data& room, const
// Read 2D array
std::vector<std::vector<int>> tilemap_2d;
tilemap_2d.reserve(16);
tilemap_2d.reserve(Map::HEIGHT);
for (const auto& row_node : tilemap_node) {
std::vector<int> row;
row.reserve(32);
row.reserve(Map::WIDTH);
for (const auto& tile_node : row_node) {
row.push_back(tile_node.get_value<int>());
@@ -225,9 +225,9 @@ auto RoomLoader::parseEnemyData(const fkyaml::node& enemy_node) -> Enemy::Data {
}
// Color
enemy.color = enemy_node.contains("color")
? enemy_node["color"].get_value_or<std::string>("white")
: "white";
if (enemy_node.contains("color")) {
enemy.color = readColorNode(enemy_node["color"]);
}
// Optional fields
enemy.flip = enemy_node.contains("flip")
@@ -293,8 +293,8 @@ auto RoomLoader::parseItemData(const fkyaml::node& item_node, const Room::Data&
: 0;
// Colors (assigned from room defaults)
item.color1 = stringToColor(room.item_color1);
item.color2 = stringToColor(room.item_color2);
item.color1 = room.item_color1;
item.color2 = room.item_color2;
return item;
}

View File

@@ -13,7 +13,7 @@
#include "game/entities/player.hpp" // Para Player::skinToAnimationPath
#include "game/options.hpp" // Para Options, options, Cheat, OptionsGame
#include "utils/defines.hpp" // Para BLOCK
#include "utils/utils.hpp" // Para stringToColor
#include "utils/utils.hpp"
// Constructor
Scoreboard::Scoreboard(std::shared_ptr<Data> data)
@@ -32,13 +32,10 @@ Scoreboard::Scoreboard(std::shared_ptr<Data> data)
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
// Inicializa el color de items
items_color_ = stringToColor("white");
items_color_ = 14;
// Inicializa el vector de colores
const std::vector<std::string> COLORS = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
for (const auto& color : COLORS) {
color_.push_back(stringToColor(color));
}
color_ = {2, 6, 8, 10, 12, 14, 3, 7, 9, 11, 13, 15};
}
// Pinta el objeto en pantalla
@@ -118,9 +115,9 @@ void Scoreboard::updateItemsColor(float delta_time) {
// Alternar color cada ITEMS_COLOR_BLINK_DURATION
if (items_color_timer_ < ITEMS_COLOR_BLINK_DURATION) {
items_color_ = stringToColor("white");
items_color_ = 14;
} else {
items_color_ = stringToColor("magenta");
items_color_ = 6;
}
}
@@ -136,7 +133,7 @@ void Scoreboard::fillTexture() {
Screen::get()->setRendererSurface(surface_);
// Limpia la textura
surface_->clear(stringToColor("black"));
surface_->clear(0);
// Dibuja las vidas
const int WALK_FRAMES = player_sprite_->getCurrentAnimationSize();
@@ -164,11 +161,11 @@ void Scoreboard::fillTexture() {
text->writeColored(ITEMS_LABEL_X, LINE1_Y, Locale::get()->get("scoreboard.items"), data_->color); // NOLINT(readability-static-accessed-through-instance)
text->writeColored(ITEMS_VALUE_X, LINE1_Y, ITEMS_TEXT, items_color_);
text->writeColored(TIME_LABEL_X, LINE1_Y, Locale::get()->get("scoreboard.time"), data_->color); // NOLINT(readability-static-accessed-through-instance)
text->writeColored(TIME_VALUE_X, LINE1_Y, TIME_TEXT, stringToColor("white"));
text->writeColored(TIME_VALUE_X, LINE1_Y, TIME_TEXT, 14);
const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10);
text->writeColored(ROOMS_LABEL_X, LINE2_Y, Locale::get()->get("scoreboard.rooms"), stringToColor("white")); // NOLINT(readability-static-accessed-through-instance)
text->writeColored(ROOMS_VALUE_X, LINE2_Y, ROOMS_TEXT, stringToColor("white"));
text->writeColored(ROOMS_LABEL_X, LINE2_Y, Locale::get()->get("scoreboard.rooms"), 14); // NOLINT(readability-static-accessed-through-instance)
text->writeColored(ROOMS_VALUE_X, LINE2_Y, ROOMS_TEXT, 14);
// Indicadores de trucos activos (fuente 8bithud)
auto cheat_text = Resource::Cache::get()->getText("8bithud");

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

View File

@@ -31,7 +31,7 @@ class TilemapRenderer {
* @param bg_color Color de fondo de la habitación (como string)
* @param conveyor_belt_direction Dirección de las cintas transportadoras (-1, 0, +1)
*/
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(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, Uint8 bg_color, int conveyor_belt_direction);
~TilemapRenderer() = default;
// Prohibir copia y movimiento
@@ -69,7 +69,7 @@ class TilemapRenderer {
* Llamado cuando se activa/desactiva el modo debug para actualizar la visualización
*/
void redrawMap(const CollisionMap* collision_map);
void setBgColor(const std::string& color) { bg_color_ = color; }
void setBgColor(Uint8 color) { bg_color_ = color; }
void setTile(int index, int tile_value); // Cambia un tile y repinta esa celda
#endif
@@ -92,9 +92,9 @@ class TilemapRenderer {
};
// === Constantes ===
static constexpr int TILE_SIZE = Tile::SIZE; // Ancho del tile en pixels
static constexpr int MAP_WIDTH = PlayArea::WIDTH / Tile::SIZE; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = PlayArea::HEIGHT / Tile::SIZE; // Alto del mapa en tiles
static constexpr int TILE_SIZE = Tile::SIZE; // Ancho del tile en pixels
static constexpr int MAP_WIDTH = Map::WIDTH; // Ancho del mapa en tiles
static constexpr int MAP_HEIGHT = Map::HEIGHT; // Alto del mapa en tiles
static constexpr int PLAY_AREA_WIDTH = PlayArea::WIDTH; // Ancho del área de juego en pixels
static constexpr int PLAY_AREA_HEIGHT = PlayArea::HEIGHT; // Alto del área de juego en pixels
static constexpr float CONVEYOR_FRAME_DURATION = 0.05F; // Duración de cada frame (3 frames @ 60fps)
@@ -103,7 +103,7 @@ class TilemapRenderer {
std::vector<int> tile_map_; // Índices de tiles de la habitación
int tile_set_width_; // Ancho del tileset en tiles
std::shared_ptr<Surface> tileset_surface_; // Gráficos del tileset
std::string bg_color_; // Color de fondo
Uint8 bg_color_{0}; // Color de fondo
int conveyor_belt_direction_; // Dirección de conveyor belts
// === Renderizado ===

View File

@@ -32,7 +32,7 @@ Credits::Credits()
SceneManager::options = SceneManager::Options::NONE;
shining_sprite_->setPos({.x = 194, .y = 174, .w = 8, .h = 8});
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
Screen::get()->setBorderColor(0); // Cambia el color del borde
fillTexture(); // Escribe el texto en la textura
Audio::get()->playMusic("574071_EA_DTV.ogg"); // Inicia la musica
}
@@ -56,33 +56,33 @@ void Credits::iniTexts() { // NOLINT(readability-convert-member-functions-to-st
auto* loc = Locale::get();
texts_.clear();
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.instructions"), .color = static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.l0"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.l1"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.l2"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.instructions"), .color = 12});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.l0"), .color = 14});
texts_.push_back({.label = loc->get("credits.l1"), .color = 14});
texts_.push_back({.label = loc->get("credits.l2"), .color = 14});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.keys"), .color = static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.keys_move"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.f8"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.f11"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.f1f2"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.f3"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.f9"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.keys"), .color = 12});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.keys_move"), .color = 14});
texts_.push_back({.label = loc->get("credits.f8"), .color = 14});
texts_.push_back({.label = loc->get("credits.f11"), .color = 14});
texts_.push_back({.label = loc->get("credits.f1f2"), .color = 14});
texts_.push_back({.label = loc->get("credits.f3"), .color = 14});
texts_.push_back({.label = loc->get("credits.f9"), .color = 14});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.author"), .color = static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({.label = loc->get("credits.date"), .color = static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.author"), .color = 12});
texts_.push_back({.label = loc->get("credits.date"), .color = 12});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = "", .color = 14});
texts_.push_back({.label = loc->get("credits.love"), .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = "", .color = static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({.label = loc->get("credits.love"), .color = 14});
texts_.push_back({.label = "", .color = 14});
}
// Escribe el texto en la textura
@@ -93,7 +93,7 @@ void Credits::fillTexture() {
// Rellena la textura de texto
auto previuos_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(text_surface_);
text_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
text_surface_->clear(0);
auto text = Resource::Cache::get()->getText("smb2");
@@ -109,7 +109,7 @@ void Credits::fillTexture() {
// Escribe el corazón
const int TEXT_LENGHT = text->length(texts_[22].label, 1) - text->length(" ", 1); // Se resta el ultimo caracter que es un espacio
const int POS_X = ((PlayArea::WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT;
text->writeColored(POS_X, 176, "ä", static_cast<Uint8>(PaletteColor::BRIGHT_RED));
text->writeColored(POS_X, 176, "ä", 5);
Screen::get()->setRendererSurface(previuos_renderer);
// Recoloca el sprite del brillo
@@ -219,7 +219,7 @@ void Credits::render() {
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
if (state_ != State::EXITING) {
// Dibuja la textura con el texto en pantalla
@@ -230,7 +230,7 @@ void Credits::render() {
// Dibuja el sprite con el brillo
if (reveal_time_ > SHINE_START_TIME) {
shining_sprite_->render(1, static_cast<Uint8>(PaletteColor::BRIGHT_WHITE));
shining_sprite_->render(1, 15);
}
}

View File

@@ -31,7 +31,7 @@ Ending::Ending()
iniPics(); // Inicializa las imagenes
iniScenes(); // Inicializa las escenas
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
Screen::get()->setBorderColor(0); // Cambia el color del borde
}
// Actualiza el objeto
@@ -55,7 +55,7 @@ void Ending::render() {
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
// Skip rendering durante WARMING_UP
if (state_ != State::WARMING_UP) {
@@ -212,8 +212,8 @@ void Ending::iniTexts() { // NOLINT(readability-convert-member-functions-to-sta
const float WIDTH = text->length(txt.caption, 1) + 2 + 2;
const float HEIGHT = text->getCharacterSize() + 2 + 2;
auto text_color = static_cast<Uint8>(PaletteColor::WHITE);
auto shadow_color = static_cast<Uint8>(PaletteColor::BLACK);
auto text_color = 14;
auto shadow_color = 0;
EndingSurface st;

View File

@@ -19,7 +19,7 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "utils/defines.hpp" // Para GameCanvas::CENTER_X, GameCanvas::CENTER_Y
#include "utils/delta_timer.hpp" // Para DeltaTimer
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#include "utils/utils.hpp"
// Constructor
Ending2::Ending2()
@@ -30,12 +30,9 @@ Ending2::Ending2()
SceneManager::options = SceneManager::Options::NONE;
// Inicializa el vector de colores
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (const auto& color : COLORS) {
colors_.push_back(stringToColor(color));
}
colors_ = {14, 12, 10, 8, 6, 4, 2, 0};
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
Screen::get()->setBorderColor(0); // Cambia el color del borde
iniSpriteList(); // Inicializa la lista de sprites
loadSprites(); // Carga todos los sprites desde una lista
placeSprites(); // Coloca los sprites en su sito
@@ -80,7 +77,7 @@ void Ending2::render() {
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
// Dibuja los sprites
renderSprites();
@@ -269,14 +266,14 @@ void Ending2::loadSprites() {
for (const auto& file : sprite_list_) {
const auto& animation_data = Resource::Cache::get()->getAnimationData(file + ".yaml");
sprites_.emplace_back(std::make_shared<DissolveSprite>(animation_data));
sprites_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::RED));
sprites_.back()->setColorReplace(1, 4);
sprites_.back()->setProgress(1.0F); // comença invisible
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
}
// El último sprite (player) va en blanco, no en rojo
sprites_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::WHITE));
sprites_.back()->setColorReplace(1, 14);
}
// Actualiza los sprites
@@ -428,7 +425,7 @@ void Ending2::createSpriteTexts() { // NOLINT(readability-convert-member-functi
// Crea el sprite
SDL_FRect pos = {.x = X, .y = Y, .w = W, .h = H};
sprite_texts_.emplace_back(std::make_shared<DissolveSprite>(surface, pos));
sprite_texts_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::WHITE));
sprite_texts_.back()->setColorReplace(1, 14);
sprite_texts_.back()->setProgress(1.0F); // comença invisible
sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED);
Screen::get()->setRendererSurface(previuos_renderer);

View File

@@ -28,7 +28,7 @@
#include "game/ui/console.hpp" // Para Console
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea::HEIGHT, RoomBorder::BOTTOM
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#include "utils/utils.hpp"
#ifdef _DEBUG
#include "core/system/debug.hpp" // Para Debug
@@ -489,7 +489,7 @@ void Game::renderPlaying() {
// Renderiza el juego en estado BLACK_SCREEN (pantalla negra)
void Game::renderBlackScreen() {
Screen::get()->start();
auto const COLOR = static_cast<Uint8>(PaletteColor::BLACK);
auto const COLOR = 0;
Screen::get()->clearSurface(COLOR);
Screen::get()->setBorderColor(COLOR);
Screen::get()->render();
@@ -498,7 +498,7 @@ void Game::renderBlackScreen() {
// Renderiza el juego en estado GAME_OVER (pantalla negra)
void Game::renderGameOver() {
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
Screen::get()->render();
}
@@ -511,7 +511,7 @@ void Game::renderFadeToEnding() {
Screen::get()->setRendererSurface(game_backbuffer_surface_);
// 3. Renderizar todo a backbuffer
game_backbuffer_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
game_backbuffer_surface_->clear(0);
room_->renderMap();
room_->renderEnemies();
room_->renderItems();
@@ -530,7 +530,7 @@ void Game::renderFadeToEnding() {
// Renderiza el juego en estado POST_FADE_ENDING (pantalla negra)
void Game::renderPostFadeEnding() {
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
Screen::get()->render();
}
@@ -550,18 +550,18 @@ void Game::renderDebugInfo() {
// Borra el marcador
SDL_FRect rect = {.x = 0, .y = 18 * Tile::SIZE, .w = PlayArea::WIDTH, .h = GameCanvas::HEIGHT - PlayArea::HEIGHT};
surface->fillRect(&rect, static_cast<Uint8>(PaletteColor::BLACK));
surface->fillRect(&rect, 0);
// Pinta la rejilla
/*for (int i = 0; i < PlayArea::BOTTOM; i += 8)
{
// Lineas horizontales
surface->drawLine(0, i, PlayArea::RIGHT, i, static_cast<Uint8>(PaletteColor::BRIGHT_BLACK));
surface->drawLine(0, i, PlayArea::RIGHT, i, 1);
}
for (int i = 0; i < PlayArea::RIGHT; i += 8)
{
// Lineas verticales
surface->drawLine(i, 0, i, PlayArea::BOTTOM - 1, static_cast<Uint8>(PaletteColor::BRIGHT_BLACK));
surface->drawLine(i, 0, i, PlayArea::BOTTOM - 1, 1);
}*/
// Pinta el texto
@@ -815,11 +815,11 @@ void Game::setScoreBoardColor() { // NOLINT(readability-convert-member-function
// Obtiene el color del borde
const Uint8 BORDER_COLOR = room_->getBorderColor();
const bool IS_BLACK = BORDER_COLOR == static_cast<Uint8>(PaletteColor::BLACK);
const bool IS_BRIGHT_BLACK = BORDER_COLOR == static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
const bool IS_BLACK = BORDER_COLOR == 0;
const bool IS_BRIGHT_BLACK = BORDER_COLOR == 1;
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
scoreboard_data_->color = IS_BLACK || IS_BRIGHT_BLACK ? static_cast<Uint8>(PaletteColor::WHITE) : BORDER_COLOR;
scoreboard_data_->color = IS_BLACK || IS_BRIGHT_BLACK ? 14 : BORDER_COLOR;
}
// Comprueba si ha finalizado el juego

View File

@@ -18,7 +18,7 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "utils/defines.hpp" // Para GameCanvas::CENTER_X
#include "utils/delta_timer.hpp" // Para DeltaTimer
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#include "utils/utils.hpp"
// Constructor
GameOver::GameOver()
@@ -34,13 +34,10 @@ GameOver::GameOver()
tv_sprite_->setPosX(GameCanvas::CENTER_X - tv_sprite_->getWidth() - TV_X_OFFSET);
tv_sprite_->setPosY(TEXT_Y + SPRITE_Y_OFFSET);
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->setBorderColor(0);
// Inicializa el vector de colores (de brillante a oscuro para fade)
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (const auto& color : COLORS) {
colors_.push_back(stringToColor(color));
}
colors_ = {14, 12, 10, 8, 6, 4, 2, 0};
color_ = colors_.back(); // Empieza en black
}
@@ -64,7 +61,7 @@ void GameOver::update() {
// Dibuja el final en pantalla
void GameOver::render() {
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
auto text = Resource::Cache::get()->getText("smb2");

View File

@@ -16,7 +16,7 @@
#include "game/options.hpp" // Para Options, options, SectionState, Options...
#include "game/scene_manager.hpp" // Para SceneManager
#include "utils/defines.hpp" // Para GAME_SPEED
#include "utils/utils.hpp" // Para stringToColor, PaletteColor
#include "utils/utils.hpp"
// Constructor
LoadingScreen::LoadingScreen()
@@ -28,7 +28,7 @@ LoadingScreen::LoadingScreen()
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
delta_timer_(std::make_unique<DeltaTimer>()) {
// Configura la superficie donde se van a pintar los sprites
screen_surface_->clear(static_cast<Uint8>(PaletteColor::WHITE));
screen_surface_->clear(14);
// Inicializa variables
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
@@ -39,7 +39,7 @@ LoadingScreen::LoadingScreen()
initLineIndexArray();
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("white"));
Screen::get()->setBorderColor(14);
transitionToState(State::SILENT1);
}
@@ -279,10 +279,10 @@ void LoadingScreen::renderDataBorder() {
auto border = Screen::get()->getBorderSurface();
// Pinta el borde de color azul
border->clear(static_cast<Uint8>(PaletteColor::BLUE));
border->clear(2);
// Añade lineas amarillas
const auto COLOR = static_cast<Uint8>(PaletteColor::YELLOW);
const auto COLOR = 12;
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
bool draw_enabled = rand() % 2 == 0;
@@ -306,10 +306,10 @@ void LoadingScreen::renderHeaderBorder() const {
auto border = Screen::get()->getBorderSurface();
// Pinta el borde de color azul o rojo
border->clear(carrier_.toggle ? static_cast<Uint8>(PaletteColor::CYAN) : static_cast<Uint8>(PaletteColor::RED));
border->clear(carrier_.toggle ? 10 : 4);
// Añade lineas rojas o azules
const auto COLOR = carrier_.toggle ? static_cast<Uint8>(PaletteColor::RED) : static_cast<Uint8>(PaletteColor::CYAN);
const auto COLOR = carrier_.toggle ? 4 : 10;
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
@@ -335,12 +335,12 @@ void LoadingScreen::renderHeaderBorder() const {
}
// Dibuja el borde de color
void LoadingScreen::renderColoredBorder(PaletteColor color) {
void LoadingScreen::renderColoredBorder(Uint8 color) {
// Obtiene la Surface del borde
auto border = Screen::get()->getBorderSurface();
// Pinta el borde de color azul
border->clear(static_cast<Uint8>(color));
// Pinta el borde del color indicado
border->clear(color);
}
// Actualiza las variables
@@ -391,7 +391,7 @@ void LoadingScreen::render() {
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
Screen::get()->clearSurface(stringToColor("white"));
Screen::get()->clearSurface(14);
// Copia la surface a la surface de Screen
screen_surface_->render(0, 0);
@@ -430,16 +430,16 @@ void LoadingScreen::renderBorder() {
renderHeaderBorder();
break;
case Border::WHITE:
renderColoredBorder(PaletteColor::WHITE);
renderColoredBorder(14);
break;
case Border::BLACK:
renderColoredBorder(PaletteColor::BLACK);
renderColoredBorder(0);
break;
case Border::RED:
renderColoredBorder(PaletteColor::RED);
renderColoredBorder(4);
break;
case Border::CYAN:
renderColoredBorder(PaletteColor::CYAN);
renderColoredBorder(10);
break;
case Border::NONE:
// No renderizar borde

View File

@@ -6,7 +6,6 @@
#include <memory> // Para shared_ptr
#include "utils/delta_timer.hpp" // Para DeltaTimer
#include "utils/utils.hpp" // Para PaletteColor
class Sprite; // Forward declaration
class Surface; // Forward declaration
@@ -90,7 +89,7 @@ class LoadingScreen {
void renderBorder(); // Pinta el borde
static void renderDataBorder(); // Dibuja el efecto de carga amarillo y azul en el borde
void renderHeaderBorder() const; // Dibuja el efecto de carga rojo y azul en el borde
static void renderColoredBorder(PaletteColor color); // Dibuja el borde de color
static void renderColoredBorder(Uint8 color); // Dibuja el borde de color
void initLineIndexArray(); // Inicializa el array de índices de líneas
void printProgramName(); // Escribe el nombre del programa
void updateCarrier(float delta_time); // Actualiza la portadora

View File

@@ -28,8 +28,8 @@ Logo::Logo()
delta_timer_(std::make_unique<DeltaTimer>()) {
// Configura variables
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
since_1998_color_ = static_cast<Uint8>(PaletteColor::BLACK);
jailgames_color_ = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
since_1998_color_ = 0;
jailgames_color_ = 15;
// Inicializa variables
SceneManager::current = SceneManager::Scene::LOGO;
@@ -51,7 +51,7 @@ Logo::Logo()
easing_function_ = EASING_OPTIONS[dist(gen)];
// Cambia el color del borde
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->setBorderColor(0);
}
// Comprueba el manejador de eventos
@@ -216,7 +216,7 @@ void Logo::update() {
void Logo::render() { // NOLINT(readability-convert-member-functions-to-static)
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
// Dibuja los objetos
for (const auto& sprite : jailgames_sprite_) {
@@ -257,14 +257,14 @@ void Logo::endSection() {
void Logo::initColors() { // NOLINT(readability-convert-member-functions-to-static)
// Inicializa el vector de colores
const std::vector<Uint8> COLORS = {
static_cast<Uint8>(PaletteColor::BLACK),
static_cast<Uint8>(PaletteColor::BLUE),
static_cast<Uint8>(PaletteColor::RED),
static_cast<Uint8>(PaletteColor::MAGENTA),
static_cast<Uint8>(PaletteColor::GREEN),
static_cast<Uint8>(PaletteColor::CYAN),
static_cast<Uint8>(PaletteColor::YELLOW),
static_cast<Uint8>(PaletteColor::BRIGHT_WHITE)};
0,
2,
4,
6,
8,
10,
12,
15};
for (const auto& color : COLORS) {
color_.push_back(color);
}

View File

@@ -20,7 +20,7 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/ui/console.hpp" // Para Console
#include "utils/defines.hpp" // Para PlayArea::CENTER_X, GameCanvas::WIDTH
#include "utils/utils.hpp" // Para stringToColor, PaletteColor, playMusic
#include "utils/utils.hpp"
// Constructor
Title::Title()
@@ -46,7 +46,7 @@ Title::Title()
// Acciones iniciales
initMarquee(); // Inicializa la marquesina
createCheevosTexture(); // Crea y rellena la textura para mostrar los logros
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
Screen::get()->setBorderColor(0); // Cambia el color del borde
Audio::get()->playMusic("574071_EA_DTV.ogg"); // Inicia la musica
}
@@ -233,7 +233,7 @@ void Title::renderMarquee() const {
if (letter.enabled && letter.clip.w > 0.0F) {
sprite->setClip(letter.clip);
sprite->setX(letter.x);
sprite->render(1, static_cast<Uint8>(PaletteColor::MAGENTA));
sprite->render(1, 6);
}
}
}
@@ -425,7 +425,7 @@ void Title::render() {
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
Screen::get()->clearSurface(0);
// Dibuja en pantalla la surface con la composicion
title_surface_->render();
@@ -463,17 +463,17 @@ void Title::createCheevosTexture() { // NOLINT(readability-convert-member-funct
Screen::get()->setRendererSurface(cheevos_surface_);
// Rellena la textura con color sólido
const auto CHEEVOS_BG_COLOR = static_cast<Uint8>(PaletteColor::BLACK);
const auto CHEEVOS_BG_COLOR = 0;
cheevos_surface_->clear(CHEEVOS_BG_COLOR);
// Escribe la lista de logros en la textura
const std::string CHEEVOS_OWNER = Locale::get()->get("title.projects"); // NOLINT(readability-static-accessed-through-instance)
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
int pos = 2;
TEXT->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, cheevos_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor("bright_green"));
TEXT->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, cheevos_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, 9);
pos += TEXT->getCharacterSize();
const Uint8 CHEEVO_LOCKED_COLOR = stringToColor("white");
const Uint8 CHEEVO_UNLOCKED_COLOR = stringToColor("bright_green");
const Uint8 CHEEVO_LOCKED_COLOR = 14;
const Uint8 CHEEVO_UNLOCKED_COLOR = 9;
constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
@@ -526,7 +526,7 @@ void Title::renderMainMenu() {
constexpr int MENU_ZONE_HEIGHT = 102;
// Menú principal normal con 4 opciones centradas verticalmente en la zona
const Uint8 COLOR = stringToColor("green");
const Uint8 COLOR = 8;
const int TEXT_SIZE = menu_text_->getCharacterSize();
const int MENU_CENTER_Y = MENU_ZONE_Y + (MENU_ZONE_HEIGHT / 2);
const int SPACING = 2 * TEXT_SIZE; // Espaciado entre opciones
@@ -554,7 +554,7 @@ void Title::fillTitleSurface() {
Screen::get()->setRendererSurface(title_surface_);
// Rellena la textura de color
title_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
title_surface_->clear(0);
switch (state_) {
case State::MAIN_MENU:
@@ -676,8 +676,8 @@ void Title::renderKeyboardRemap() const {
constexpr int MENU_ZONE_Y = 73;
constexpr int MENU_ZONE_HEIGHT = 102;
const Uint8 COLOR = stringToColor("green");
const Uint8 ERROR_COLOR = stringToColor("red");
const Uint8 COLOR = 8;
const Uint8 ERROR_COLOR = 4;
const int TEXT_SIZE = menu_text_->getCharacterSize();
const int MENU_CENTER_Y = MENU_ZONE_Y + (MENU_ZONE_HEIGHT / 2);
@@ -724,8 +724,8 @@ void Title::renderJoystickRemap() const {
constexpr int MENU_ZONE_Y = 73;
constexpr int MENU_ZONE_HEIGHT = 102;
const Uint8 COLOR = stringToColor("green");
const Uint8 ERROR_COLOR = stringToColor("red");
const Uint8 COLOR = 8;
const Uint8 ERROR_COLOR = 4;
const int TEXT_SIZE = menu_text_->getCharacterSize();
const int MENU_CENTER_Y = MENU_ZONE_Y + (MENU_ZONE_HEIGHT / 2);

View File

@@ -1024,9 +1024,14 @@ void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cogni
};
#ifdef _DEBUG
// Colores de la paleta (compartido por SET COLOR, BGCOLOR, BORDER, ITEMCOLOR1, ITEMCOLOR2)
// Colores de la paleta como índices numéricos (compartido por SET COLOR, BGCOLOR, BORDER, ITEMCOLOR1, ITEMCOLOR2)
auto color_provider = []() -> std::vector<std::string> {
return {"BLACK", "BRIGHT_BLACK", "BLUE", "BRIGHT_BLUE", "RED", "BRIGHT_RED", "MAGENTA", "BRIGHT_MAGENTA", "GREEN", "BRIGHT_GREEN", "CYAN", "BRIGHT_CYAN", "YELLOW", "BRIGHT_YELLOW", "WHITE", "BRIGHT_WHITE"};
std::vector<std::string> result;
result.reserve(64);
for (int i = 0; i < 64; ++i) {
result.push_back(std::to_string(i));
}
return result;
};
dynamic_providers_["SET COLOR"] = color_provider;
dynamic_providers_["SET BGCOLOR"] = color_provider;

View File

@@ -23,9 +23,9 @@ Notifier* Notifier::notifier = nullptr;
// Definición de estilos predefinidos
const Notifier::Style Notifier::Style::DEFAULT = {
.bg_color = static_cast<Uint8>(PaletteColor::BLUE),
.border_color = static_cast<Uint8>(PaletteColor::CYAN),
.text_color = static_cast<Uint8>(PaletteColor::CYAN),
.bg_color = 2,
.border_color = 10,
.text_color = 10,
.shape = Notifier::Shape::SQUARED,
.text_align = Notifier::TextAlign::CENTER,
.duration = 2.0F,
@@ -33,9 +33,9 @@ const Notifier::Style Notifier::Style::DEFAULT = {
.play_sound = false};
const Notifier::Style Notifier::Style::CHEEVO = {
.bg_color = static_cast<Uint8>(PaletteColor::MAGENTA),
.border_color = static_cast<Uint8>(PaletteColor::BRIGHT_MAGENTA),
.text_color = static_cast<Uint8>(PaletteColor::WHITE),
.bg_color = 6,
.border_color = 7,
.text_color = 14,
.shape = Notifier::Shape::SQUARED,
.text_align = Notifier::TextAlign::CENTER,
.duration = 4.0F,