Page 1 of 1

[Ti-Asm] Tetris Clone Hit detection help

Posted: Sun 18 Jun, 2006 12:25 am
by dragon__lance
Hi, i'm trying to create a tetris clone(more accurately, Dr.Robotnik's Mean Bean Machine Remake) as my entry to Tifreakware's programming contest.I'm sorry i can't release too much info. about it, but it's restricted. The idea of the game is to have different colored blocks that drop. Once 4 or more blocks of the same touch in any way,they dissappear.And the blocks above fall, sometimes triggering combos. I need to find a way for hit dettection between the blocks. I have thought about it a lot. What i came up with is to allot each block a byte. The first 4 bits define the type of block(color),and the last 4 define the links that block has. Ex: When the block falls and hits another block of the same type, i set the corresponding bit, so it shows the relation.Then i run though all the relations, and if's it's above 4, i trigger dissapearing sequence. The problem is that i can already think of a dozen instances where this wouldn't work, and the falling blocks triggered from dissapearences would make it even more complicated :( I'm just wondering if anyone has a better way of doing this?

Posted: Sun 18 Jun, 2006 12:16 pm
by Liazon
How big are the blocks?

and aren't you going to have a tilemap anyways?

Posted: Sun 18 Jun, 2006 12:47 pm
by CoBB
The trivial solution doesn't require you to maintain relations between blocks. All you need is one free bit in each block. This bit is initially reset everywhere on the whole playfield. When a new piece falls and reaches its final place, run the check routine for each of its blocks. The check routine does the following:

1. Run a floodfill routine that sets this marker bit for every block that makes a contiguous single-coloured blob with the starting block. More on this below.
2. Count the blocks with the marker set. Check if the number is greater than the lower limit.
3a. If yes, clear all the blocks marked.
3b. If no, just reset all the marker bits you set in the first step (the dumb solution is to reset them for the whole field).

After all the deletions happened, let all the necessary blocks fall, and do the checks for every block on the field. This can be sped up by not checking those that were already marked during previous checks; you can achieve this by introducing another marker bit. Repeat this until no more deletions are possible.

The flood fill can be hard to program, but it has a simple solution with the drawback of using a lot of stack space. The input is the (x, y) coordinates of the starting block.

1. Mark the block at (x, y).
2. Call the routine for every unmarked neighbouring block which has the same colour. Note that this is a recursive routine, so you have to save the coordinates on the stack before making the recursive calls.

This will use as much stack as the longest path from the starting block. It can be made to use a lot less storage, but it adds complexity to the routine.

Posted: Sun 18 Jun, 2006 2:39 pm
by Dwedit
Then again, if you're looking to match up to 4 blocks like puyopuyo, it's not going to use much stack space.

Posted: Sun 18 Jun, 2006 3:42 pm
by CoBB
It's not at most but at least four blocks. It's an interesting question what's the upper limit of the possible areas. By direct impact you can't get bigger than x*(4-1)+n, where n is the number of blocks per piece and x is the number of disjoint areas a piece can touch at the same time (if n=1, then x=3; if n=3, then x=5; probably x=n-(n mod 2)+3, I'm not entirely sure). That's no problem. However, combos might easily lead to bigger areas, but it's hard to tell how big. Most probably this won't be an issue with a 100-deep stack.

Posted: Sun 18 Jun, 2006 4:17 pm
by kv83
Afaik there are no combo's in Tetris possible :) There is no gravity, so blocks will not "fall" down, if one piece of their own block is "ereased". This can cause "floating" blocks :)

Posted: Sun 18 Jun, 2006 4:35 pm
by dragon__lance
I'm trying to create a tetris "clone", otherwise as i've stated before, a remake of puyopuyo, known as Dr.Robotnik's Mean Bean Machine in the US. In this version, 2 blocks fall down at a time :)
Thanks Cobb,I'll get to programming now :) I might have a few more questions though...

Posted: Mon 19 Jun, 2006 12:23 am
by thegamefreak0134
For making the blocks fall, try this:

1) go by columns and run up the column. If there is an empty space, do the next steps, otherwise quit routine
2) On an empty space, starting at the space load into that tile the one above it, advance tile and repeat. (of course, save the empty space position)
3) When you get to the top jump back to the same block and repeat the process at one. Make sure the block you jump to gets checked again, or you will get holes left.

If you want, you can take the above and mod it so the blocks are moved and marked, and then you animate the marked ones for the fall. Otherwise, this should work, and I know it will because I use it for my bejeweled variations, which fall in the same manner. As for the individual piece controll, you're on your own there. Sorry.

-thegamefreak

Posted: Mon 19 Jun, 2006 6:03 pm
by Dwedit
I doubt you will extinguish the stack, unless more than 100 pieces are marked in a flood fill. Using tail-recursion would eliminate stack usage by non-junctions.