Unity Stardew Valley Day Night Cycle

While working on my current project, I needed a day night cycle similar to Stardew Valley. If you’ve ever played Stardew Valley, you’ll know it tracks hours, minutes, days, seasons, and years. It does this by having a 20 hour day from 6AM – 2AM, after which the character passes out.

I started this journey knowing I’d use a coroutine for my minutes tick. I wanted it to happen every 10 real life seconds and once it reached a value 60 I’d increment my hour and reset my minutes indicator.

        private void IncrementGameTime()
        {
            minutes += 10;
            if (minutes >= 60) {
                minutes = 0;
                hour += 1.0f;
                AdjustDarkness();
            }        
            
            if(hour >= 26)
            {
                hour = 6.0f;
                IncrementDays();
            }
        }

The entire system hinges on the code provided above. The method triggers an increment of days which impacts seasons, which also impacts the number of years that has been played.

I wanted my in-game time to be displayed as standard time as opposed to a 24 hour format, however the data is being represented in a 24 data format. So I had to write these additional methods.

GenerateStandardFormatHour does exactly as it reads, it converts a 24 hour time format to a 12 hour time format, with this I also needed to generate a meridiem value. A meridem is nothing more than the AM (ante meridem) which means before and PM ( post meridem ) meaning after.

        private float GenerateStandardFormatHour()
        {
            float stdHr = 0.0f;
            if (hour >= 13)
                stdHr = hour - 12.0f;
            else
                stdHr = hour;

            return stdHr;
        }

       private string GenerateMeridiem()
        {
            if(hour < 13)
            {
                return "AM";
            } else
            {
                return "PM";
            }
        }

So the script for this functionality is contained within one file, its easy to use. Drop it into a game manager or empty game object in your scene. Reference the script and observe the values. Where you take the functionality after this is up to you, you could increment a darkness overlay or do whatever your game needs. Additional coding will be needed though.

You can get the full script from my github:

https://github.com/Diaonic/UnityDayNightCycle/blob/master/DayNightCycle.cs

Cheers,

Corey

LD45 – Fan The Flames – Rated Edition

So the game rating portion of Ludum Dare is over and Fan The Flames had 54 people rate it, with a total of 76 downloads. While it would of been nice to land in the Top 100. I knew from the feedback I was getting this wasn’t a reality. The scope of this project was rather large and ambitious for a solo developer to pull off within 48 hours. My game lacked a proper tutorial or at least teaching aspects, and the controls were convoluted. These are the two primary areas I’d improve on if I was starting LD45 today. The main game-play loop was accomplished rather quickly, but I spent too much time trying to perfect a day night cycle. I should have included more crafting recipes and controlled the snowfall better. Minor annoyances such as repetitive jumping sound, poor collision detection, and a non intuitive workbench left players frustrated. Overall, I’m happy with the direction of the art, I was able to produces those sprites rather quickly and using a cohesive color palette really added to the mood which is my second highest ranking result. The audio rating is pretty funny, as its all procedural generated sounds.

The other area of improvement I needed was a pixel perfect camera, some users reported seeing lines between the tile sprites, which I didn’t experience. However, I bet on a 16:9 screen this was a problem. Overall a solid entry and I’m looking forward to crushing these scores in April when LD46 comes around.

Cheers,

Corey

Ludum Dare 45 – Fan The Flames

Fan The Flames – https://ldjam.com/events/ludum-dare/45/fan-the-flames

This past weekend I participated in the Ludum Dare 45 (LD). Its a biannual game jam where you’re tasked with creating a full featured game within 48 hours as a solo developer (compo), or 72 hours as a team (jam). The theme is announced at 6 PM EST on Friday.

The rules are simple, if you do the 48 hour compo, as a solo developer you need to create everything (art, programming, sound). The 72 hour jam allows multiple team members, and allots an extra 24 hours of development time.

Prior to the jam a voting process occurs where popular suggestions are floated to the top and a final theme is chosen. During this time I try to brainstorm at least one game idea for each of the possible themes on the final round. While this theme wasn’t my favorite, I had an idea and figured we’d run with it.

