Last three weeks

Here I am, the final three weeks until I graduate with my computer science degree. It’s been an interesting 3 and 1/2 years. Online learning was an obviously choice for me as I’m a full-time dad, husband, and IT professional. When I enrolled into my degree program it was an uncomfortable decision, it had been 15 years since I had been in school, and my first post-secondary experience. However, uncomfortable was the feeling I was after. I needed to make a change to pursue the work I wanted to do. Programming.

When I started my degree, I was a seasoned IT veteran of 15 years; I had seen many different industries, and worked many different problems ranging from programming, security, networking, and customer support. Yet, I had never attended college and had to wade through the IT-101 type classes which covered topics such as, what’s a hard drive? how does a CPU work? While this was painful at times, it allowed me to reflect upon my on the job training, and I had a better understanding of what I’ve accomplished in a non-traditional way. I attempted to look at each of these classes as an opportunity to share industry experience with my peers and reinforce any areas or gaps in my knowledge.

Some of the classes I dreaded taking, ended up being some of the most enjoyable for me. I’ve never been extremely strong with math, although Discrete Mathematics was one of my favorite courses, and it really challenged me. When I reflect upon why this math class resonated with me, I think it relates to how easy the formula’s and techniques can be mapped to computer science implementation.

Other areas of study helped round of my education, such as English, Psychology, and History. While I wasn’t thrilled about taking these, I understood their importance and haven seen a significant improvement in my writing and general aptitude towards their content. Again, I tried to find relatable learning experiences with my passion for game development. Studying psychology allowed me to better understand what drives behavioral decisions and how habits are formed. These are all relevant if you’re trying to build an immersive and replayable game I told myself.

In conclusion I’m a firm believer that the SNHU online degree program is a positive one. However, you get what you put into it. If you’re not reading the weekly material, have late assignments, or are not understanding the work. You must reach out for help; you need to be self-motivated and understand what your end goal is. You’re learning how to learn; the course content can is sometimes be irrelevant.

I feel there are huge gaps within the Computer Science degree program. The program has you jumping around between several different languages and wastes significant time learning about basic CS skills such as looping, iteration, and conditionals across all these languages. It should focus in on one language and take students to a much higher advanced aptitude. One area employers are looking for is knowledge of design patterns. This topic was never covered and it’s a shame. Design patterns are the building blocks of functional code, you’re learning from the mistakes that others have already performed and are given a recipe for how to implement it correctly.

Would I recommend this degree program? Well that depends, if you’re not just graduating high school, and have limited time. You have good time management, are self-motivated, and have a general interest in learning, then go get that degree.

If you’re just graduating high school and you don’t know what you want to do. Spend the extra money and go to a campus, you’ll form lifelong friendships. You’ll have improved social interactions, if you’re struggling you can go to the office hours of the professor, you can lean on your peers for support. These features and support systems are lacking within an online school, they try to compensate but its just not the same.

Happy Learning

Corey

 

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.

Unity 2D Fog of War

When I started down my journey of making a roguelike in Unity I knew fog of war was a feature I wanted. I’ve always liked the ambiance of the unknown, going back to when Diablo was released. The exploration the player has to do and the unknown of what they’ll uncover I feel adds a lot of value to the game.

So I implemented this feature three times and I wasn’t really happy with it until now. I’ll explain the ways it was implemented and why I think the last version is ideal (at least for my project).

My ideal fog of war implementation looks like this:

Full transparency in the spaces adjacent to the player, and 50% transparency to the outer edges. This gives the illusion of what the player can see near them and what they can barely see; and then obviously the unknown. My game is using procedural dungeon generation as with most roguelikes. If you’re unfamiliar with this type of implementation, the dungeon regenerates itself on each play through or level change. This minimizes the amount of level design needed.

Here’s a sample of my level being generated.

So applying a fog of war implementation on this map can get tricky as you have individual tile locations on a X,Y Cartesian grid.

Attempt Number 1 (holy fuck was this idea stupid)

I think Benjamin Franklin had a quote about failing and learning, that’s how I felt about this process. I now know how NOT to implement fog of war.

