barrallantse en la colisió en les habitacions dels costats

fix: surface no clipejava be la copia de surfaces a surfaces que eixien per la dreta amb el flip activat
This commit is contained in:
2026-04-08 19:04:45 +02:00
parent 2a63227ee2
commit 79f79166bd
5 changed files with 191 additions and 13 deletions

View File

@@ -294,32 +294,34 @@ void Surface::render(int x, int y, SDL_FRect* src_rect, SDL_FlipMode flip) { //
float w = (src_rect != nullptr) ? src_rect->w : surface_data_->width;
float h = (src_rect != nullptr) ? src_rect->h : surface_data_->height;
// Guardar dimensiones originales antes del clipping (necesarias para flip)
float orig_w = (src_rect != nullptr) ? src_rect->w : static_cast<float>(surface_data_->width);
float orig_h = (src_rect != nullptr) ? src_rect->h : static_cast<float>(surface_data_->height);
// Limitar la región para evitar accesos fuera de rango en origen
w = std::min(w, surface_data_->width - sx);
h = std::min(h, surface_data_->height - sy);
w = std::min(w, surface_data_dest->width - x);
h = std::min(h, surface_data_dest->height - y);
// Limitar la región para evitar accesos fuera de rango en destino
w = std::min(w, surface_data_dest->width - x);
h = std::min(h, surface_data_dest->height - y);
w = std::min(w, surface_data_dest->width - static_cast<float>(x));
h = std::min(h, surface_data_dest->height - static_cast<float>(y));
// Renderiza píxel por píxel aplicando el flip si es necesario
const Uint8* src_ptr = surface_data_->data.get();
Uint8* dst_ptr = surface_data_dest->data.get();
for (int iy = 0; iy < h; ++iy) {
for (int ix = 0; ix < w; ++ix) {
// Coordenadas de origen
int src_x = (flip == SDL_FLIP_HORIZONTAL) ? (sx + w - 1 - ix) : (sx + ix);
int src_y = (flip == SDL_FLIP_VERTICAL) ? (sy + h - 1 - iy) : (sy + iy);
// Coordenadas de origen (flip usa dimensiones originales, no clipped)
int src_x = (flip == SDL_FLIP_HORIZONTAL) ? static_cast<int>(sx + orig_w - 1 - ix) : static_cast<int>(sx + ix);
int src_y = (flip == SDL_FLIP_VERTICAL) ? static_cast<int>(sy + orig_h - 1 - iy) : static_cast<int>(sy + iy);
// Coordenadas de destino
int dest_x = x + ix;
int dest_y = y + iy;
// Verificar que las coordenadas de destino están dentro de los límites
if (dest_x >= 0 && dest_x < surface_data_dest->width && dest_y >= 0 && dest_y < surface_data_dest->height) {
// Copia el píxel si no es transparente
// Verificar que las coordenadas están dentro de los límites
if (dest_x >= 0 && dest_x < surface_data_dest->width && dest_y >= 0 && dest_y < surface_data_dest->height &&
src_x >= 0 && src_x < surface_data_->width && src_y >= 0 && src_y < surface_data_->height) {
Uint8 color = src_ptr[static_cast<size_t>(src_x + (src_y * surface_data_->width))];
if (color != static_cast<Uint8>(transparent_color_)) {
dst_ptr[static_cast<size_t>(dest_x + (dest_y * surface_data_dest->width))] = sub_palette_[color];