The idea centered around a campfire in a winter theme. The player needed to craft tools, harvest materials and keep the fire going while the environment fought back and tried to extinguish it. Thus Fan The Flames was born.

I started at 6PM on Friday and I knew I wanted procedural generation, but I had to keep the process simple, I opted for a small side scrolling level, with minimal platforming abilities. I had to keep the art style simple as well, I’m not an artist and my pixel art skills are below average at best.

  • Simple Art
  • Crafting System
  • Weather System
  • Day Night system
  • Tools
  • Inventory

These are the core features and as I kept planning sacrifices had to be made. I felt like the scope for a 48 hour was ambitious. I opted for no inventory system and would only allow the player to carry one item.

While I did complete the game and I felt accomplished, I learned a lot. First and foremost, I needed to focus more time on player controls and a tutorial. Players opening the game had no idea what to do, unless reading the Ludum Dare page. This broke immersion, the initial build had too many controls. Pickup and drop were separate keys, feed the fire was a separate key, it became really cumbersome to play and too many options were present. Allowing the player to only carry one item was a design choice, it was very cumbersome as the snowfall will continue to impede movement. I gave the player no tools to start and they should be able to at least use their hands at a reduced rate to accomplish something. A crafting recipe indicator was required, players had no idea how to craft items and I ended up releasing the crafting list after publishing.

It was a good experience overall, I learned more about game design than programming or technical work and I think some very valuable lessons were gleaned. I look forward to the next Ludum Dare in April 2020.

Castle Kilburn – Update

Warrior Charge Special Attack

I think I’m starting to settle on a formalized name, I was tossing around the idea of Castle Kilburn or Escape From Castle Kilburn. However, my gut tells me to go with the shorter name. Either way I’ve tried to refocus my development efforts into core mechanics that push me closer to a playable state.

I think its really important right now to get to a playable state to avoid project burnout, the things I’m working on are very time consuming and as a solo dev I could easily get bogged down or lose interest. So this is the list I’ve implemented and its helped keep my work focused on the ever important “playable state” goal.

I’m happy with my procedural generation at this point and I created a new Tile class that keeps track of various parameters such as movement cost, current occupant, tile type. This has formalized movement and allowed me to work on special abilities as shown above.

I revamped the scene loading mechanism, I’ve opted to not allow the player to return to a previous level once going down the stairs. This has allowed me to keep the number of scenes to a minimum of three right now:

Menu,Dungeon,Shop. I use a modulus operator to check the scene at load time, if modulus 3 == 0, then we load a shop level. So basically the player gets the opportunity to shop every three levels. This may get tweaked once combat is done and more testing is performed.

I’ve revamped the shop graphics to match what is shown throughout the dungeon, I do have plans to implement more dungeon graphics as the player continues through the levels. I will need a backstory as to why this shop keeper is here and why we’re escaping a castle dungeon by going down… or maybe we just change the stairs to go up, unsure yet on this one.

Anyway, hope you enjoyed this brief update and the small window into my development process. Lots more to come, but I gotta get back to work.

Cheers,

Corey

Kilburn – Roguelike – Update

One of my favorite game developer conference (GDC) talks is the Diablo postmortem by David Brevik. He details the nitty gritty of game design and development and show cases his original game design document (GDD) he was working on while in high school. I’ve always aspired to learn from the great developers that blazed the trails before me and I’ve been wracking my brain trying to come up with a name for the roguelike game I’ve been working on. David got the name Diablo from the mountain near his California home Mt. Diablo. So to google maps I went and I’ll be naming my future roguelike Kilburn, its a mountain that’s near my home.

Cheers David

Devlog Update

So feature development has been slow, I’ve spent the last two weeks rewriting my procedural map generation, redoing my artwork for my dungeon generator and integrating this work into the project. When I started this rewrite I wanted to do it outside of my active project so I was free of any other code that was running. I wanted to nail down the basics of procedural prefab room generation. I also wanted to publish this procedural generation so other developers could use it.

So, I released a basic version of my code under the MIT license, you can get a copy of it here:

https://github.com/Diaonic/ProceduralMapGen

Here’s what a generated map looks like in Kilburn
Here is a first look at the wall and floor tile set.

That’s all for now, as I continue to work on AI, combat, and work towards a playable build. We’ll be posting more updates.

