如何制作“矩阵”对于拼图泡泡?

发布于 2024-10-03 13:39:02 字数 327 浏览 0 评论 0原文

嘿伙计们,我正在尝试制作一个拼图泡泡克隆,但我对如何处理背景内容感到困惑。主要是因为线条不匹配(即:一个气泡不是有另一个没有顶部的气泡,一个在左上角,一个在右上角,而是一个在左上角,一个在右上角)右上角 http://dl.dropbox.com/u/680263/puzzle_bobble_2.jpg< /a>)以及如何确定射击时哪些气泡会破裂(以及哪些气泡会掉落),而无需使用会让我的 i7 哭泣的蛮力算法。

谁能就如何处理这个问题提出一些建议?

Hey guys, I'm trying to make a puzzle bubble clone but I'm stumped on how to handle the background stuff. Mostly with the fact that the lines don't match up (i.e: instead of a bubble having another no top of it, one on the upper-left and one on the upper-right, it has one on the upper left and one on the upper right http://dl.dropbox.com/u/680263/puzzle_bobble_2.jpg) and how to determine which bubbles pop when I make shot (and which fall) without making a brute-force algorithm that would make my i7 cry.

Can anyone give some sugestions on how to handle this?

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

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

发布评论

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

评论(3

小苏打饼 2024-10-10 13:39:02

它必须是多维数组吗?像这样的“气泡”结构怎么样:

typedef struct t_bubble_tag {
   t_colour colour; /* whatever else you want to store about your bubble */
   struct t_bubble_tag pUpperLeft;
   struct t_bubble_tag pUpperRight;
   struct t_bubble_tag pLeft;
   struct t_bubble_tag pRight;
   struct t_bubble_tag pLowerLeft;
   struct t_bubble_tag pLowerRight;
} t_bubble;

然后,当您弹出一个给定的气泡时,您可以沿双向和横向双向遍历树,并摆脱最终未附着在顶部的任何气泡“岛”墙。请记住,气泡可以由其他气泡的“手臂”从侧面或下方支撑。

我怀疑与使用多维数组相比,这存储效率较低,但速度效率更高。

Does it have to be a multi-dimensional array? How about a "bubble" structure like this:

typedef struct t_bubble_tag {
   t_colour colour; /* whatever else you want to store about your bubble */
   struct t_bubble_tag pUpperLeft;
   struct t_bubble_tag pUpperRight;
   struct t_bubble_tag pLeft;
   struct t_bubble_tag pRight;
   struct t_bubble_tag pLowerLeft;
   struct t_bubble_tag pLowerRight;
} t_bubble;

Then when you pop a given bubble, you can do a tree traverse down both ways and sideways both ways, and get rid of any "island" of bubbles that are not eventually attached to the top wall. Bear in mind bubbles can be supported by "arms" of other bubbles from the side or below.

I suspect that this is less storage efficient, but more speed efficient, than using a multi-dimensional array.

硪扪都還晓 2024-10-10 13:39:02

我已经用Lua用表格实现了这个泡泡拼图游戏,
http://www.youtube.com/watch?v=rD0fQVSj_7w& ;list=UUlKVS4jFzSMXF9l6Jw1uoaw&feature=plcp
你可以在这里看到代码:
https://gist.github.com/1725481

您可以使用二维拼图板来使用此实现表:

function Puzzle:loadPuzzle()
    print("Loading level "..level)
    self.state     = PUZZLE_LOADING
    -- create the bubbles
    local n = 0
    local k = 0
    local w = self.width
    local h = self.height
    for i=1, h do
     self.bubbles[i] = {}
     n = 0
     if levels[level][i]~=nil then
         n = #(levels[level][i])
     end
     local aux = 0
     if math.fmod(i,2)==0 then
        aux = (self.bubbleSize/2) + 16
     end
     local y = self.initHeight+self.tileSize*self.height - self.bubbleSize - (i-1)*self.tileSize
     for j=1,self.width do
        local c,state = nil,BUBBLE_EMPTY
        if nil==levels[level][i] or nil == levels[level][i][j] then 
            c = nil
            if aux>0 and j==self.width then
                state = nil
            end
        else
            c = levels[level][i][j]
            state = BUBBLE_ATTACHED
            self:addCurrentColor(c,currentColors)
        end
        self.bubbles[i][j] = Bubble(
            vec2(aux+self.initWidth+self.tileSize*j - self.bubbleSize,y),
            self.tileSize, -- bubble radius size
            c --color
         ) 
        self.bubbles[i][j].state = state 
      end 
    end
    sound(SOUND_POWERUP, 33755)
    self.state     = PUZZLE_PLAYING
    print(""..(#currentColors).." colors")
end

用 C 代码编写很简单......

I have implemented this Puzzle Bubble game in Lua with tables,
http://www.youtube.com/watch?v=rD0fQVSj_7w&list=UUlKVS4jFzSMXF9l6Jw1uoaw&feature=plcp
you can see the code here:
https://gist.github.com/1725481

You can use this implementation for the puzzle board using a bidimensional table:

function Puzzle:loadPuzzle()
    print("Loading level "..level)
    self.state     = PUZZLE_LOADING
    -- create the bubbles
    local n = 0
    local k = 0
    local w = self.width
    local h = self.height
    for i=1, h do
     self.bubbles[i] = {}
     n = 0
     if levels[level][i]~=nil then
         n = #(levels[level][i])
     end
     local aux = 0
     if math.fmod(i,2)==0 then
        aux = (self.bubbleSize/2) + 16
     end
     local y = self.initHeight+self.tileSize*self.height - self.bubbleSize - (i-1)*self.tileSize
     for j=1,self.width do
        local c,state = nil,BUBBLE_EMPTY
        if nil==levels[level][i] or nil == levels[level][i][j] then 
            c = nil
            if aux>0 and j==self.width then
                state = nil
            end
        else
            c = levels[level][i][j]
            state = BUBBLE_ATTACHED
            self:addCurrentColor(c,currentColors)
        end
        self.bubbles[i][j] = Bubble(
            vec2(aux+self.initWidth+self.tileSize*j - self.bubbleSize,y),
            self.tileSize, -- bubble radius size
            c --color
         ) 
        self.bubbles[i][j].state = state 
      end 
    end
    sound(SOUND_POWERUP, 33755)
    self.state     = PUZZLE_PLAYING
    print(""..(#currentColors).." colors")
end

and write in C code is simple...

哽咽笑 2024-10-10 13:39:02

我不认为在益智泡泡游戏中使用这种数据结构是一个好主意,因为它需要更新棋盘中所有泡泡的大量指针。

就拿这个简单的例子来说:

  • 当你有两个或三个相同颜色的气泡和两个不同颜色的气泡时,所有气泡都已经设置在板上;下一个发射的气泡是第一种颜色,它击中了三个气泡,您必须首先将气泡附加到其位置,然后更新所有指针。

  • 然后,您必须遍历所有这些指针来搜索气泡姐妹(相同颜色和相邻),但使用这种数据结构更难找到,因为您必须构建多个具有很多条件的递归函数。

另外你还必须知道第一行的气泡比下一行多,即偶数行有 7 个(例如),奇数行有 6 个气泡。

使用表格时,您必须考虑这些情况,这也很复杂。
也许,另一种实现可能是使用一棵树,其中根具有第一行气泡作为子节点。

I don't think that using this data-structure in a puzzle bubble game is a good idea, because it needs to update a lot of pointers for all the bubbles in the board.

Just take this simple case:

  • when you have two or three bubbles of the same colour and 2 with different colors, all already set in the board; and the next bubble launched is of the first color, it hits the group of three, you have first to attach the bubble in its place and then update all the pointers.

  • then, you have to go through all these pointers searching for bubble sisters (same colour and adjacents) but with this datastructure is much harder to find because you have to build several recursive functions with a lot of conditions.

Also you have to know that the first line of bubbles have more than the next, it is, even rows have 7 (for example) and odd rows have 6 bubbles.

With a table you have to consider these cases, there is also a complexity here.
Maybe, another implementation could be to use a tree where the root has the first line of bubbles as child nodes.

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