So I have my grid of tiles after dungeon generation has happened, I had the brilliant idea that I would just Instantiate a new tile above all the existing tiles and set it color to black. Then I would use a circle collider on the player and when the collider had a resulting collision with one of these black tiles, it would set their transparency value to either full or half depending on distance from the player transform.

The implementation worked…kind of.

While I was pleased to see my handy code craftsmanship work right off the bat. I soon realized what I had done. I had effectively doubled my tile count, put colliders on all those objects. My FPS in debug mode dropped nearly 60%.

Here’s a brief video of it in action.

While it seems playable at first, you have to understand I have no sounds, very few enemies and AI implemented, no collectibles. It’s a shell of a game at this point and losing 60% of my frames was alarming to say the least.

Attempt 2: (Slightly better)

On my second attempt I took a large black sprite and covered the entire area where the map could spawn. I then used a sprite mask on an image the same shape that was desired and with some fiddling with culling settings and mask interactions I was able to achieve the same result as the video above. However, I didn’t get a 60% drop in frames. Infact, it hardly had any impact. I still wasn’t happy with the result, I wanted the areas the player had visited to be 50% transparent after they left. The player would know where they had visited and I could avoid a mini-map implementation

Attempt 3: (my implementation)

After eight hours of sleep and a hearty breakfast I got to work on another implementation. I’ll preface this by saying, sometimes you just need to walk away from your code. Its not until you give your brain a break that you can fully realize potential mistakes and come through with a solution.

It dawned on me that I’m already using sprite renderers on all my tiles. This means I could set this color and transparency without instantiating any other objects.

So on my dungeon generation class I have this code:

// Sets a member variable color to black
private Color DarkTileColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
//After each Instantiation of a tile I call this
created_tile.GetComponent<SpriteRenderer>().color = DarkTileColor;

So now I have a map of tiles that is entirely black

So this is where the magic comes in. I use a Unity physics2D object called “CircleCastAll”. This object returns all colliders it comes in contact with for a specified radius and distance around an origin point. What this means is, I put a circle around my player and anything the circle touches, it tells me about.

public class CheckFog : MonoBehaviour
{
    RaycastHit2D[] hit;
    int frames = 0;
    void FixedUpdate()
    {
        frames++;
        if (frames == 4)
        {
            frames = 0;


            hit = Physics2D.CircleCastAll(transform.position, 2f, new Vector2(0, 0), 3f);

            foreach (var item in hit)
            {
                Vector3 dis = transform.position - item.collider.transform.position;
                if (dis.x == 2 || dis.x == -2 || dis.y == 2 || dis.y == -2)
                {
                    item.collider.transform.gameObject.GetComponent<SpriteRenderer>().color = new Color(.5f, .5f, .5f, 1.0f);
                }
                else
                {
                    item.collider.transform.gameObject.GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 1.0f);

                }
            }
        }
    }
}

So after I get an array of colliders. I iterate over them with a foreach loop and then I check the distance from my player to the collider and if the x or y value meets the criteria of 2 or -2, it tells me its an outer tile and we’ll set the transparency to half. Otherwise we’ll set the transparency to full as the other tiles left are the ones adjacent to me. This implementation also has the added benefit of adding a mask to monsters and it gives a nice silouhette effect when the monster is “out of range”. Here’s what it looks like:

In the code above I’m also only checking colliders every fourth frame. Checking every frame in a turn based game seemed like a waste of resources and I could barely tell a difference.

Happy coding

-Diaonic

Roguelike – [Insert Name here]

Its been awhile since I posted an update. I took some time off from personal projects and have been focused in on finishing my CS degree with 4 classes left. The past two weeks I’ve found time to get back into my passion ( game development) and I’ve started working on a roguelike that is lacking a proper name.

So when I set out to build this, I wanted to keep my eye on the prize and get a prototype up and running as quickly as possible. This way I had something playable and could then iterate over game features, tuning, and polish. So without further ado here is a short tech demo. Things I’ve got completed:

  • Procedural Map Generation
  • A* Pathfinding
  • Player Movement & AI movement
  • A combat system based on 1d100 roll under

More updates to come, but the project is coming along nicely.

Cheers,

Corey

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