Hexbreaker: Randomization and Replayability
Salutations, all. My name is Dylan, and I am one of the two programmers working on our game: Hexbreaker. Today, I will be sharing some of the programming going on behind-the-scenes for the randomized elements of Hexbreaker. I will try my best to explain all of the programming examples I give for those of you that are not versed in C#, so hopefully it'll be perfectly understandable to anyone!
Why Randomize?
The easiest reason to give for randomization in games is replayability! Replayability allows players to have a different experience with the game each time they play through the game. Since Hexbreaker is a Roguelite, the randomization is even more of a major key factor in the game than in many other genres. To explain a Roguelite, it is a game genre where the player must make it through a gauntlet of encounters with a set amount of HP, but the player generally gains some form of improvement during the runs after each encounter that is lost upon failing the gauntlet run or succeeding. After a gauntlet run's success, the player will then be sent back to the start of the game, usually due to some narrative trope.
Talisman Type Randomization
In Roguelites, there is almost always some kind of power-up that the player gains for completing an encounter. In Hexbreaker, these are called Talismans. From increasing your max health, defense, attack or granting a whole new aspect of combat, talismans have a wide variety of possibilities. How do I randomize, you might ask? Well, in C# at least, it's usually rather simple. Take a look at the code snippet below:
I will focus more on the line of code at the top in a moment. First, take a look at the second line of code. Using a built in feature of C#, I can generate a random whole number between 0 and 75. In C#, the upper bound of the random range must be one whole number higher than what you want the highest possible value to be, so I had to set it to 76 to make it a range of 0 to 75. This line of code generates the random number that we will use to decide what type of talisman is given to the player here.
The next line of code, which contains an "if" statement reads like this: If the talismanType is less than or equal to 35, then create a health talisman. So, if our randomized number from above was any number less than or equal to 35, the code would offer the player a health talisman. Health talismans restore a specific amount of health for the player when chosen.
The line of code after that contains another "if" statement. This one reads a little bit differently: If the talismanType is greater than 35 AND the talismanType is less than or equal to 55, then create an extending talisman. This has to check for two conditions on the random value at the same time, so I must use "&&" which simply means "and." Extending talismans extend the player's maximum health pool.
The next line of code is similar to the previous one, but it generates a max health talisman instead. In-game, these are called Surgical Talismans, they both increase the player's max health and decrease the player's current health.
The final line would create a defense talisman, but those are not yet implemented. Therefore, my random range here doesn't allow itself to reach a value that would generate a defense talisman.
And there you have it. The talisman type is now randomized, and the player will have a different selection of talismans each time they complete an encounter. Ah, but that just isn't enough replayability for my liking. So, we must continue!
Talisman Rarity Randomization
I'm a sucker for rare things in games. Getting a rare item in an RPG is a feeling like no other I've known. So, I'd be remiss in my duties as programmer if I didn't incorporate rarities, now wouldn't I? If a healing talisman in the game heals for a set amount, let's say 5 in this case, implementing rarities would be simple. A common healing talisman would just heal for the default amount of 5. But an uncommon one would heal for 10, a rare for 15, a legendary for 20 and a spectral for 25. Since Hexbreaker is narratively focused on curses and ethereal things, I named the highest rarity of talismans "Spectral." Take a look at the code snippet below:
Refer back to the previous snippet and recall the first line of code there. That line of code calls a function named "DecideTalismanRarity," and that is what this block of code here is. To randomize the talisman rarity, we once again use a random range, but use 1 to 101 this time since I already know all the rarities that exist. Now, here is the code snippet that actually decides the rarity:
This one may look a little bit daunting, but it is very similar to the one I just went over. It uses if statements to figure out what number the random range has determined, and from there it instantiates--or creates--a talisman, which I call a "frame." The first line within each of the if and else if statements here shows the rarity. Look for where it says "commonFrame," "uncommonFrame," "rareFrame," "legendaryFrame" and "spectralFrame." The other parts of those lines of code are telling the script where to place the talisman so that the player can see it and choose it. We wouldn't want it appearing out of sight, that'd be disastrous!
So, there it is. Now we have randomized talisman types and we have randomized talisman rarities. Now the player will have a very different experience with their runs of the game's gauntlet based on their luck and their ambition!
Replayability Maximization
Now that you know how to randomize things and why you should, I'll speak for just a moment about the most important thing to randomize in a Roguelite: the gauntlet itself. A player can choose the same path all they want and get randomized upgrades all they like, but that alone does not make the experience all that different. To have a massively replayable experience... you need to randomize the very game itself. In Hexbreaker, there is an overworld map, made of a set amount of encounters and then a boss. After each encounter aside from the boss, the player can choose to travel to one of two adjacent and forward-facing encounters. So, to add the largest level of replayability that I can, I must randomize these encounters every time the player starts a new run of the gauntlet. What will the player encounter? Combat? A healing fountain? A lucky chamber filled with riches? Nobody can quite say, because you'll have to play it again to find out!
Here ends the discussion on Hexbreaker's randomization and replayability. I hope you enjoyed and understood some of the chaos that programming may seem to be. See you next time!
-Dylan
Get Hexbreaker
Hexbreaker
Death is not the end in this realm, merely a setback in your efforts.
Status | Released |
Authors | cfringerwtcc, dmgrummerwtcc, Arissa Guard, ddsanchezWT, Jacksonmgb |
Genre | Action |
Tags | 3D, paranormal, Roguelite, Singleplayer, Turn-Based Combat |
More posts
- Hexbreaker: Pen & Paper PrototypingJul 24, 2023
- Hexbreaker: Skyboxes for UnityJul 18, 2023
- Hexbreaker: Feature UpdatesJul 11, 2023
- Hexbreaker: Expanding Character with ParticlesJul 04, 2023
- Hexbreaker: Button Sprite SwapsJul 03, 2023
- Hexbreaker: Character DesignJun 27, 2023
- Hexbreaker: How to create foliage!Jun 12, 2023
- Quick-Time Events: Why and How ToJun 05, 2023
- Hexbreaker: The First DevlogMay 30, 2023
Leave a comment
Log in with itch.io to leave a comment.