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

GLOOMHAVEN RPG
GLOOMHAVEN RPG: Designer Diary 11

November 21, 2024

Join Danielle as she peels back the curtain on the game's captivating art and layout in our latest Designer Diary. And get an exclusive sneak peek at the stunning artwork on its way to the final book!

Read More

CEPHALOFAIR DESIGNER DIARY ISSUE 10: GLOOMHAVEN RPG
CEPHALOFAIR DESIGNER DIARY ISSUE 10: GLOOMHAVEN RPG

September 13, 2024

Read More

CEPHALOFAIR DESIGNER DIARY ISSUE 9: GLOOMHAVEN RPG
CEPHALOFAIR DESIGNER DIARY ISSUE 9: GLOOMHAVEN RPG

September 13, 2024

A sneak peak on character creation and Quatryl stats for Gloomhaven RPG.

Read More