06 Nov 2019 - vidya
Something new is growing…
It’s some cauliflower–I have successfully implemented farming and the day cycle!
Not the prettiest pixel cauliflower in existence... but it'll do!
Implementing planting and growing was actually quite a bit easier than I anticipated! I had already created a system for targeting Tiles, and a system that linked Tiles to their contained WorldObject (what I am now calling objects like rocks, trees, flowers, etc. that are bound to a Tile location)… so now I just needed to connect the two! I created a WorldObjectSpawnEffect that targets Tiles… then, if the target Tile contains no WorldObject, instantiate a WorldObject and update the Tile to reflect its new inhabitant!
Up next was time–plants need a lot of it! In the above GIF you can see that I had already set up a “Pass Day” function when I first implemented plants. All it did was issue a DayChange event, and each plant WorldObject had a component listening to that event. I created a WorldTileEffect that would change the soil into a watered soil sprite, and also update a new WaterLevel component of the Tile. If the plant’s Tile’s WaterLevel is satisfactory, the plant grows in response to a DayChange event. Otherwise, it tallies a “stagnantDays” integer. Enough stagnant days and the plant can die!
Next was implementing a day and night cycle. Now, traditional farming simulators usually have you go to sleep to pass a day (and save), and I plan to do the same! But first, minutes and hours needed to pass. Unity has a number of ways of incrementing values over time, I simply went with a ‘increment every X frames’ type of function to increment the time. Then I converted this raw integer into minutes and hours with some functions to determine AM/PM and the reset of the day, etc. Using some Unity AnimationCurves as well as Gradients, it was easy to set up a cycling color and intensity gradient for the sun!
Time is racing! And the days are resetting at midnight. Just for demonstration ;-)
Very excited with how this ended up, and how all the pieces are already coming together! With this, I have completed the core farming loop of farming simulator games. But, there is still much more to look forward to!