Re: [stella] Big Dig

Subject: Re: [stella] Big Dig
From: Christopher Tumber <christophertumber@xxxxxxxxxx>
Date: Sun, 10 Oct 2004 11:24:16 -0400
>You somehow seem to prefer that kind of code. ;-)

Heh...

>How do you time the complex routines? Do you read the timer and abort when running out of time? 

I tried that but I could never get it to "interrupt" elegantly.

Instead I made all my routines completely modular and sectional and went with a Status byte. So, for example when nothing special is going on, Status=0.

When the game needs to check if there are any falling blocks Status is set to 1 which casues the "flag falling blocks" routine to be initialised and then Status is set to 2. At Status=2, the "flag falling blocks routine" searches for a block that has a blank space beneath it, these blocks have the *potential* to fall.

If such a block is found, Status is set to 3. At Status=3, the "find group" routine is initialised and status is set to 4. The "find group" routine is called every frame until the entire group is found (this can take several frames for a large, complex group). This is a brute force routine which searches the entire grid of blocks looking for new "neighbours". If no new neighbours are found in that iteration then the routine is done. Otherwise the routine must be run again. A single search through is done each frame, flagging member blocks as it goes. (doing this recursively would be much more efficient but also much more difficult to run over multiple frames, and RAM is a problem...)

Once the group is defined, the Status is set to 5. This calls the "check if this group can fall" routine which scans through looking to see if any members of the group have a non-group and non-blank block below them, in which case the group can't fall.

If the group can fall, the Status is set to 6. If it can't, the the group is un-flagged and Status is set back to 2 so that the "flag falling blocks" routine can be continued as there may be other "potentially falling blocks" to be found later in the grid.

At Status 6 the group falls which leads to Status 3 where the "find group" routine is initialised again (because the blocks may have ffallen onto like-coloured blocks and formed a larger group). This leads to Status 4 where the "find group" routine is run and run. After which is Status 7 where this group is checked to see if it's 4 or greater and if so the blocks are removed.

At which point we're back to Status 2 to continue looking for more "potentially falling blocks" as above.

Once the "potentially falling blocks" routine gets to the "top" of the grid of blocks, Status is returned to 0.

(I've probably skipped some steps in there and those aren't neccessarily the Status values I actually used, but you get the idea...)




Hey, that doesn't seem so complicated!!!



Chris...


Current Thread