Terrarium (WIP)

Update #5: Bugs! (the flying kind)

I actually had a bug flying around within a tile shortly after I started the project weeks ago. Sort of a proof of concept. Once I switched to “official” production mode I removed that code while I finalized the communications code and water & plant systems.

But now’s the time to bring it back!

bug

Once spawned, bugs will fly around between tiles.

Here’s a more fully-formed terrarium with a bug having fun.

bug2

These tiles are really difficult to photograph. Maybe a DSLR would work better - I don’t know. The colors just bleed into one another too much in video.

Plant branches

Plants used to be all green as they grew. I made it so when a new leaf grows, the thing it attaches to changes color to look closer to a proper branch.

Plant flowers

I’m also trying to work flowers into the plants. Right now they only grow under certain conditions that are pretty difficult to set up, but let me know if you manage it.

If you do manage to blossom a flower, a bug will spawn. It’s a kind of game-ified progression system to give you something to do and strive for. I would have put tons of those kinds of things in if the code space gods were more generous.

For now, though, since it’s still a work in progress, you can triple-click any tile to spawn a bug there.

Dripper = Gravity

I didn’t like having a fourth type of special tile to handle gravity. Since most folks only have six tiles to begin with, that takes away too many from actually building your terrarium.

I merged the gravity tile functionality into the dripper. It kind of makes sense anyway - gravity mostly only affects water.

To communicate the direction of gravity, I changed how the dripper looks. It will now kind of flow down within the tile. If you want to change gravity direction, you need to physically rotate the tile. Clicking will only affect the dripper speed.

Render experimentation

I experimented with a new renderer that is a bit more sophisticated, but it ended up taking too much code space that I couldn’t afford. I did manage to add code to brighten tiles that are in the path of sunlight. So at least there’s that.

Profiling

I profiled my main loop to see how long it takes. I used the tile faces to display, in binary, the time difference between millis() calls in successive “frames”. Turns out to be between 31-48 ms, which is honestly in line with what I was hoping.

I was worried that when transferring the bug from tile to tile, it would briefly show up on both due to the communications delay. That doesn’t seem to be a problem though. Whew!

Learnings

I had some code to set a timer in several places. I consolidated that into a helper function and called that instead. Turned out to save a significant chunk of code space. Lesson learned there!

Future

Code space is pretty much full for both sketch types (special tiles and normal tiles). I don’t want this to be the end of the project so I’m going to try to eke out enough space for one more update. Optimization ahoy!

9 Likes