Monday, November 14, 2016

Harvest Booze Update #2: The Miracle of Time

So I'm working on getting trees into the game, but here's the thing: trees have to grow. That growth is somehow tethered to time. WHAT IS TIME?

Most farming games deal with the problem of things growing over time by just having them grow while you're asleep. So you just need a few sprites for the various growth stages of a tree, and it updates between days, so you'll wake up to find that the oak tree which was a sapling last night is now an adult tree. It's a weird convention, I guess, but it works just fine as long as you force the player to sleep every night. I really want to let the player sleep wherever & whenever they want, though, which poses a couple of problems.

First of all, events in time clearly can't be synced to the player's sleep schedule. There will be good reasons to work during the day & sleep during the night, just like there are in life (e.g. it's pain-in-the-ass dark at night), but I want the player to decide how they spend their time in the game. So, if I stick with my planned sleep system, I won't know ahead of time when a player will sleep or even for how long. I need another way for things in the world to keep track of time. What's more, I need to be able to speed up time when the player is sleeping, so time passing in the game world can't rely on a constant clock or on time passing in the real world like some always-on games (Farmville & so on) do. And everything in the game needs to be on board, marching in sync.

The other thing is, with this system, I can't have just a couple of sprites for different growth stages. I mean, I could, but it would be goofy if a sapling suddenly changed into a mature tree as you were walking by. I could just draw a bunch of in between sprites so the transition isn't so jarring, but, like, what a pain in the dick, I'm not going to do that. Even if I had a program interpolate the in between sprites, I would have to load all of those into the game, which would probably have a noticeable effect on loading times once I have all of the plants finished. So I need a better way.

I've finished a time keeping system which I think solves the first problem. It keeps track of time in the game world, updating a few times per (real world) second to move time along and call an update function which iterates over everything in the game world, letting the trees & everything else know that a minute or whatever has passed. Then the objects themselves, the trees & whatnot, use that information to take care of themselves. I can easily change how many minutes pass per update, so I can speed up the passage of time when I need to. So I have an acorn object in the game now that is born with a "time_to_sprout" property. Once planted, whenever the time keeping system tells it that some time has passed, the time_to_sprout decreases by that same amount. When the acorn sees that time_to_sprout is zero or less, it starts to grow a tree.

That still doesn't solve the problem of how to visually represent the tree growing in a smooth, gradual way. I've got a plan which I think will work, though, so that's what I'm working on now. Next post will either feature a nice forest growing from a bunch of acorns, or a hilarious glitched out mess. Should be good either way.

No comments:

Post a Comment