Sky's the limit!


I have been getting deep into making the code for the game run smoother, work better, and be more expandable in the future. This was much more exciting to me than continuing to add new things which feels overwhelming. Instead, I want to make a super solid base for the way the game thinks so that creating more objects and content is much easier.

Previously, placing a piece of dirt on the ground just made it look like it was dropped, now vertical building is possible. I am working on another tool that cuts slopes into tiles so that building can be more customizable. This is necessary to the lore of the game since it is based on Mississippian people that built mounds in prehistoric North America.


The boss fight for quest 2 was a little unclear that grass traps were enemies since they just looked like grass. They now have some animation to make them look like they are special/dangerous.

Cut down level code by 50% by giving every "plantable" object (shovel, dirt, seeds, etc.) their own rules that the game level pulls from instead of having the game level make decisions based on the item being held. This is a pretty standard OOP technique that I overlooked here.

The biggest change in the code was that I completely reworked plants. Previously, every single plant was a static body with a sprite, multiple area 2ds, and a unique script for every plant type. Instead, I wrote one single script for plants that again uses functions and variables from the plant resources to determine what plants will do based on their type. Additionally, this script is in the grid data (every tile has unique data stored in a node). I gave the tile node functionality to spawn plants by adding a layer to the tile map that is the plant design. This way, tiles look like they have plants on them, but computationally it is equivalent to adding a tile. All that is present in the game world is an area 2d so that the player can click the plant to gather or otherwise interact with it. This area's parent is the game level, but its owner is the abstracted plant node.

Plant functional groups have rules for whether or not they can appear in the world based on what is already present. For instance, if a weed is present, a riparian plant cannot over take it, but if the tile is wet it can. This makes cycling of weeds/legumes possible, where a weed can outcompete a legume if the tile has enhanced nitrogen, but the legume can overtake the weed if nitrogen is degraded. This article in Nature discusses the ecology behind this concept and how game theory can be used to explain it: https://www.nature.com/articles/s41467-020-14531-6

Since the code is more robust, I can give a single plant multiple functional groups, so squash (arguably the most central plant to this game) can fix nitrogen, shade tiles (vining plants create shade that outcompetes weeds and protects taller plants, three sisters concept), and it can be a riparian plant since that is part of its niche in nature. This can lead to many complex interactions between species, while actually maintaining very simple rules.

Something that is super exciting about this is that randomizing plant cover at the start of the game is possible. I was trying to do this before, but instantiating all of those objects crashed my entire pc. Now, all I have to do is pass in a resource to the cell data, and the plants add themselves!

Going forward, I will apply these concepts to insect and animal nests and expand upon these concepts. Having one single script for plants will be such a breath of fresh air and make adding more plants so much less of a hassle. Saving and loading will be much faster as well.


Thanks for reading!

Cody

Leave a comment

Log in with itch.io to leave a comment.