- Treballant en el mapa

This commit is contained in:
2024-09-16 14:08:49 +02:00
parent 2fd5f39285
commit 4ace433340
3 changed files with 72 additions and 30 deletions

View File

@@ -504,6 +504,17 @@ namespace draw
sel_color = col;
}
void isoline(int x, int y, const int dx, const int dy, const int len)
{
for (int i=0; i<len; ++i)
{
pset(destination, x,y, sel_color);
x+=dx;
pset(destination, x,y, sel_color);
x+=dx; y+=dy;
}
}
void hline(const int x, const int y, const int w)
{
for (int i=x;i<x+w;++i) pset(destination, i, y, sel_color);

View File

@@ -108,6 +108,7 @@ namespace draw
void swapcol(const uint8_t c1, const uint8_t c2);
void restorecol(const uint8_t c);
void color(const uint8_t col);
void isoline(int x, int y, const int dx, const int dy, const int len);
void hline(const int x, const int y, const int w);
void vline(const int x, const int y, const int h);
void fillrect(const int x, const int y, const int w, const int h);

View File

@@ -11,7 +11,7 @@ namespace modules
{
draw::surface *surf;
vec2_t scroll {0,0};
bool drawn[64];
int drawn[64];
int current_room;
struct miniroom_t
@@ -23,6 +23,49 @@ namespace modules
};
miniroom_t minirooms[64];
void drawLines(const int room, const int x, const int y)
{
if (drawn[room]) return;
drawn[room] = true;
if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) )
{
draw::color(RED);
if (minirooms[room].exits[XN] != 255) { draw::isoline(x,y,-1,-1,14); draw::isoline(x,y-1,-1,-1,14); draw::isoline(x,y+1,-1,-1,14); }
if (minirooms[room].exits[YN] != 255) { draw::isoline(x,y,+1,-1,14); draw::isoline(x,y-1,+1,-1,14); draw::isoline(x,y+1,+1,-1,14); }
if (minirooms[room].exits[XP] != 255) { draw::isoline(x,y,+1,+1,14); draw::isoline(x,y-1,+1,+1,14); draw::isoline(x,y+1,+1,+1,14); }
if (minirooms[room].exits[YP] != 255) { draw::isoline(x,y,-1,+1,14); draw::isoline(x,y-1,-1,+1,14); draw::isoline(x,y+1,-1,+1,14); }
}
if (minirooms[room].exits[XN] != 255) drawLines(minirooms[room].exits[XN], x-24, y-12);
if (minirooms[room].exits[XP] != 255) drawLines(minirooms[room].exits[XP], x+24, y+12);
if (minirooms[room].exits[YN] != 255) drawLines(minirooms[room].exits[YN], x+24, y-12);
if (minirooms[room].exits[YP] != 255) drawLines(minirooms[room].exits[YP], x-24, y+12);
}
void drawRoom(const int room, const int x, const int y)
{
if (drawn[room]) return;
drawn[room] = true;
if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) )
{
draw::stencil::set(room);
draw::swapcol(1, minirooms[room].color);
draw::draw(x-16, y-8, 32, 16, minirooms[room].w*32, minirooms[room].h*16);
//draw::swapcol(1, RED);
//if (minirooms[room].exits[XN] != 255) draw::draw(x-4-(minirooms[room].w*2), y-5-(minirooms[room].w),4,5,0,64);
//if (minirooms[room].exits[YN] != 255) draw::draw(x+(minirooms[room].h*2), y-5-(minirooms[room].h),4,5,3,64);
//if (minirooms[room].exits[XP] != 255) draw::draw(x+(minirooms[room].w*2), y-3+(minirooms[room].w),4,5,0,64);
//if (minirooms[room].exits[YP] != 255) draw::draw(x-4-(minirooms[room].h*2), y-3+(minirooms[room].h),4,5,3,64);
char num[] = "00"; num[0] = 48+(room/10); num[1] = 48+(room%10);
draw::print(num, x-4, y-3, LIGHT+(room==current_room?YELLOW:WHITE), BLACK);
}
if (minirooms[room].exits[XN] != 255) drawRoom(minirooms[room].exits[XN], x-24, y-12);
if (minirooms[room].exits[XP] != 255) drawRoom(minirooms[room].exits[XP], x+24, y+12);
if (minirooms[room].exits[YN] != 255) drawRoom(minirooms[room].exits[YN], x+24, y-12);
if (minirooms[room].exits[YP] != 255) drawRoom(minirooms[room].exits[YP], x-24, y+12);
}
void loadMiniRoom()
{
const int room = room::getCurrent();
@@ -53,45 +96,32 @@ namespace modules
current_room = room::getCurrent();
loadMiniRoom();
room::load(current_room);
}
void drawRoom(const int room, const int x, const int y)
{
if (drawn[room]) return;
drawn[room] = true;
if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) )
{
draw::stencil::set(room);
draw::swapcol(1, minirooms[room].color);
draw::draw(x-16, y-8, 32, 16, minirooms[room].w*32, minirooms[room].h*16);
for (int i=0;i<64;++i) drawn[i]=false;
draw::cls(2);
draw::setSource(surf);
drawLines(room::getCurrent(), scroll.x, scroll.y);
draw::swapcol(1, RED);
if (minirooms[room].exits[XN] != 255) draw::draw(x-4-(minirooms[room].w*2), y-5-(minirooms[room].w),4,5,0,64);
if (minirooms[room].exits[YN] != 255) draw::draw(x+(minirooms[room].h*2), y-5-(minirooms[room].h),4,5,3,64);
if (minirooms[room].exits[XP] != 255) draw::draw(x+(minirooms[room].w*2), y-3+(minirooms[room].w),4,5,0,64);
if (minirooms[room].exits[YP] != 255) draw::draw(x-4-(minirooms[room].h*2), y-3+(minirooms[room].h),4,5,3,64);
for (int y=-1; y<=1; ++y)
for (int x=-1; x<=1; ++x)
{
for (int i=0;i<64;++i) drawn[i]=false;
drawRoom(room::getCurrent(), scroll.x+x, scroll.y+y);
}
char num[] = "00"; num[0] = 48+(room/10); num[1] = 48+(room%10);
draw::print(num, x-4, y-3, LIGHT+(room==current_room?YELLOW:WHITE), BLACK);
}
if (minirooms[room].exits[XN] != 255) drawRoom(minirooms[room].exits[XN], x-24, y-12);
if (minirooms[room].exits[XP] != 255) drawRoom(minirooms[room].exits[XP], x+24, y+12);
if (minirooms[room].exits[YN] != 255) drawRoom(minirooms[room].exits[YN], x+24, y-12);
if (minirooms[room].exits[YP] != 255) drawRoom(minirooms[room].exits[YP], x-24, y+12);
}
bool loop()
{
for (int i=0;i<64;++i) drawn[i]=false;
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
draw::cls(2);
draw::setSource(surf);
draw::stencil::enable();
draw::stencil::clear(255);
for (int i=0;i<64;++i) drawn[i]=false;
drawRoom(room::getCurrent(), scroll.x, scroll.y);
draw::render();