Cheers

Corey

Unity Procedural Level Generation

I was unhappy with the assets and approaches I was finding for Unity procedural level generation. I had read about some developers taking prefab rooms and generating maps, but I couldn’t find any examples. However, I didn’t want the Binding of Isaac or Zelda dungeon feel. I wanted to be able t customize rooms, then generate a dungeon based on thematic prefab rooms.

Here’s the result

So whats going on here?

We’ll step through some pseudo code.

SpawnStartingRoom()

Spawn a 4-connection point room at a random x, y coordinate on our map array.

  • Store those 4 connection transforms in a list.
    • I also stored the connection transforms as keys to a dictionary of gameObjects, this way when I pulled a random transform, I look it up in the dictionary, get the gameObject.
    • Set all four of these connection points as available for connection, I just used a bool value on the prefab object to keep track of this.

SpawnPrefab()

  • Grab a random key from our available connection list
    • Grab the associated gameobject using the transform as a key for our dictionary of gameObjects
    • Using overlap collider, I check if there is an object present at my random key
      • Iterate over the bool values and find a connection point
      • Instantiate our prefab at the destination transform and apply an offset, so it lines up nicely with the existing gameObject
      • Set some connection flags
      • Rinse -> Repeat

Once we reach the number of rooms we want to spawn. We then initiate a cleanup phase.

CapDeadEnds()

  • This method iterates over all the spawned hallways.
  • It evaluates if the hallway has an open connection.
  • If we find an open connection, we attempt to spawn a large 8×8 endcap, if that fails, we spawn a 4×4 endcap, if that fails, we use a 2×2 endcap.

I ran into some issues here with detecting overlap and it resulted in a better generator in my opinion. So, the prefabs were built on entirely the same layer. So, I added another layer just for the floor, now when I get weird overlapping issues, its cutting into wall space and creating some interesting room configurations.

  • The intersected wall objects are removed.

I know this post probably isn’t for everybody, but I wanted to show some of my work and my nontraditional way of tacking level generation. I could probably add some more cleanup to remove oddities such as low value tiles spread throughout the center of the map. This is a good base I believe.

Portfolio Project: Update 1 – Simple FTP

Quick update to my portfolio projects, I’ve been working on a simple ftp client. Progress has been moving along, I’m able to connect, and query a list of files. I’ve been working on building out a file object data type, and displaying files within a text window by using string tools.

If the file names are exceeding 25 characters I’m doing some truncating using a sub-string to keep the padding and adjustment correct as shown in the remote file system view below. This allows file names upwards of 255 characters. However, the user can still decipher what file they’ve uploaded via extension and last few characters. I thought this was an import feature as many people use filename1, filename2 to increment version changes.

My todo list for this:

  • Local file system selection
  • Upload feature
  • Salt the password field
  • Implement the port field
  • Disconnect button

Again this isn’t intended to be a full fledged FTP client, my goal is to highlight the core features and show that I can take a web response and make a meaningful WPF application.

Happy Coding

Corey

Python Update

Its been awhile since I’ve done an update. I’ve gotten swamped with work, and a side project as of lately and haven’t had the time to post as much as I’d like. Anyway thought I’d share what I’ve been working on.

I’ve been learning MicroPython with a pycom board. The board will control a series of hardware components, lights, speakers, door lock and so on. The core component I’m working through now is remotely updating the pycom boards if we had hundreds of these out in the field. I can’t share the intimate details of the project as of yet.

A few terms ago I took a CS course that utilized python 3 and I enjoyed the little bit of the language I was able to learn. The indentation rules are a real killer if you’ve been coding in C/C# or any other C variant. Compiler errors when your if statements are out of wack can be incredibly frustrating. So, I’m looking at this as a learning tool to write better code thats cleaner and utilizes this strict type language. MicroPython has a nice structure, gives you a boot.py, main.py, and a lib folder to hold any libraries you need to import or create. Feels like a very easy way to get started with micro controller programming. Certainly much easier than the old arduino stuff I use to mess around with.

Anyway, if you’re doing a project with pycom or any microcontroller leave a comment below and let me know!

Happy Coding!

Corey