Lazy Robots - Block selection

April 09, 2012

So after creating the basic building blocks of the levels, I started working on selecting boxes by clicking on them. Which would seem relatively straightforward, right? Like a couple lines of code...

But then complications arose. First of all, I wanted a shift-click option as well that would highlight all contiguous blocks at once, so that was somewhat complex - writing a function to take coordinates from an array, look at all the nearest neighbor spaces of that coordinate and feed those back into the array under certain conditions so the function could be run recursively until all contiguous blocks were found.

The goal in the end is really ease of control. So shift-click just seemed like an obvious implementation, as well as the ability to deselect specific boxes, say, if you wanted to move all the boxes of a specific group except one (and shift-clicking a selected box would deselect all boxes).

But then I started to have major problems with having multiple groups of non-contiguous blocks selected at the same time. So, first of all, every time you select any block, you've gotta check if any other boxes are selected, and, if so, are they adjacent to the box you're selecting? (If not, deselect them.) But the real ass-kicker was what if deselecting an individual box split up a large group of boxes into two separate groups.

Now we've gotta look at all the neighboring boxes of the deselected square, including diagonals, and see if there are multiple groupings of selected boxes. Something like:
XOO
XDX
OOX
where D is the deselected box, and Os are selected boxes. But that doesn't necessarily mean two separate groups because the selected boxes could connect up farther away from the center, like:
XXXOO
XXOOO
XXDXO
XOOXO
OOOOO
So for N groupings of deselected boxes around the original deselected box, I investigate N-1 groups by storing all their coordinates in an array, and then starting with the first coordinate (moving clockwise around the D), I attempt to move around the border of a group of selected boxes counter-clockwise, always keeping track of the coordinate I am in and the coordinate I came from. If you move around the border of group, eventually you are going to get back to where you started. And here's the thing: if I enter the original D square by moving from a coordinate that was in the original set of deselected boxes I started in, then there wasn't a break in the group of selected boxes, but if I move in from a coordinate corresponding to another set, then the group of selected boxes I traveled around, then that group is separate from the other selected boxes neighboring the original D and I've split up a group by deselecting that box. In that case, I just deselect everything as punishment to the play from making me write that ridiculous code.

Here's a movie demonstration (first screens!). It might be a little clearer. Maybe not.
And I'm sorry there aren't cute lazy robots yet. Just boxes...


Leave a comment

Comments will be approved before showing up.


Also in Blog

CEPHALOFAIR DESIGNER DIARY ISSUE 8: GLOOMHAVEN RPG
CEPHALOFAIR DESIGNER DIARY ISSUE 8: GLOOMHAVEN RPG

June 05, 2024

Dive into our newest Designer Diary post detailing fan's first-time experiences at UKGE and their thoughts about the game. They've played it, now it's your turn! Find out where else you can try it, next.

Read More

CEPHALOFAIR DESIGNER DIARY ISSUE 7: GLOOMHAVEN RPG
CEPHALOFAIR DESIGNER DIARY ISSUE 7: GLOOMHAVEN RPG

April 30, 2024

Join us in today's Designer Diaries where Danielle gives us an insider look into the Merchant's Guild, Factions, and Reputation Tiers in Gloomhaven RPG.

Read More

CEPHALOFAIR DESIGNER DIARY ISSUE 6: GLOOMHAVEN RPG
CEPHALOFAIR DESIGNER DIARY ISSUE 6: GLOOMHAVEN RPG

April 02, 2024

Danielle talks about more updates on the Gloomhaven RPG, featuring revelations and fun from our recent Gloomcabin (Cephalofair Games' annual retreat) trip.

Read More