Ja torna a deixar jugar

Encara queden bugs per corregir
Trencat el sistema de triar la paleta, de moment
This commit is contained in:
2025-02-26 20:37:29 +01:00
parent 85ab5ea03f
commit e6fd4225a2
7 changed files with 362 additions and 384 deletions

View File

@@ -41,9 +41,9 @@ Demo::Demo()
currentRoom = rooms[roomIndex]; currentRoom = rooms[roomIndex];
// Crea los objetos // Crea los objetos
itemTracker = std::make_shared<ItemTracker>(); ItemTracker::init();
scoreboard = std::make_shared<Scoreboard>(&board); scoreboard = std::make_shared<Scoreboard>(&board);
room = std::make_shared<Room>(resource->getRoom(currentRoom), itemTracker, &board.items, false); room = std::make_shared<Room>(resource->getRoom(currentRoom), &board.items, false);
text = resource->getText("smb2"); text = resource->getText("smb2");
// Inicializa el resto de variables // Inicializa el resto de variables
@@ -62,6 +62,12 @@ Demo::Demo()
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
} }
// Destructor
Demo::~Demo()
{
ItemTracker::destroy();
}
// Comprueba los eventos de la cola // Comprueba los eventos de la cola
void Demo::checkEvents() void Demo::checkEvents()
{ {
@@ -183,7 +189,7 @@ bool Demo::changeRoom(std::string file)
if (asset->get(file) != "") if (asset->get(file) != "")
{ {
// Crea un objeto habitación a partir del fichero // Crea un objeto habitación a partir del fichero
room = std::make_shared<Room>(resource->getRoom(file), itemTracker, &board.items, false); room = std::make_shared<Room>(resource->getRoom(file), &board.items, false);
// Pone el color del marcador en función del color del borde de la habitación // Pone el color del marcador en función del color del borde de la habitación
setScoreBoardColor(); setScoreBoardColor();

View File

@@ -28,7 +28,6 @@ private:
std::shared_ptr<Room> room; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr<Room> room; // Objeto encargado de gestionar cada habitación del juego
std::shared_ptr<Text> text; // Objeto para los textos del juego std::shared_ptr<Text> text; // Objeto para los textos del juego
std::shared_ptr<Scoreboard> scoreboard; // Objeto encargado de gestionar el marcador std::shared_ptr<Scoreboard> scoreboard; // Objeto encargado de gestionar el marcador
std::shared_ptr<ItemTracker> itemTracker; // Lleva el control de los objetos recogidos
// Variables // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
@@ -75,7 +74,7 @@ public:
Demo(); Demo();
// Destructor // Destructor
~Demo() = default; ~Demo();
// Bucle para el juego // Bucle para el juego
void run(); void run();

View File

@@ -1,59 +1,57 @@
#include "item.h" #include "item.h"
#include "resource.h"
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
// Constructor // Constructor
Item::Item(item_t item) Item::Item(ItemData item)
{ {
constexpr int ITEMSIZE = 8; constexpr int ITEMSIZE = 8;
// Crea objetos; // Crea objetos;
sprite = std::make_shared<Sprite>(item.texture, item.x, item.y, ITEMSIZE, ITEMSIZE); sprite_ = std::make_shared<Sprite>(Resource::get()->getTexture(item.tile_set_file), item.x, item.y, ITEMSIZE, ITEMSIZE);
// Inicia variables // Inicia variables
sprite->setClip((item.tile % 10) * ITEMSIZE, (item.tile / 10) * ITEMSIZE, ITEMSIZE, ITEMSIZE); sprite_->setClip((item.tile % 10) * ITEMSIZE, (item.tile / 10) * ITEMSIZE, ITEMSIZE, ITEMSIZE);
collider = sprite->getRect(); collider_ = sprite_->getRect();
colorChangeSpeed = 4; change_color_speed = 4;
counter = item.counter * colorChangeSpeed; counter_ = item.counter * change_color_speed;
// Inicializa los colores // Inicializa los colores
Color c = item.color1; color_.push_back(item.color1);
color.push_back(c); color_.push_back(item.color1);
color.push_back(c);
c = item.color2; color_.push_back(item.color2);
color.push_back(c); color_.push_back(item.color2);
color.push_back(c);
} }
// Pinta el objeto en pantalla // Pinta el objeto en pantalla
void Item::render() void Item::render()
{ {
const int index = (counter / colorChangeSpeed) % color.size(); const int index = (counter_ / change_color_speed) % color_.size();
sprite->getTexture()->setColor(color[index].r, color[index].g, color[index].b); sprite_->getTexture()->setColor(color_[index].r, color_[index].g, color_[index].b);
sprite->render(); sprite_->render();
sprite->getTexture()->setColor(255, 255, 255); sprite_->getTexture()->setColor(255, 255, 255);
} }
// Obtiene su ubicación // Obtiene su ubicación
SDL_Point Item::getPos() SDL_Point Item::getPos()
{ {
const SDL_Point p = {sprite->getX(), sprite->getY()}; const SDL_Point p = {sprite_->getX(), sprite_->getY()};
return p; return p;
} }
// Asigna los colores del objeto // Asigna los colores del objeto
void Item::setColors(Color col1, Color col2) void Item::setColors(Color col1, Color col2)
{ {
// Reinicializa el vector de colores // Reinicializa el vector de colores
color.clear(); color_.clear();
// Añade el primer color // Añade el primer color
color.push_back(col1); color_.push_back(col1);
color.push_back(col1); color_.push_back(col1);
// Añade el segundo color // Añade el segundo color
color.push_back(col2); color_.push_back(col2);
color.push_back(col2); color_.push_back(col2);
} }

View File

@@ -1,45 +1,43 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <memory> // for shared_ptr, __shared_ptr_access #include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Color #include "utils.h" // for Color
struct item_t struct ItemData
{ {
SDL_Renderer *renderer; // El renderizador de la ventana std::string tile_set_file; // Ruta al fichero con los gráficos del item
std::shared_ptr<Texture> texture; // Textura con los gráficos del item int x; // Posición del item en pantalla
std::string tileSetFile; // Ruta al fichero con los gráficos del item int y; // Posición del item en pantalla
int x; // Posición del item en pantalla int tile; // Número de tile dentro de la textura
int y; // Posición del item en pantalla int counter; // Contador inicial. Es el que lo hace cambiar de color
int tile; // Número de tile dentro de la textura Color color1; // Uno de los dos colores que se utiliza para el item
int counter; // Contador inicial. Es el que lo hace cambiar de color Color color2; // Uno de los dos colores que se utiliza para el item
Color color1; // Uno de los dos colores que se utiliza para el item
Color color2; // Uno de los dos colores que se utiliza para el item
// Constructor por defecto // Constructor
item_t() : renderer(nullptr), texture(nullptr), x(0), y(0), tile(0), counter(0), color1(), color2() {} ItemData() : x(0), y(0), tile(0), counter(0), color1(), color2() {}
}; };
class Item class Item
{ {
private: private:
// Objetos y punteros // Objetos y punteros
std::shared_ptr<Sprite> sprite; // Sprite del objeto std::shared_ptr<Sprite> sprite_; // Sprite del objeto
// Variables // Variables
std::vector<Color> color; // Vector con los colores del objeto std::vector<Color> color_; // Vector con los colores del objeto
int counter; // Contador interno int counter_; // Contador interno
SDL_Rect collider; // Rectangulo de colisión SDL_Rect collider_; // Rectangulo de colisión
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color int change_color_speed; // Cuanto mas alto, mas tarda en cambiar de color
public: public:
// Constructor // Constructor
Item(item_t item); Item(ItemData item);
// Destructor // Destructor
~Item() = default; ~Item() = default;
@@ -48,18 +46,17 @@ public:
void render(); void render();
// Actualiza las variables del objeto // Actualiza las variables del objeto
void update() { counter++; } void update() { counter_++; }
// Obtiene el rectangulo de colision del objeto // Obtiene el rectangulo de colision del objeto
SDL_Rect &getCollider() { return collider; } SDL_Rect &getCollider() { return collider_; }
// Obtiene su ubicación // Obtiene su ubicación
SDL_Point getPos(); SDL_Point getPos();
// Recarga la textura // Recarga la textura
void reLoadTexture() { sprite->getTexture()->reLoad(); } void reLoadTexture() { sprite_->getTexture()->reLoad(); }
// Asigna los colores del objeto // Asigna los colores del objeto
void setColors(Color col1, Color col2); void setColors(Color col1, Color col2);
}; };

View File

@@ -4,13 +4,13 @@
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector
struct ItemData struct ItemTrackerData
{ {
std::string name; // Nombre de la habitación donde se encuentra el objeto std::string name; // Nombre de la habitación donde se encuentra el objeto
std::vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación std::vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación
// Constructor // Constructor
ItemData(const std::string& name, const SDL_Point& position) ItemTrackerData(const std::string& name, const SDL_Point& position)
: name(name) : name(name)
{ {
pos.push_back(position); pos.push_back(position);
@@ -24,7 +24,7 @@ private:
static ItemTracker *item_tracker_; static ItemTracker *item_tracker_;
// Variables // Variables
std::vector<ItemData> list; // Lista con todos los objetos recogidos std::vector<ItemTrackerData> list; // Lista con todos los objetos recogidos
// Busca una entrada en la lista por nombre // Busca una entrada en la lista por nombre
int findByName(std::string name); int findByName(std::string name);

View File

@@ -15,9 +15,11 @@
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "options.h" #include "options.h"
#include "utils.h" // Para stringToBool, stringToColor
#include "resource.h"
// Carga las variables y texturas desde un fichero de mapa de tiles // Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose) std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose)
{ {
std::vector<int> tileMapFile; std::vector<int> tileMapFile;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
@@ -69,7 +71,7 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
} }
// Carga las variables desde un fichero de mapa // Carga las variables desde un fichero de mapa
RoomData loadRoomFile(std::string file_path, bool verbose) RoomData loadRoomFile(const std::string &file_path, bool verbose)
{ {
RoomData room; RoomData room;
room.item_color1 = "yellow"; room.item_color1 = "yellow";
@@ -104,13 +106,13 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("="); int pos = line.find("=");
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length()))) std::string key = line.substr(0, pos);
{ std::string value = line.substr(pos + 1, line.length());
if (!setEnemy(&enemy, key, value))
if (verbose) if (verbose)
{ {
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
} }
}
} while (line != "[/enemy]"); } while (line != "[/enemy]");
// Añade el enemigo al vector de enemigos // Añade el enemigo al vector de enemigos
@@ -120,7 +122,7 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item // Si la linea contiene el texto [item] se realiza el proceso de carga de un item
else if (line == "[item]") else if (line == "[item]")
{ {
item_t item; ItemData item;
item.counter = 0; item.counter = 0;
item.color1 = stringToColor(Palette::ZXSPECTRUM, "yellow"); item.color1 = stringToColor(Palette::ZXSPECTRUM, "yellow");
item.color2 = stringToColor(Palette::ZXSPECTRUM, "magenta"); item.color2 = stringToColor(Palette::ZXSPECTRUM, "magenta");
@@ -133,7 +135,9 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("="); int pos = line.find("=");
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length()))) std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1, line.length());
if (!setItem(&item, key, value))
{ {
if (verbose) if (verbose)
{ {
@@ -153,7 +157,9 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("="); int pos = line.find("=");
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length()))) std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1, line.length());
if (!setRoom(&room, key, value))
{ {
if (verbose) if (verbose)
{ {
@@ -181,226 +187,210 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
return room; return room;
} }
// Asigna variables a partir de dos cadenas // Asigna variables a una estructura RoomData
bool setVars(RoomData *room, std::string var, std::string value) bool setRoom(RoomData *room, const std::string &key, const std::string &value)
{ {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
if (var == "tileMapFile") try
{ {
room->tile_map_file = value; if (key == "tileMapFile")
}
else if (var == "name")
{
room->name = value;
}
else if (var == "bgColor")
{
room->bg_color = value;
}
else if (var == "border")
{
room->border_color = value;
}
else if (var == "itemColor1")
{
room->item_color1 = value;
}
else if (var == "itemColor2")
{
room->item_color2 = value;
}
else if (var == "tileSetFile")
{
room->tile_set_file = value;
}
else if (var == "roomUp")
{
room->room_top = value;
}
else if (var == "roomDown")
{
room->room_bottom = value;
}
else if (var == "roomLeft")
{
room->room_left = value;
}
else if (var == "roomRight")
{
room->room_right = value;
}
else if (var == "autoSurface")
{
if (value == "right")
{ {
room->auto_surface_direction = 1; room->tile_map_file = value;
}
else if (key == "name")
{
room->name = value;
}
else if (key == "bgColor")
{
room->bg_color = value;
}
else if (key == "border")
{
room->border_color = value;
}
else if (key == "itemColor1")
{
room->item_color1 = value;
}
else if (key == "itemColor2")
{
room->item_color2 = value;
}
else if (key == "tileSetFile")
{
room->tile_set_file = value;
}
else if (key == "roomUp")
{
room->room_top = value;
}
else if (key == "roomDown")
{
room->room_bottom = value;
}
else if (key == "roomLeft")
{
room->room_left = value;
}
else if (key == "roomRight")
{
room->room_right = value;
}
else if (key == "autoSurface")
{
room->auto_surface_direction = (value == "right") ? 1 : -1;
}
else if (key == "" || key.substr(0, 1) == "#")
{
// No se realiza ninguna acción para estas claves
} }
else else
{ {
room->auto_surface_direction = -1; success = false;
} }
} }
catch (const std::exception &e)
else if (var == "" || var.substr(0, 1) == "#")
{
}
else
{ {
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false; success = false;
} }
return success; return success;
} }
// Asigna variables a una estructura enemy_t // Asigna variables a una estructura EnemyData
bool setEnemy(EnemyData *enemy, std::string var, std::string value) bool setEnemy(EnemyData *enemy, const std::string &key, const std::string &value)
{ {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
if (var == "tileSetFile") try
{ {
enemy->texture_path = value; if (key == "tileSetFile")
{
enemy->texture_path = value;
}
else if (key == "animation")
{
enemy->animation_path = value;
}
else if (key == "width")
{
enemy->w = std::stoi(value);
}
else if (key == "height")
{
enemy->h = std::stoi(value);
}
else if (key == "x")
{
enemy->x = std::stof(value) * BLOCK;
}
else if (key == "y")
{
enemy->y = std::stof(value) * BLOCK;
}
else if (key == "vx")
{
enemy->vx = std::stof(value);
}
else if (key == "vy")
{
enemy->vy = std::stof(value);
}
else if (key == "x1")
{
enemy->x1 = std::stoi(value) * BLOCK;
}
else if (key == "x2")
{
enemy->x2 = std::stoi(value) * BLOCK;
}
else if (key == "y1")
{
enemy->y1 = std::stoi(value) * BLOCK;
}
else if (key == "y2")
{
enemy->y2 = std::stoi(value) * BLOCK;
}
else if (key == "flip")
{
enemy->flip = stringToBool(value);
}
else if (key == "mirror")
{
enemy->mirror = stringToBool(value);
}
else if (key == "color")
{
enemy->color = value;
}
else if (key == "frame")
{
enemy->frame = std::stoi(value);
}
else if (key == "[/enemy]" || key == "tileSetFile" || key.substr(0, 1) == "#")
{
// No se realiza ninguna acción para estas claves
}
else
{
success = false;
}
} }
catch (const std::exception &e)
else if (var == "animation")
{
enemy->animation_path = value;
}
else if (var == "width")
{
enemy->w = std::stof(value);
}
else if (var == "height")
{
enemy->h = std::stof(value);
}
else if (var == "x")
{
enemy->x = std::stof(value) * BLOCK;
}
else if (var == "y")
{
enemy->y = std::stof(value) * BLOCK;
}
else if (var == "vx")
{
enemy->vx = std::stof(value);
}
else if (var == "vy")
{
enemy->vy = std::stof(value);
}
else if (var == "x1")
{
enemy->x1 = std::stoi(value) * BLOCK;
}
else if (var == "x2")
{
enemy->x2 = std::stoi(value) * BLOCK;
}
else if (var == "y1")
{
enemy->y1 = std::stoi(value) * BLOCK;
}
else if (var == "y2")
{
enemy->y2 = std::stoi(value) * BLOCK;
}
else if (var == "flip")
{
enemy->flip = stringToBool(value);
}
else if (var == "mirror")
{
enemy->mirror = stringToBool(value);
}
else if (var == "color")
{
enemy->color = value;
}
else if (var == "frame")
{
enemy->frame = std::stoi(value);
}
else if (var == "[/enemy]" || var == "tileSetFile" || var.substr(0, 1) == "#")
{
}
else
{ {
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false; success = false;
} }
return success; return success;
} }
// Asigna variables a una estructura item_t // Asigna variables a una estructura ItemData
bool setItem(item_t *item, std::string var, std::string value) bool setItem(ItemData *item, const std::string &key, const std::string &value)
{ {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
if (var == "tileSetFile") try
{ {
item->tileSetFile = value; if (key == "tileSetFile")
{
item->tile_set_file = value;
}
else if (key == "counter")
{
item->counter = std::stoi(value);
}
else if (key == "x")
{
item->x = std::stof(value) * BLOCK;
}
else if (key == "y")
{
item->y = std::stof(value) * BLOCK;
}
else if (key == "tile")
{
item->tile = std::stof(value);
}
else if (key == "[/item]")
{
// No se realiza ninguna acción para esta clave
}
else
{
success = false;
}
} }
catch (const std::exception &e)
else if (var == "counter")
{
item->counter = std::stoi(value);
}
else if (var == "x")
{
item->x = std::stof(value) * BLOCK;
}
else if (var == "y")
{
item->y = std::stof(value) * BLOCK;
}
else if (var == "tile")
{
item->tile = std::stof(value);
}
else if (var == "[/item]")
{
}
else
{ {
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false; success = false;
} }
@@ -408,7 +398,7 @@ bool setItem(item_t *item, std::string var, std::string value)
} }
// Constructor // Constructor
Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled) Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jail_is_open)
: screen_(Screen::get()), : screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()), renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()), asset_(Asset::get()),
@@ -428,17 +418,12 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
tile_set_file_ = room->tile_set_file; tile_set_file_ = room->tile_set_file;
tile_map_file_ = room->tile_map_file; tile_map_file_ = room->tile_map_file;
auto_surface_direction_ = room->auto_surface_direction; auto_surface_direction_ = room->auto_surface_direction;
textureA_ = room->textureA; tile_map_ = Resource::get()->getTileMap(room->tile_map_file);
textureB_ = room->textureB; texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
tile_map_ = room->tile_map; jail_is_open_ = jail_is_open;
texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? textureA_ : textureB_;
jail_is_open_ = jailEnabled;
// Inicializa variables // Inicializa variables
tile_size_ = 8; tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
tile_set_width_ = texture_->getWidth() / tile_size_;
map_width_ = 32;
map_height_ = 16;
paused_ = false; paused_ = false;
counter_ = 0; counter_ = 0;
@@ -455,7 +440,6 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
if (!ItemTracker::get()->hasBeenPicked(room->name, itemPos)) if (!ItemTracker::get()->hasBeenPicked(room->name, itemPos))
{ {
item.renderer = renderer_;
item.color1 = stringToColor(options.video.palette, item_color1_); item.color1 = stringToColor(options.video.palette, item_color1_);
item.color2 = stringToColor(options.video.palette, item_color2_); item.color2 = stringToColor(options.video.palette, item_color2_);
items_.emplace_back(std::make_shared<Item>(item)); items_.emplace_back(std::make_shared<Item>(item));
@@ -466,7 +450,7 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
item_sound_ = JA_LoadSound(asset_->get("item.wav").c_str()); item_sound_ = JA_LoadSound(asset_->get("item.wav").c_str());
// Abre la jail para poder entrar // Abre la jail para poder entrar
if (jailEnabled) if (jail_is_open)
{ {
openTheJail(); openTheJail();
} }
@@ -536,121 +520,117 @@ void Room::fillMapTexture()
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo // Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
SDL_Rect clip = {0, 0, tile_size_, tile_size_}; SDL_Rect clip = {0, 0, TILE_SIZE_, TILE_SIZE_};
for (int y = 0; y < map_height_; ++y) for (int y = 0; y < MAP_HEIGHT_; ++y)
for (int x = 0; x < map_width_; ++x) for (int x = 0; x < MAP_WIDTH_; ++x)
{ {
// Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n. // Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n.
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1 // Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices) // Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
const int index = (y * map_width_) + x; const int index = (y * MAP_WIDTH_) + x;
const bool a = (tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 19 * tile_set_width_); const bool a = (tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 19 * tile_set_width_);
const bool b = tile_map_[index] > -1; const bool b = tile_map_[index] > -1;
if (b && !a) if (b && !a)
{ {
clip.x = (tile_map_[index] % tile_set_width_) * tile_size_; clip.x = (tile_map_[index] % tile_set_width_) * TILE_SIZE_;
clip.y = (tile_map_[index] / tile_set_width_) * tile_size_; clip.y = (tile_map_[index] / tile_set_width_) * TILE_SIZE_;
texture_->render(x * tile_size_, y * tile_size_, &clip); texture_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
#ifdef DEBUG #ifdef DEBUG
// **** if (debug_->getEnabled())
if (debug->getEnabled())
{ {
if (clip.x != -tileSize) if (clip.x != -TILE_SIZE_)
{ {
clip.x = x * tileSize; clip.x = x * TILE_SIZE_;
clip.y = y * tileSize; clip.y = y * TILE_SIZE_;
SDL_SetRenderDrawColor(renderer, 64, 64, 64, 224); SDL_SetRenderDrawColor(renderer_, 64, 64, 64, 224);
SDL_RenderFillRect(renderer, &clip); SDL_RenderFillRect(renderer_, &clip);
} }
} }
// ****
#endif #endif
} }
} }
#ifdef DEBUG #ifdef DEBUG
// **** if (debug_->getEnabled())
if (debug->getEnabled())
{ {
// BottomSurfaces // BottomSurfaces
if (true) if (true)
{ {
for (auto l : bottomSurfaces) for (auto l : bottom_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 0xFF); SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
} }
} }
// TopSurfaces // TopSurfaces
if (true) if (true)
{ {
for (auto l : topSurfaces) for (auto l : top_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 0xFF); SDL_SetRenderDrawColor(renderer_, 0, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
} }
} }
// LeftSurfaces // LeftSurfaces
if (true) if (true)
{ {
for (auto l : leftSurfaces) for (auto l : left_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 128, 128, 255, 0xFF); SDL_SetRenderDrawColor(renderer_, 128, 128, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2); SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2);
} }
} }
// RightSurfaces // RightSurfaces
if (true) if (true)
{ {
for (auto l : rightSurfaces) for (auto l : right_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 0xFF); SDL_SetRenderDrawColor(renderer_, 255, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2); SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2);
} }
} }
// LeftSlopes // LeftSlopes
if (true) if (true)
{ {
for (auto l : leftSlopes) for (auto l : left_slopes_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 0xFF); SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2); SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2);
} }
} }
// RightSlopes // RightSlopes
if (true) if (true)
{ {
for (auto l : rightSlopes) for (auto l : right_slopes_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0xFF); SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2); SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2);
} }
} }
// AutoSurfaces // AutoSurfaces
if (true) if (true)
{ {
for (auto l : autoSurfaces) for (auto l : auto_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
} }
} }
} }
// ****
#endif #endif
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(renderer_, nullptr);
@@ -665,7 +645,7 @@ void Room::renderMap()
// Dibuja los tiles animados // Dibuja los tiles animados
#ifdef DEBUG #ifdef DEBUG
if (!debug->getEnabled()) if (!debug_->getEnabled())
{ {
renderAnimatedTiles(); renderAnimatedTiles();
} }
@@ -747,7 +727,7 @@ std::string Room::getRoom(int border)
// Devuelve el tipo de tile que hay en ese pixel // Devuelve el tipo de tile que hay en ese pixel
tile_e Room::getTile(SDL_Point point) tile_e Room::getTile(SDL_Point point)
{ {
const int pos = ((point.y / tile_size_) * map_width_) + (point.x / tile_size_); const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_);
return getTile(pos); return getTile(pos);
} }
@@ -867,7 +847,7 @@ void Room::reLoadPalette()
screen_->setBorderColor(stringToColor(options.video.palette, border_color_)); screen_->setBorderColor(stringToColor(options.video.palette, border_color_));
// Cambia la textura // Cambia la textura
texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? textureA_ : textureB_; //texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
// Pone la nueva textura a los tiles animados // Pone la nueva textura a los tiles animados
for (auto tile : animated_tiles_) for (auto tile : animated_tiles_)
@@ -882,22 +862,22 @@ void Room::reLoadPalette()
// Obten el tamaño del tile // Obten el tamaño del tile
int Room::getTileSize() int Room::getTileSize()
{ {
return tile_size_; return TILE_SIZE_;
} }
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
int Room::getSlopeHeight(SDL_Point p, tile_e slope) int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{ {
// Calcula la base del tile // Calcula la base del tile
int base = ((p.y / tile_size_) * tile_size_) + tile_size_; int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
#ifdef DEBUG #ifdef DEBUG
debug->add("BASE = " + std::to_string(base)); debug_->add("BASE = " + std::to_string(base));
#endif #endif
// Calcula cuanto se ha entrado en el tile horizontalmente // Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (p.x % tile_size_); // Esto da un valor entre 0 y 7 const int pos = (p.x % TILE_SIZE_); // Esto da un valor entre 0 y 7
#ifdef DEBUG #ifdef DEBUG
debug->add("POS = " + std::to_string(pos)); debug_->add("POS = " + std::to_string(pos));
#endif #endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa // Se resta a la base la cantidad de pixeles pos en funcion de la rampa
@@ -905,14 +885,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{ {
base -= pos + 1; base -= pos + 1;
#ifdef DEBUG #ifdef DEBUG
debug->add("BASE_R = " + std::to_string(base)); debug_->add("BASE_R = " + std::to_string(base));
#endif #endif
} }
else else
{ {
base -= (tile_size_ - pos); base -= (TILE_SIZE_ - pos);
#ifdef DEBUG #ifdef DEBUG
debug->add("BASE_L = " + std::to_string(base)); debug_->add("BASE_L = " + std::to_string(base));
#endif #endif
} }
@@ -926,14 +906,14 @@ void Room::setBottomSurfaces()
// Busca todos los tiles de tipo muro que no tengan debajo otro muro // Busca todos los tiles de tipo muro que no tengan debajo otro muro
// Hay que recorrer la habitación por filas (excepto los de la última fila) // Hay que recorrer la habitación por filas (excepto los de la última fila)
for (int i = 0; i < (int)tile_map_.size() - map_width_; ++i) for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH_; ++i)
{ {
if (getTile(i) == t_wall && getTile(i + map_width_) != t_wall) if (getTile(i) == t_wall && getTile(i + MAP_WIDTH_) != t_wall)
{ {
tile.push_back(i); tile.push_back(i);
// Si llega al final de la fila, introduce un separador // Si llega al final de la fila, introduce un separador
if (i % map_width_ == map_width_ - 1) if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{ {
tile.push_back(-1); tile.push_back(-1);
} }
@@ -951,8 +931,8 @@ void Room::setBottomSurfaces()
do do
{ {
h_line_t line; h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1; line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
lastOne = i; lastOne = i;
i++; i++;
@@ -969,7 +949,7 @@ void Room::setBottomSurfaces()
} }
} }
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1; line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
bottom_surfaces_.push_back(line); bottom_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1) if (i <= (int)tile.size() - 1)
{ {
@@ -989,14 +969,14 @@ void Room::setTopSurfaces()
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro // Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
// Hay que recorrer la habitación por filas (excepto los de la primera fila) // Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = map_width_; i < (int)tile_map_.size(); ++i) for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i)
{ {
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - map_width_) != t_wall) if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - MAP_WIDTH_) != t_wall)
{ {
tile.push_back(i); tile.push_back(i);
// Si llega al final de la fila, introduce un separador // Si llega al final de la fila, introduce un separador
if (i % map_width_ == map_width_ - 1) if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{ {
tile.push_back(-1); tile.push_back(-1);
} }
@@ -1014,8 +994,8 @@ void Room::setTopSurfaces()
do do
{ {
h_line_t line; h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / map_width_) * tile_size_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i; lastOne = i;
i++; i++;
@@ -1032,7 +1012,7 @@ void Room::setTopSurfaces()
} }
} }
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1; line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
top_surfaces_.push_back(line); top_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1) if (i <= (int)tile.size() - 1)
{ {
@@ -1052,11 +1032,11 @@ void Room::setLeftSurfaces()
// Busca todos los tiles de tipo muro que no tienen a su izquierda un tile de tipo muro // Busca todos los tiles de tipo muro que no tienen a su izquierda un tile de tipo muro
// Hay que recorrer la habitación por columnas (excepto los de la primera columna) // Hay que recorrer la habitación por columnas (excepto los de la primera columna)
for (int i = 1; i < map_width_; ++i) for (int i = 1; i < MAP_WIDTH_; ++i)
{ {
for (int j = 0; j < map_height_; ++j) for (int j = 0; j < MAP_HEIGHT_; ++j)
{ {
const int pos = (j * map_width_ + i); const int pos = (j * MAP_WIDTH_ + i);
if (getTile(pos) == t_wall && getTile(pos - 1) != t_wall) if (getTile(pos) == t_wall && getTile(pos - 1) != t_wall)
{ {
tile.push_back(pos); tile.push_back(pos);
@@ -1076,9 +1056,9 @@ void Room::setLeftSurfaces()
do do
{ {
v_line_t line; v_line_t line;
line.x = (tile[i] % map_width_) * tile_size_; line.x = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y1 = ((tile[i] / map_width_) * tile_size_); line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
while (tile[i] + map_width_ == tile[i + 1]) while (tile[i] + MAP_WIDTH_ == tile[i + 1])
{ {
if (i == (int)tile.size() - 1) if (i == (int)tile.size() - 1)
{ {
@@ -1086,7 +1066,7 @@ void Room::setLeftSurfaces()
} }
i++; i++;
} }
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1; line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
left_surfaces_.push_back(line); left_surfaces_.push_back(line);
i++; i++;
} while (i < (int)tile.size() - 1); } while (i < (int)tile.size() - 1);
@@ -1100,11 +1080,11 @@ void Room::setRightSurfaces()
// Busca todos los tiles de tipo muro que no tienen a su derecha un tile de tipo muro // Busca todos los tiles de tipo muro que no tienen a su derecha un tile de tipo muro
// Hay que recorrer la habitación por columnas (excepto los de la última columna) // Hay que recorrer la habitación por columnas (excepto los de la última columna)
for (int i = 0; i < map_width_ - 1; ++i) for (int i = 0; i < MAP_WIDTH_ - 1; ++i)
{ {
for (int j = 0; j < map_height_; ++j) for (int j = 0; j < MAP_HEIGHT_; ++j)
{ {
const int pos = (j * map_width_ + i); const int pos = (j * MAP_WIDTH_ + i);
if (getTile(pos) == t_wall && getTile(pos + 1) != t_wall) if (getTile(pos) == t_wall && getTile(pos + 1) != t_wall)
{ {
tile.push_back(pos); tile.push_back(pos);
@@ -1124,9 +1104,9 @@ void Room::setRightSurfaces()
do do
{ {
v_line_t line; v_line_t line;
line.x = ((tile[i] % map_width_) * tile_size_) + tile_size_ - 1; line.x = ((tile[i] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.y1 = ((tile[i] / map_width_) * tile_size_); line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
while (tile[i] + map_width_ == tile[i + 1]) while (tile[i] + MAP_WIDTH_ == tile[i + 1])
{ {
if (i == (int)tile.size() - 1) if (i == (int)tile.size() - 1)
{ {
@@ -1134,7 +1114,7 @@ void Room::setRightSurfaces()
} }
i++; i++;
} }
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1; line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
right_surfaces_.push_back(line); right_surfaces_.push_back(line);
i++; i++;
} while (i < (int)tile.size() - 1); } while (i < (int)tile.size() - 1);
@@ -1161,9 +1141,9 @@ void Room::setLeftSlopes()
while (found.size() > 0) while (found.size() > 0)
{ {
d_line_t line; d_line_t line;
line.x1 = (found[0] % map_width_) * tile_size_; line.x1 = (found[0] % MAP_WIDTH_) * TILE_SIZE_;
line.y1 = (found[0] / map_width_) * tile_size_; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
int lookingFor = found[0] + map_width_ + 1; int lookingFor = found[0] + MAP_WIDTH_ + 1;
int lastOneFound = found[0]; int lastOneFound = found[0];
found.erase(found.begin()); found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i) for (int i = 0; i < (int)found.size(); ++i)
@@ -1171,13 +1151,13 @@ void Room::setLeftSlopes()
if (found[i] == lookingFor) if (found[i] == lookingFor)
{ {
lastOneFound = lookingFor; lastOneFound = lookingFor;
lookingFor += map_width_ + 1; lookingFor += MAP_WIDTH_ + 1;
found.erase(found.begin() + i); found.erase(found.begin() + i);
i--; i--;
} }
} }
line.x2 = ((lastOneFound % map_width_) * tile_size_) + tile_size_ - 1; line.x2 = ((lastOneFound % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1; line.y2 = ((lastOneFound / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
left_slopes_.push_back(line); left_slopes_.push_back(line);
} }
} }
@@ -1202,9 +1182,9 @@ void Room::setRightSlopes()
while (found.size() > 0) while (found.size() > 0)
{ {
d_line_t line; d_line_t line;
line.x1 = ((found[0] % map_width_) * tile_size_) + tile_size_ - 1; line.x1 = ((found[0] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.y1 = (found[0] / map_width_) * tile_size_; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
int lookingFor = found[0] + map_width_ - 1; int lookingFor = found[0] + MAP_WIDTH_ - 1;
int lastOneFound = found[0]; int lastOneFound = found[0];
found.erase(found.begin()); found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i) for (int i = 0; i < (int)found.size(); ++i)
@@ -1212,13 +1192,13 @@ void Room::setRightSlopes()
if (found[i] == lookingFor) if (found[i] == lookingFor)
{ {
lastOneFound = lookingFor; lastOneFound = lookingFor;
lookingFor += map_width_ - 1; lookingFor += MAP_WIDTH_ - 1;
found.erase(found.begin() + i); found.erase(found.begin() + i);
i--; i--;
} }
} }
line.x2 = (lastOneFound % map_width_) * tile_size_; line.x2 = (lastOneFound % MAP_WIDTH_) * TILE_SIZE_;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1; line.y2 = ((lastOneFound / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
right_slopes_.push_back(line); right_slopes_.push_back(line);
} }
} }
@@ -1230,14 +1210,14 @@ void Room::setAutoSurfaces()
// Busca todos los tiles de tipo animado // Busca todos los tiles de tipo animado
// Hay que recorrer la habitación por filas (excepto los de la primera fila) // Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = map_width_; i < (int)tile_map_.size(); ++i) for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i)
{ {
if (getTile(i) == t_animated) if (getTile(i) == t_animated)
{ {
tile.push_back(i); tile.push_back(i);
// Si llega al final de la fila, introduce un separador // Si llega al final de la fila, introduce un separador
if (i % map_width_ == map_width_ - 1) if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{ {
tile.push_back(-1); tile.push_back(-1);
} }
@@ -1252,8 +1232,8 @@ void Room::setAutoSurfaces()
do do
{ {
h_line_t line; h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / map_width_) * tile_size_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i; lastOne = i;
i++; i++;
@@ -1270,7 +1250,7 @@ void Room::setAutoSurfaces()
} }
} }
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1; line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
auto_surfaces_.push_back(line); auto_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1) if (i <= (int)tile.size() - 1)
{ {
@@ -1292,12 +1272,12 @@ void Room::setAnimatedTiles()
if (getTile(i) == t_animated) if (getTile(i) == t_animated)
{ {
// La i es la ubicación // La i es la ubicación
const int x = (i % map_width_) * tile_size_; const int x = (i % MAP_WIDTH_) * TILE_SIZE_;
const int y = (i / map_width_) * tile_size_; const int y = (i / MAP_WIDTH_) * TILE_SIZE_;
// TileMap[i] es el tile a poner // TileMap[i] es el tile a poner
const int xc = (tile_map_[i] % tile_set_width_) * tile_size_; const int xc = (tile_map_[i] % tile_set_width_) * TILE_SIZE_;
const int yc = (tile_map_[i] / tile_set_width_) * tile_size_; const int yc = (tile_map_[i] / tile_set_width_) * TILE_SIZE_;
aTile_t at; aTile_t at;
at.sprite = std::make_shared<Sprite>(texture_, x, y, 8, 8); at.sprite = std::make_shared<Sprite>(texture_, x, y, 8, 8);
@@ -1315,11 +1295,11 @@ void Room::updateAnimatedTiles()
int offset = 0; int offset = 0;
if (auto_surface_direction_ == -1) if (auto_surface_direction_ == -1)
{ {
offset = ((counter_ / 3) % numFrames * tile_size_); offset = ((counter_ / 3) % numFrames * TILE_SIZE_);
} }
else else
{ {
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * tile_size_); offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * TILE_SIZE_);
} }
for (auto &a : animated_tiles_) for (auto &a : animated_tiles_)

View File

@@ -50,29 +50,32 @@ struct RoomData
std::vector<int> tile_map; // Indice de los tiles a dibujar en la habitación std::vector<int> tile_map; // Indice de los tiles a dibujar en la habitación
int auto_surface_direction; // Sentido en el que arrastran las superficies automáticas de la habitación int auto_surface_direction; // Sentido en el que arrastran las superficies automáticas de la habitación
std::vector<EnemyData> enemies; // Listado con los enemigos de la habitación std::vector<EnemyData> enemies; // Listado con los enemigos de la habitación
std::vector<item_t> items; // Listado con los items que hay en la habitación std::vector<ItemData> items; // Listado con los items que hay en la habitación
std::shared_ptr<Texture> textureA; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureB; // Textura con los graficos de la habitación
}; };
// Carga las variables desde un fichero de mapa // Carga las variables desde un fichero de mapa
RoomData loadRoomFile(std::string file, bool verbose = false); RoomData loadRoomFile(const std::string &file_path, bool verbose = false);
// Carga las variables y texturas desde un fichero de mapa de tiles // Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose = false); std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose = false);
// Asigna variables a partir de dos cadenas // Asigna variables a una estructura RoomData
bool setVars(RoomData *room, std::string var, std::string value); bool setRoom(RoomData *room, const std::string &key, const std::string &value);
// Asigna variables a una estructura enemy_t // Asigna variables a una estructura EnemyData
bool setEnemy(EnemyData *enemy, std::string var, std::string value); bool setEnemy(EnemyData *enemy, const std::string &key, const std::string &value);
// Asigna variables a una estructura item_t // Asigna variables a una estructura ItemData
bool setItem(item_t *item, std::string var, std::string value); bool setItem(ItemData *item, const std::string &key, const std::string &value);
class Room class Room
{ {
private: 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
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana
@@ -81,8 +84,6 @@ private:
std::vector<std::shared_ptr<Enemy>> enemies_; // Listado con los enemigos de la habitación std::vector<std::shared_ptr<Enemy>> enemies_; // Listado con los enemigos de la habitación
std::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación std::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación
std::shared_ptr<Texture> texture_; // Textura con los graficos de la habitación std::shared_ptr<Texture> texture_; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureA_; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureB_; // Textura con los graficos de la habitación
SDL_Texture *map_texture_; // Textura para dibujar el mapa de la habitación SDL_Texture *map_texture_; // Textura para dibujar el mapa de la habitación
int *items_picked_; // Puntero a la cantidad de items recogidos que lleva el juego int *items_picked_; // Puntero a la cantidad de items recogidos que lleva el juego
@@ -112,9 +113,6 @@ private:
bool paused_; // Indica si el mapa esta en modo pausa bool paused_; // Indica si el mapa esta en modo pausa
std::vector<aTile_t> animated_tiles_; // Vector con los indices de tiles animados std::vector<aTile_t> animated_tiles_; // Vector con los indices de tiles animados
std::vector<h_line_t> auto_surfaces_; // Lista con las superficies automaticas de la habitación std::vector<h_line_t> auto_surfaces_; // Lista con las superficies automaticas de la habitación
int tile_size_; // Ancho del tile en pixels
int map_width_; // Ancho del mapa en tiles
int map_height_; // Alto del mapa en tiles
int tile_set_width_; // Ancho del tileset en tiles int tile_set_width_; // Ancho del tileset en tiles
bool jail_is_open_; // Indica si hay acceso a la Jail bool jail_is_open_; // Indica si hay acceso a la Jail