Showing posts with label level up. Show all posts
Showing posts with label level up. Show all posts

Monday, May 1, 2023

Character Building 101: How to Build a Level Up System in Stencyl

What is Character Building?


Character building is the backbone of every great RPG game ever made.It's not only for RPG's, though. Over the past decade we are seeing more and more games of different genre's dip into the realm of character building. Even first person shooters are beginning to adopt character building principles (think Borderlands).

To be concise, when I say character building, I mean that the particular game in question has a built in system where your character accumulates experience. That experience usually translates into higher attack power, higher defense, new magical abilities etc. This style of character building is more commonly known as role playing (RPG  - role playing game).

Another type of character building would be acquiring experience in one form or another, and then using that to purchase upgraded abilities (Dante's Inferno).  We will cover building a skill tree of that nature in another tutorial here in a few days.

Today, we are going to go in depth on the first idea I stated, a classic RPG style level up system. The system is pretty simple overall. We are basically going to create a character behavior to attach to our main actor, or playable character. This behavior will watch for one variable ($experience) to become greater than, or equal to, another variable ($NextLevel). Once the experience surpasses the quota for the next level, it will increment our level up one. It will then increment all of our other character attributes, like attack, defense, and max health. Once all of our character specs have been incremented, it will create a new $NextLevel value, so that the behavior can once again begin to watch for a new level up instance.

The Difference Between Getters/Setters and Game Attributes


Before we get started putting our blocks together, we need to discuss the difference between getter/setters, and game attributes. Getters and setters in stencyl are the equivalent of a variable with local scope in an actual programming language. For those of you who know a bit of programming, you already know where this is heading. For those that don't know, a variable with local scope will only function within the confines of where it's created. Sometimes this means one page of a website, or it could mean one particular function of a whole program. These types of variables are used for things that we don't need to pass on to the rest of the program.

A good example of when to use local scope in a game would be the boss battles in the old Mario games. Instead of coding a health bar and doing math to take damage, in a game like this, you could create a code block that checked how many times the boss has been hit, every time he gets hit. The code block increments the HitCount by 1. It then checks to see if the HitCount is greater than, or equal to, three. If this is the case, Bowser dies (sorry Bowser). All of this would be done locally as we don't need it to carry on to any other part of the game.
An example of how to increment damage for simpler games.

When coding a level up system, we have no use for local scope variables. They won't do us any good if they can't follow us around for the entirety of the game, no matter where the game takes us. But don't you worry your pretty little head. Like a good neighbor... global scope is there!

That's right. With a global scope, a variable and it's contents and be manipulated and called on from anywhere in the game. The stencyl equivalent of global scope is Game Attributes. To access these, while in the coding screen, click on the attribute category of blocks, and then in the sub-categories click on Game Attributes.

If we create all of our characters statistics with game attributes, we are now able to create a very simple code block that allows the game to constantly check to see if our experience is sufficient to level up. If we have enough experience to do so, that same code block will increment all of our character traits, increment the amount of experience needed to level up again, and then just for fun, it will also refill our health and energy meters to our new max health and max energy levels.



Implementation


Code blocks depicting how to create a level up system in stencyl.Now we have our very basic level up system. Our game now knows that once we accrue a certain amount of experience, to let us know that we are a little bit smarter than we were a few seconds ago (and stronger, too). Now, how do we start collecting all that experience?:Easy...peasy...Mrs. pacmans sleazy.

All we need to do is add a little bit of code to all of our enemies to define the amount of experience that they will give us if we completely and utterly destroy them (isn't that nice of them to do that?). Simply create another game attribute with a unique name, that can easily be identified as being the experience given for killing this particular enemy.


An example of how to retrieve experience from enemies in stencyl





Optionally, if you were building a much larger game where you may face the same enemies down the road, but they will be much stronger, you could increment the experience similarly to how I did in our level up blocks. You could also use this method to increment the traits of the enemy it's self, instead of creating a whole new actor with the same graphics.





What's Next?


My next few tutorials are going to walk you through the advanced mechanics of character building. Here are just a few of the topics that we are going to discuss:

  1. HUD's, or Heads Up Displays. I am going to show you how to implement health bars, energy bars, magic bars, etc.
  2.  I am going to get a little more in depth with the math behind  this level up system.
  3. Leveling up for RPG style games where you control more than one character, I.E. leveling up several playable characters separately (Final Fantasy Series).
  4. Skill Tree's ( I told ya so)
  5. Status Effects (poison, sleep, etc.)
  6. Stat boosting based on equipped items (think Diablo).
  7. Xbox style achievements
  8. And a whole lot more...

Saturday, April 29, 2023

Character Building 101: Calculating Damage and Other Character Specs

So your characters learned to level up? Whoopty doo.


If you followed the previous tutorial then you now have a nice, basic, level up system for your game. Last time we learned how to eliminate the enemy and gain a little bit of experience in the process. That experience then accumulates and eventually causes our character to level up, which in turn alters our characters attributes slightly. If you haven't read the previous article yet, you can find it here.

Now that our characters level up from the experience that they collect, we need to develop a system for letting our increased strength and knowledge show. We need to create a math based system that allows our specs to reflect their increased value on their own. Today we are going to learn a very basic version of this just so that you can see how it works. I will probably post more on this at a later date showing a few more complicated ways to create a more in depth system. But for now, let's keep it basic.

Let's Get Started

To first get a firm understanding on what we are doing here, we are going to just focus on one part of the whole system. This will allow us to grasp what's happening and why, and then we can apply this same thing to all of the other aspects of the system with little twists if needed. The part we are going to focus on first is a very basic algorithm for calculating damage. When I say very basic, I do mean very basic. 

The general concept of what we are going to do is take our characters attack, add it to our weapons attack strength, and then subtract our enemies defense (like I said, very basic). The output of this function will be the amount of HP that it takes from our enemy. 
How to calculate damage to a character in stencyl

I kept it very simple with this example for the sake of understanding. Our attack is 5. Our weapon attack is 7.

5 + 7 = 12

Our enemies defense is 5. 

12 - 5 = 7 

The damage that we inflict is 7.

Again, this is a very basic way of doing things. For a lot of games, this would work. You wouldn't need to do much else. If your doing any kind of platform game or small scale rpg, this system would work well. If your creating a game that could compete with the Final Fantasy series, you would probably want a more complex and thorough system, which would involve incorporating several different factors into the calculation of the damage done. This usually involves things like strength, dexterity, agility and several others. I will cover all of these things and the math involved in the advanced mechanics part of this series. But for now, let's run with this.

Applying this to the Rest of our System

Once you've learned how to calculate damage done by an attack, all of the other specs of our characters will be easy to work with. To calculate the damage done to us, we would apply this same method, but opposite. We would add the enemies attack to his weapon attack if he's using one, and then subtract our defense. That would then take away from our HP.

You can calculate magic damage and things of that nature with the same method described previously. If you are looking to add elemental damage, status effects, and things like immunity and weaknesses, I will be posting another stencyl tutorial soon specifically about those topics.


What's Next?

Within the next two or three days I will be posting an in depth stencyl tutorial on skill trees. It will describe full implementation of skill trees, how to make them effect your characters stats, how to add new skills and magic to your character, and even how to apply a system of collecting points and how to spend them on your skill tree.