locke
|
(EDIT: Oops... this should be in Help... sorry!)
Have a question for you smart guys and gals...
I'm doing a 'columns'-like game...
You know, tetris-style objects falling. When you line up a bunch of like-objects, it deletes them, etc.
Well, I'm having trouble validating squares next to the squares I'm dropping.
Let's keep this simple:
I'm dropping 2x2 blocks, each of the 4 sub-blocks could be one of two colors. I want to delete sub-blocks from the grid when I get (at least) 3 of the same color in a row. Sounds easy.
But how do I check for 3 in a row quickly and efficiently?
Right now I am basically looking at the squares next to the sub-blocks I just dropped... but it's extremely cumbersome.
I'm thinking, maybe I should iterate over the whole grid when a block is 'placed'. I could just look for 3-in-a-row with a nested for-loop. I'd have to do two passes for horizontal and verticle.
Thoughts? Easy way to find groups? Searching off the newly placed block is extremely ... blecky. Or maybe I'm doing it wrong.
Thanks. Hope you'all are well.
-l
Posted on 2005-02-10 17:34:36 (last edited on 2005-02-10 17:35:23)
|
locke
|
Quote:Originally posted by TomT64
You could do it line by line based on the placement of the block. VOpenCHR once did this to flood fill colors. However I had difficulty understanding it. It is apparently a very fast way to check for differences on a 2D grid.
I would say check each horizontal line where the block is placed for a 3 in a row match. You could save each line in an array and then treat each array as a 2D grid to check for matches. This would effectively remove the need to check the entire board.
Yeah, that's kinda what I was working on. The problem that I ran into is that I basically need to check a 3 square block AROUND the blocks itself, because of 'crossovers'. For example, I have a one block on the left of the newly placed block, that happens to match the blocks I just placed, plus there are a few blocks on the right which match, which form a line of ... let's say... 5 blocks that all should be deleted.
Hmmm ... you made me think of something. A mini-grid that extends 3 blocks out would cover it, but I still have to process each square. I'm using a flag system now... like it finds two that match, raises sets a counter, etc... it's just a lot to deal with. It seems like such a simple task... such a simple game, but not so simple. I'll keep banging away. Thanks!
-l
Posted on 2005-02-11 07:36:15
|