Devlog 6/16 - Slugs and Beetles


Don't look too closely at the date this was posted.

Slugs

Slugs get you slime, but only if they have space to walk (crawl? trudge? slither?).  Furthermore, they can only use regions that are perfectly rectangular (and 1x1 is not allowed).  The code for these guys will always use the biggest rectangle that can be made while including the slug.  The algorithm for this is quite naive -- it starts with the four 2x2 squares that include the slug and progressively "spirals out", creating larger progressively larger rectangles until it no longer can, while keeping track of the largest valid rectangle.  Surprisingly, this seems to have very little performance impact (especially with an upper limit for how big a slug's rectangle can be), so I won't be pursuing any optimizations just yet.

The amount of slime you get from a slug scales linearly with the amount of space they have to work with.

Roller Beetles


Roller beetles are basically just dung beetles, but with a far more valuable payload.  Given a track to run on, they will roll out a shiny pearl for you to collect.  In computer science terms, this insect requires a cycle in order to do work.  This one ended up a bit different from the idea I had in the design doc.  I initially thought the smallest valid cycle would be a 3x3 like so:


While the 2x2 is a valid cycle, I thought it was a poor representation of the beetle's behavior and wanted to disallow it.  However, my first pass of the pathing logic did allow a 2x2, and I realized that it actually works quite well.  It turns out that because the beetle will always take the smallest cycle available to it, allowing a 2x2 gives some better feedback while you're building out its habitat, and so I decided to keep it.

The algorithm for this is also pretty simple, although it took me the longest to come up with so far.  It's essentially four breadth-first searches on each of the cardinals surrounding the beetle.  Each BFS will terminate as soon as it reaches a valid tile adjacent to the beetle.  Since this tile is necessarily a starting point for another BFS, I make an optimization to remove it from future searches.  Once we find a valid path, we still need to do the BFS starting with the other cardinals, and return the search that results with the smallest cycle if any. 

While writing this entry I find myself wondering why our roller beetles make pearls?  Clams make pearls as a way of isolating parasites and bacteria, while dung beetles roll dung because they need to bring it to a suitable location where it can be buried to provide sustenance for their young.  Perhaps roller beetles make pearls by accumulating minerals from the cavern floor? I won't speculate on why, but this line of thinking makes me interested in pursuing some minor procedural generation elements that were not on our initial design.  Something like tiles that give inherent bonuses for certain bugs if they're included in its habitat.

Get Bug Bank

Leave a comment

Log in with itch.io to leave a comment.