The Case Study: Change Log

Following up on last time, the change log as I get ready for Friday:

1. The rules are now available through main game screen. (As I expected, this was a simple thing that took a long time. 😉 Unity’s UI system is definitely something I need to put a lot more practice into.)

2. There’s now a turn counter.

3. Searchers now correctly report locations for players to re-enter the game, even when overlapping with other searchers. (This turned out to be completely trivial, but I had to get a bunch of practice with Unity’s 2D physics engine before I could understand the problem and how to fix it. Here’s what happened:

The game needs to determine whether there’s anything in each of the 16 spaces around each searcher. It doesn’t matter what the thing is; if there’s anything in a space, that space is no good for re-entering.

In order to make that determination, the game used Physics2D.Linecast to send invisible lines from the center of the searcher to each of the 16 spaces. Each space got three lines: one that would respond if it hit a player, one if it hit a searcher, and one if it hit the edge of the board. If any of those lines reported that they’d hit something, that space gets marked as occupied.

Unfortunately, this system had a critical logic error. When searchers overlapped, the lines looking for searchers would hit something—the other searcher—instantly, as soon as they left their point of origin. The space would be marked occupied, but the line hadn’t actually gotten that far!

The fix was to send the line from the space to be checked to the space to be checked. Physics2D.Linecast, it turns out, allows one to have the same point as both the start and the destination; it will send a fractionally tiny line at that location, and if that line hits something it will report back normally. Using those fractionally tiny lines made it possible to check just the intended space. In the end, the entire fix was changing one word in one line of code:

hit = Physics2D.Linecast(start, surroundingSpaces[j], searcherLayer);

was changed to

hit = Physics2D.Linecast(surroundingSpaces[j], surroundingSpaces[j], searcherLayer); )

4. The rules now include players leaving trails in the sand, and the searchers following those trails.

5. Various smaller bug fixes, mostly relating to the UI.

So far so good; we’re on track for Friday!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s