forked from jaildesigner-jailgames/jaildoctors_dilemma
Transició a surface: barallantme amb tots els Color que hi ha pel codi
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include "resource.h" // for Resource
|
||||
#include "scoreboard.h" // for ScoreboardData
|
||||
#include "screen.h" // for Screen
|
||||
#include "s_sprite.h" // for Sprite
|
||||
#include "s_sprite.h" // for SSprite
|
||||
#include "surface.h" // for Texture
|
||||
#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe...
|
||||
|
||||
@@ -77,7 +77,7 @@ RoomData loadRoomFile(const std::string &file_path, bool verbose)
|
||||
RoomData room;
|
||||
room.item_color1 = "yellow";
|
||||
room.item_color2 = "magenta";
|
||||
room.auto_surface_direction = 1;
|
||||
room.conveyor_belt_direction = 1;
|
||||
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = fileName.substr(0, fileName.find_last_of("."));
|
||||
@@ -125,8 +125,8 @@ RoomData loadRoomFile(const std::string &file_path, bool verbose)
|
||||
{
|
||||
ItemData item;
|
||||
item.counter = 0;
|
||||
item.color1 = stringToColor(Palette::ZXSPECTRUM, "yellow");
|
||||
item.color2 = stringToColor(Palette::ZXSPECTRUM, "magenta");
|
||||
item.color1 = stringToColor("yellow");
|
||||
item.color2 = stringToColor("magenta");
|
||||
|
||||
do
|
||||
{
|
||||
@@ -226,23 +226,23 @@ bool setRoom(RoomData *room, const std::string &key, const std::string &value)
|
||||
}
|
||||
else if (key == "roomUp")
|
||||
{
|
||||
room->room_top = value;
|
||||
room->upper_room = value;
|
||||
}
|
||||
else if (key == "roomDown")
|
||||
{
|
||||
room->room_bottom = value;
|
||||
room->lower_room = value;
|
||||
}
|
||||
else if (key == "roomLeft")
|
||||
{
|
||||
room->room_left = value;
|
||||
room->left_room = value;
|
||||
}
|
||||
else if (key == "roomRight")
|
||||
{
|
||||
room->room_right = value;
|
||||
room->right_room = value;
|
||||
}
|
||||
else if (key == "autoSurface")
|
||||
{
|
||||
room->auto_surface_direction = (value == "right") ? 1 : -1;
|
||||
room->conveyor_belt_direction = (value == "right") ? 1 : -1;
|
||||
}
|
||||
else if (key == "" || key.substr(0, 1) == "#")
|
||||
{
|
||||
@@ -415,17 +415,17 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
|
||||
setAnimatedTiles();
|
||||
|
||||
// Crea la textura para el mapa de tiles de la habitación
|
||||
map_texture_ = createTexture(Screen::get()->getRenderer(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
map_surface_ = createTexture(Screen::get()->getRenderer(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
|
||||
// Pinta el mapa de la habitación en la textura
|
||||
fillMapTexture();
|
||||
|
||||
// Establece el color del borde
|
||||
Screen::get()->setBorderColor(stringToColor(options.video.palette, border_color_));
|
||||
Screen::get()->setBorderColor(stringToColor(border_color_));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Room::~Room() { SDL_DestroyTexture(map_texture_); }
|
||||
Room::~Room() { SDL_DestroyTexture(map_surface_); }
|
||||
|
||||
void Room::initializeRoom(const RoomData &room)
|
||||
{
|
||||
@@ -436,16 +436,16 @@ void Room::initializeRoom(const RoomData &room)
|
||||
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;
|
||||
room_top_ = room.room_top;
|
||||
room_bottom_ = room.room_bottom;
|
||||
room_left_ = room.room_left;
|
||||
room_right_ = room.room_right;
|
||||
upper_room_ = room.upper_room;
|
||||
lower_room_ = room.lower_room;
|
||||
left_room_ = room.left_room;
|
||||
right_room_ = room.right_room;
|
||||
tile_set_file_ = room.tile_set_file;
|
||||
tile_map_file_ = room.tile_map_file;
|
||||
auto_surface_direction_ = room.auto_surface_direction;
|
||||
conveyor_belt_direction_ = room.conveyor_belt_direction;
|
||||
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
||||
texture_ = Resource::get()->getSurface(room.tile_set_file);
|
||||
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
|
||||
surface_ = Resource::get()->getSurface(room.tile_set_file);
|
||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE_;
|
||||
is_paused_ = false;
|
||||
counter_ = 0;
|
||||
|
||||
@@ -464,8 +464,8 @@ void Room::initializeRoom(const RoomData &room)
|
||||
{
|
||||
// Crear una copia local de los datos del item
|
||||
ItemData itemCopy = item;
|
||||
itemCopy.color1 = stringToColor(options.video.palette, item_color1_);
|
||||
itemCopy.color2 = stringToColor(options.video.palette, item_color2_);
|
||||
itemCopy.color1 = stringToColor(item_color1_);
|
||||
itemCopy.color2 = stringToColor(item_color2_);
|
||||
|
||||
// Crear el objeto Item usando la copia modificada
|
||||
items_.emplace_back(std::make_shared<Item>(itemCopy));
|
||||
@@ -476,8 +476,8 @@ void Room::initializeRoom(const RoomData &room)
|
||||
// Crea la textura con el mapeado de la habitación
|
||||
void Room::fillMapTexture()
|
||||
{
|
||||
const Color color = stringToColor(options.video.palette, bg_color_);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), map_texture_);
|
||||
const Uint8 color = stringToColor(bg_color_);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), map_surface_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
|
||||
@@ -498,7 +498,7 @@ void Room::fillMapTexture()
|
||||
{
|
||||
clip.x = (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);
|
||||
surface_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (Debug::get()->getEnabled())
|
||||
@@ -521,7 +521,7 @@ void Room::fillMapTexture()
|
||||
// BottomSurfaces
|
||||
if (true)
|
||||
{
|
||||
for (auto l : bottom_surfaces_)
|
||||
for (auto l : bottom_floors_)
|
||||
{
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 0, 0xFF);
|
||||
@@ -532,7 +532,7 @@ void Room::fillMapTexture()
|
||||
// TopSurfaces
|
||||
if (true)
|
||||
{
|
||||
for (auto l : top_surfaces_)
|
||||
for (auto l : top_floors_)
|
||||
{
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 0, 0xFF);
|
||||
@@ -543,7 +543,7 @@ void Room::fillMapTexture()
|
||||
// LeftSurfaces
|
||||
if (true)
|
||||
{
|
||||
for (auto l : left_surfaces_)
|
||||
for (auto l : left_walls_)
|
||||
{
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 128, 128, 255, 0xFF);
|
||||
@@ -554,7 +554,7 @@ void Room::fillMapTexture()
|
||||
// RightSurfaces
|
||||
if (true)
|
||||
{
|
||||
for (auto l : right_surfaces_)
|
||||
for (auto l : right_walls_)
|
||||
{
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 0, 0xFF);
|
||||
@@ -587,7 +587,7 @@ void Room::fillMapTexture()
|
||||
// AutoSurfaces
|
||||
if (true)
|
||||
{
|
||||
for (auto l : auto_surfaces_)
|
||||
for (auto l : conveyor_belt_floors_)
|
||||
{
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
|
||||
@@ -604,7 +604,7 @@ void Room::renderMap()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), map_texture_, nullptr, &dest);
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), map_surface_, nullptr, &dest);
|
||||
|
||||
// Dibuja los tiles animados
|
||||
#ifdef DEBUG
|
||||
@@ -669,19 +669,19 @@ std::string Room::getRoom(int border)
|
||||
switch (border)
|
||||
{
|
||||
case BORDER_TOP:
|
||||
return room_top_;
|
||||
return upper_room_;
|
||||
break;
|
||||
|
||||
case BORDER_BOTTOM:
|
||||
return room_bottom_;
|
||||
return lower_room_;
|
||||
break;
|
||||
|
||||
case BORDER_RIGHT:
|
||||
return room_right_;
|
||||
return right_room_;
|
||||
break;
|
||||
|
||||
case BORDER_LEFT:
|
||||
return room_left_;
|
||||
return left_room_;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -861,7 +861,7 @@ void Room::setBottomSurfaces()
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
bottom_surfaces_.push_back(line);
|
||||
bottom_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile[i] == -1)
|
||||
@@ -923,7 +923,7 @@ void Room::setTopSurfaces()
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
top_surfaces_.push_back(line);
|
||||
top_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile[i] == -1)
|
||||
@@ -977,7 +977,7 @@ void Room::setLeftSurfaces()
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
left_surfaces_.push_back(line);
|
||||
left_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
}
|
||||
@@ -1025,7 +1025,7 @@ void Room::setRightSurfaces()
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
right_surfaces_.push_back(line);
|
||||
right_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
}
|
||||
@@ -1160,7 +1160,7 @@ void Room::setAutoSurfaces()
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
auto_surfaces_.push_back(line);
|
||||
conveyor_belt_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile[i] == -1)
|
||||
@@ -1189,7 +1189,7 @@ void Room::setAnimatedTiles()
|
||||
const int yc = (tile_map_[i] / tile_set_width_) * TILE_SIZE_;
|
||||
|
||||
AnimatedTile at;
|
||||
at.sprite = std::make_shared<Sprite>(texture_, x, y, 8, 8);
|
||||
at.sprite = std::make_shared<SSprite>(surface_, x, y, 8, 8);
|
||||
at.sprite->setClip(xc, yc, 8, 8);
|
||||
at.x_orig = xc;
|
||||
animated_tiles_.push_back(at);
|
||||
@@ -1202,7 +1202,7 @@ void Room::updateAnimatedTiles()
|
||||
{
|
||||
const int numFrames = 4;
|
||||
int offset = 0;
|
||||
if (auto_surface_direction_ == -1)
|
||||
if (conveyor_belt_direction_ == -1)
|
||||
{
|
||||
offset = ((counter_ / 3) % numFrames * TILE_SIZE_);
|
||||
}
|
||||
@@ -1231,7 +1231,7 @@ void Room::renderAnimatedTiles()
|
||||
// Comprueba las colisiones
|
||||
int Room::checkRightSurfaces(SDL_Rect *rect)
|
||||
{
|
||||
for (const auto &s : right_surfaces_)
|
||||
for (const auto &s : right_walls_)
|
||||
{
|
||||
if (checkCollision(s, *rect))
|
||||
{
|
||||
@@ -1245,7 +1245,7 @@ int Room::checkRightSurfaces(SDL_Rect *rect)
|
||||
// Comprueba las colisiones
|
||||
int Room::checkLeftSurfaces(SDL_Rect *rect)
|
||||
{
|
||||
for (const auto &s : left_surfaces_)
|
||||
for (const auto &s : left_walls_)
|
||||
{
|
||||
if (checkCollision(s, *rect))
|
||||
{
|
||||
@@ -1259,7 +1259,7 @@ int Room::checkLeftSurfaces(SDL_Rect *rect)
|
||||
// Comprueba las colisiones
|
||||
int Room::checkTopSurfaces(SDL_Rect *rect)
|
||||
{
|
||||
for (const auto &s : top_surfaces_)
|
||||
for (const auto &s : top_floors_)
|
||||
{
|
||||
if (checkCollision(s, *rect))
|
||||
{
|
||||
@@ -1273,7 +1273,7 @@ int Room::checkTopSurfaces(SDL_Rect *rect)
|
||||
// Comprueba las colisiones
|
||||
int Room::checkBottomSurfaces(SDL_Rect *rect)
|
||||
{
|
||||
for (const auto &s : bottom_surfaces_)
|
||||
for (const auto &s : bottom_floors_)
|
||||
{
|
||||
if (checkCollision(s, *rect))
|
||||
{
|
||||
@@ -1287,7 +1287,7 @@ int Room::checkBottomSurfaces(SDL_Rect *rect)
|
||||
// Comprueba las colisiones
|
||||
int Room::checkAutoSurfaces(SDL_Rect *rect)
|
||||
{
|
||||
for (const auto &s : auto_surfaces_)
|
||||
for (const auto &s : conveyor_belt_floors_)
|
||||
{
|
||||
if (checkCollision(s, *rect))
|
||||
{
|
||||
@@ -1301,7 +1301,7 @@ int Room::checkAutoSurfaces(SDL_Rect *rect)
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkTopSurfaces(SDL_Point *p)
|
||||
{
|
||||
for (const auto &s : top_surfaces_)
|
||||
for (const auto &s : top_floors_)
|
||||
{
|
||||
if (checkCollision(s, *p))
|
||||
{
|
||||
@@ -1315,7 +1315,7 @@ bool Room::checkTopSurfaces(SDL_Point *p)
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkAutoSurfaces(SDL_Point *p)
|
||||
{
|
||||
for (const auto &s : auto_surfaces_)
|
||||
for (const auto &s : conveyor_belt_floors_)
|
||||
{
|
||||
if (checkCollision(s, *p))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user