Love2D Lua框架 - 将无组织的渲染表转换为地图结构

发布于 2024-10-27 06:02:34 字数 1284 浏览 0 评论 0原文

我正在将未组织的 2D 渲染地图转换为字符串表,例如:

“Render = {{Image,50,60,2}}”

其中 Image 是图像(我正在使用 Love2D Lua 框架) 50是X轴 60是Y轴 2 是图像 ID(这就是实际表中的内容。)

但是大约有 100 个这样的图像,所有这些都是无组织的,我需要将它们组织成结构化地图。

这是奇怪的一点:当我把它变成一个有组织的字符串时..它..有点逆时针旋转桌子90*角。

说我想要的结果

{ 
{7,6,5}, 
{6,5,4}, 
} 

是:

{ 
{5,4}, 
{6,5}, 
{7,6}, 
} 

显然没有错误,因为它在技术上是有效的,只是旋转错误。这是相关代码:

function OrganiseRenderIntoMap() 
    MapString = "" 

    Map2 = {} 
    MaxSoFarX = 0 
    MaxSoFarY = 0 
    for _,v in pairs(Render) do 
        if v[2] > MaxSoFarX then 
            MaxSoFarX = v[2] 
        elseif v[3] > MaxSoFarY then 
            MaxSoFarY = v[3] 
        end 
    end 

    for currx = 0, MaxSoFarX, 32 do 
        Map2[currx] = {} 
        MapString = MapString.."{" 
        for curry = 0, MaxSoFarY, 32 do 
            MapString = MapString..GetRenderPos(currx,curry).."," 
            Map2[currx][curry] = GetRenderPos(currx,curry) 
        end 
        MapString = MapString.."},\n" 
    end 

    return MapString 
end 


function GetRenderPos(locx,locy) 
    for _,v in pairs(Render) do 
        if v[2] == locx and v[3] == locy then 
            return v[4] 
        end 
    end 
end 

I'm turning a 2D rendered map which is unorganised into a string table, EG from:

"Render = {{Image,50,60,2}}"

Where Image is the image (I'm using Love2D Lua framework)
50 is the X axis
60 is the Y axis
2 is the Image ID (This is what will be in the actual table.)

But there's like 100 of these, all unorganised and stuff, and I need to oragnise them into a structured map.

Here's the odd bit: When I morph it into an organised string.. It.. Kinda rotates the table on a 90* angle anticlockwise.

Saying I want the result of

{ 
{7,6,5}, 
{6,5,4}, 
} 

I would get:

{ 
{5,4}, 
{6,5}, 
{7,6}, 
} 

Obviously no error since it technically works, just rotates wrongly. Here's the relevant code:

function OrganiseRenderIntoMap() 
    MapString = "" 

    Map2 = {} 
    MaxSoFarX = 0 
    MaxSoFarY = 0 
    for _,v in pairs(Render) do 
        if v[2] > MaxSoFarX then 
            MaxSoFarX = v[2] 
        elseif v[3] > MaxSoFarY then 
            MaxSoFarY = v[3] 
        end 
    end 

    for currx = 0, MaxSoFarX, 32 do 
        Map2[currx] = {} 
        MapString = MapString.."{" 
        for curry = 0, MaxSoFarY, 32 do 
            MapString = MapString..GetRenderPos(currx,curry).."," 
            Map2[currx][curry] = GetRenderPos(currx,curry) 
        end 
        MapString = MapString.."},\n" 
    end 

    return MapString 
end 


function GetRenderPos(locx,locy) 
    for _,v in pairs(Render) do 
        if v[2] == locx and v[3] == locy then 
            return v[4] 
        end 
    end 
end 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中二柚 2024-11-03 06:02:34

看看我的LÖVE 磁贴教程1d-Strings 部分讲述了如何处理“switched x和y”的问题。

Give a look at my LÖVE tile tutorial. Section 1d-Strings speaks about how to handle the "switched x and y" problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文