Time System

Back to the Devlog
Posted: 29 Sep 2018 21:01

Time, Clocks, & a Night Cycle

This turned into a rather time consuming project, but mostly because this is all still a learning experience for me. In order to feel immersed, I knew that it was an absolute necessity to have a day/night cycle. There is no built in mechanism to do this which means that I had to create the mechanism. This started with creating a time system. Essentially, this is done by creating an event that first sets a time to wait for x number of frames, then after those frames have passed I can add a value of 1 to a variable that I call "minutes". Once "minutes" reach 60 I then pass on a new value of +1 to a new variable called "hours" and finally, once hours reaches 24 I then pass on a +1 to a variable called "days". I have not added years yet.

Creating Time

Since the initial count of frames is referring to the frame-rate of the game, this means that I can decide on how long I want a day/night cycle to last. After some trial and error I ended up with one hour of real life time being equal to 24 hours in-game. This assumes that the game is running at 60 fps, which I can cap to ensure that time does not flow faster (if I decide to cap it). However, this also means that if someone with an older PC is playing with only 30 FPS, then one in-game day will last 2 hours of real life time, instead of just 1 hour.

Making it Dark or Light

With the time system built, I could then create day and night cycles, and what a royal pain this turned out to be. Long story short, I eventually hammered it out to what I wanted with night time lasting from 22:00 to 06:00 (10pm to 6am). With the rate that time passes in Nia, this means that one night will last for 20 minutes and day will last 40 minutes.

The most important part of setting up day and night cycles was setting up a feedback system for the user so that it actually feels like it is night when compared to day. For starters, it gets darker. From 22:00 to midnight is the "dusk" period and from midnight to 06:00 is the darker portion of night. It's dark, but not so dark that you can't see well enough to keep on playing. In addition to getting dark, the background music (BGM) stops to give the feeling that things are more quiet. But it's not silent, that BGM is replaced by a background sound (BGS) of night sounds such as crickets, the occasional hoot of an owl, and some mystery creature. This sound is a default sound asset but I like it so until I find something I like more, this will do well for now.

The simple task of stopping BGM to coincide with night meant that I had to redo the pre-existing default BGM system that came with RPG Maker. Prior to including night cycles, I had BGM hooked to a "room". A room is whatever current scene is loaded into the game, it could be the interior of a house, a dungeon, an outdoor area, or the world map. However, this conflicted with the default system so I had to go back and redo some things and change the way that BGM gets invoked. But it's good, the feedback is obvious and this really helps to set the night time mood.

One issue that I spent a lot of time on was deciding whether or not to have it dark indoors too. In the end I decided that having it dark inside as well as outside helped with the night time immersion. After all, it does get dark inside too, that's why we have indoor lighting IRL. Later on I will look at lighting elements for the indoors so that you can still tell that it's dark outside, yet have some illumination indoors based on the placement of lights. However, one thing I did do, is decrease the volume of the night sounds when inside because this is how it works IRL, with walls helping to muffle the sounds outside.

Look George! It's a Clock!

With the time system in place, it was quite easy to make a clock. All I had to do was use the dialogue box to display the variables of hours and minutes. However, I can also display the clock within the HUD. I have not yet decided if I want this by default, or if I want the player to first purchase a watch.

dark-with-clock.jpg


An early example of a clock as seen in the hud. It's 5:31 am, just before sunrise in the starter dungeon.

Other Opportunities

I'll be tweaking the time system as I progress because I know that I will eventually encounter issues that will require it. But the system is, for arguments sake, built. And with that out of the way, I can now use it for other events and encounters. One thing I would like to do, is have NPC's go home at night. I've also added a "days" variable so that the player can see how many in-game days s/he's been playing. I can also use this to trigger an event that happens on day x or to perhaps block something that does not become available until x days after trigger y happens. I have far more options now than I did prior to the time system.