- [FIX] Ficar correctament el color transparent al volcar a pantalla

- [NEW] Rejilla de tiles
This commit is contained in:
2025-11-01 19:36:20 +01:00
parent ed1ee498f8
commit 68f5b2ff0f
4 changed files with 59 additions and 9 deletions

View File

@@ -564,6 +564,22 @@ namespace draw
}
}
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int zoom)
{
// Si no hi ha superficie d'oritge especificada, no fem res, o petarà el mame
if (source == nullptr) return;
for (int y=0; y<h; ++y) {
for (int x=0; x<w; ++x) {
const uint8_t pixel = pget(source, sx+x, sy+y);
for (int zx=0; zx<zoom; ++zx)
for (int zy=0; zy<zoom; ++zy) {
pset(destination, dx+zx+x*zoom, dy+zy+y*zoom, pixel);
}
}
}
}
// Pinta tota la superficie "source" en la superficie "destination", posició (x,y).
void draw(const int x, const int y)
{

View File

@@ -124,6 +124,16 @@ namespace draw
/// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos)
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const draw::flip flip = draw::flip::none);
/// @brief Pinta un troç de la superficie "source" en la superficie "destination", amb zoom.
/// @param dx coordenada x de la destinació
/// @param dy coordenada y de la destinació
/// @param w ample del quadrat d'oritge a pintar
/// @param h alt del quadrat d'oritge a pintar
/// @param sx coordenada x de l'oritge
/// @param sy coordenada y de l'oritge
/// @param zoom zoom a aplicar al pintar
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int zoom);
/// @brief Pinta tota la superficie "source" en la superficie "destination", posició (x,y).
/// @param x coordenada x de la destinació
/// @param y coordenada y de la destinació

View File

@@ -17,8 +17,12 @@ void game::init()
bool loop()
{
draw::cls(0);
rooms::drawFullMap();
//draw::cls(0);
//rooms::drawFullMap();
rooms::draw();
draw::color(COLOR_BRIGHT_BLACK);
for (int i=0; i<=32; ++i) draw::vline(64+i*16, 48, 256);
for (int i=0; i<=16; ++i) draw::hline(64, 48+i*16, 512);
draw::render();
return true;
}

View File

@@ -18,6 +18,7 @@ namespace rooms
std::string current_room = "";
std::map<std::string, room_t> rooms;
int full_map_x = 0, full_map_y = 0;
draw::surface *map_surface {nullptr};
static const char *paletteMap[] = {
"black", "bright_black", "blue", "bright_blue",
@@ -284,6 +285,10 @@ namespace rooms
detectFullMapOffset("01", 0, 0);
full_map_x++;
full_map_y++;
if (map_surface) draw::freeSurface(map_surface);
map_surface = draw::createSurface(256,128);
/*for (auto &item : rooms)
{
room_t &room = item.second;
@@ -295,17 +300,23 @@ namespace rooms
std::cout << std::endl;
}
}*/
room_t &room = rooms["01"];
for (int y=0; y<16; ++y) {
for (int x=0; x<32; ++x)
std::cout << std::to_string(room.tiles[x][y]) << ",";
std::cout << std::endl;
}
}
void draw()
{
room_t &room = rooms["02"];
draw::cls(room.border);
draw::setViewport(32, 24, 256, 128);
draw::cls(room.bgColor);
room_t &room = rooms["01"];
draw::setTrans(16);
draw::setDestination(map_surface);
draw::resetViewport();
draw::setSource(room.tileSetFile);
draw::cls(room.bgColor);
for (int y=0; y<16; ++y) {
for (int x=0; x<32; ++x) {
@@ -317,6 +328,7 @@ namespace rooms
}
}
draw::setTrans(0);
for (auto enemy : room.enemies)
{
enemies::enemy_t &anim = enemies::get(enemy.animation);
@@ -327,10 +339,18 @@ namespace rooms
draw::restorecol(1);
}
draw::setTrans(16);
draw::setDestination(nullptr);
draw::setSource(map_surface);
draw::cls(COLOR_BRIGHT_BLACK);
draw::color(room.border);
draw::fillrect(48, 32, 512+32, 256+32);
draw::setViewport(64, 48, 512, 256);
draw::draw(0, 0, 256, 128, 0, 0, 2);
draw::resetViewport();
draw::setSource(room.thumbnail);
draw::draw();
//draw::setSource(room.thumbnail);
//draw::draw();
}
void drawFullMap()