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.

Introduction to Power Ups - How to boost your characters

Recently I stumbled across a question on quora.com about how to accelerate your character speed without having to write extra blocks of code to figure out exactly what direction the character is traveling.

How do I increase the acceleration of an actor in stencyl without having to know a direction?

This immediately triggered a response in my mind. It made me realize that a lot of people who are using stencyl haven't fully grasped the whole picture of what a simple variable can do! So, today, I am going to show you how you can use a couple of game variables so that your speed automatically adjusts it's self when you hit a power up in a scene.

The process of doing this is relatively simple.

1. Create your variables

You will need 6 total for this example. You will need:

  • One that contains the normal movement speed
  • One that contains the normal movement speed as a negative
  • One that contains the boosted movement speed
  • One that contains the boosted movement speed as a negative
  • One that is empty that can contain either of the positive speeds
  • One that is empty that can contain either of the negative speeds
  • A boolean variable (true or false switch) that we can use to trigger the power up
2. Create a block of code similar to these in your main characters behavior. Note that you will have to recreate this for every movement direction.
A Stencyl block showing how to form the Up button movement
A Stencyl block showing how to form the right button movement






3. Add another block to your character that looks like this.
A Stencyl block that shows how to adjust the movement speed of your character
What this block does is determine if the boolean variable $speedboost has been switched to true. If the variable becomes true, it changes the $speed variable for normal to godspeed. In this block I kept the normal movement speed at 10, and the boosted speed at 20. So when you run over the power up it doubles your movement speed. The "do after" block at the end makes it so that after ten seconds all of the movement speeds revert back to normal speed. Pretty clever!

4. Create a character that will be your power up item. 


Edit it's behavior to include a block like this:
(Note: Ignore the red flags in this block. Stencyl threw those up because I didn't add animations to this actor before creating the behaviors.)

Stencyl block that shows how to trigger the movement speed change when I power up is collided with

You may also want to add something to that block that kills the actor and removes it from the screen. I had planned to do that for this example but it slipped my mind. If anyone is unsure how to do that, just let me know in the comments and I'll cover it in another post.

That's all you need to do to change your movement speed without first calculating directions. Play around with those blocks and see what other kinds of cool things you can achieve with this principle. 

If this blog helps you out, or you just enjoy reading it, consider subscribing to my feed burner so you get immediate updates when this blog is updated. I am always looking for suggestions on what to post next that will everyone will get the most value from, so if there is anything in particular that you would like to me to explain, please let me know in the comments and I'll cover it. Thanks for reading!

Friday, April 28, 2023

How to create and use global variables in Stencyl

Variables are a very powerful thing. They are what give a programming language it's overall flexibility. Without variables, programming languages wouldn't know what to do with themselves, LITERALLY.

What is a variable?

A variable is basically a container. It can contain just about anything. It can hold numbers, strings, etc. Then you have things like boolean variables, which are true and false switches.

What can you do with a variable?

You can do a lot with variables. In stencyl specifically, you can use them to store values that get passed around from behavior to behavior. In my last post, I showed how you could create a basic power up that boosted the players movement speed for 10 seconds. We achieved this by passing values back and forth in the form of variables.

You could also use variables to create a level up system for you characters. In fact, you couldn't achieve something like that without variables.

The list is endless.

Understanding variable scope

Depending on what programming language you are using, there are several different scopes to consider. In stencyl, we only need to be concerned with two - Local and Global.

A local variable is something that usually only affects one small part of the script. For us, that could be one actor. If you create a local variable inside of an actor behavior, it can only affect that actor. In fact, in the stencyl program, you wouldn't even be able to access that variable outside of that actors behavior editor.

A Global variable is a variable that we can create that we can apply to several aspects of the game. We can take that variable and apply it to any number of characters or scenes in our game.

How do I create global variables?

In Stencyl, global variables are referred to as Game Attributes. To create them, click on the Game Attributes tab, then click the grey button that says "create new game attribute".

A display of all of the block categories in windows with the game attributes selection highlighted

Stencyl Game Attributes Menu with Create New Game Attribute highlighted





Now, you should see this pop up window:

new attribute pop up window with attribute type selection bar highlighted


As you can see, there are a handful of options here to choose from. Take your time naming variables. I can't even express to you how many times I have forgotten what a variables intended use was. Make sure that you name yours something that you will remember what they are used for!

The next thing to do is to be sure that you click the right button based on what you intend for your variable to contain. If it is meant to hold a number value, then make sure that you click number. If it is meant to hold your characters name, then make sure that you click text. You get the point.

How to use Game Attributes

Now, that you know how to create a Game Attribute, I'll give you a quick guide on how to use them. I will also expand on this in the next couple of lessons.

This is the block that I used in my last post. It shows how you can use a boolean game attribute as a trigger. In this example the trigger was pulled when the player ran over a power up. Once it was triggered it doubled the players movement speed for 10 seconds.

code block showing how to use stencyl game attributesNow you know how to create and use game attributes. In the next couple of lessons, I will show you more advanced ways to use these variables to create more flexible games. I'll see you in the next post!

If you find these Stencul tutorials helpful then please feel free to subscribe to my feed burner. If you have a lesson that you would like me to create then please let me know in the comments.

Wednesday, April 26, 2023

5 Places to get FREE Music for your Game

Note: Please read my other article: "How to get FREE Music for your Game" if you haven't already. It explains everything you need to know about the different types of licensing that these audio sites use.


The audio in your game is very important. It sets the tone for the entire game. Unless you are part of a major development studio, acquiring quality audio assets without breaking the bank can be a real challenge. Here I am giving you a short list of 5 places to get free music for your game.

1. Free Music Archive
Free Music Archive is a great place to find creative commons licensed music. They have a huge selection of audio, spanning every genre you could possibly imagine. If you can't find good tracks on FMA then you must be a damn caveman. Another bonus to this site is their licensing cheat sheet that shows you exactly what is important to you for every license type.

2. Jamendo
Although Jamendo is set up like more of an end-user service, you can still find tons of great assets on this site. Like FMA, there are tons of genres, and artists to coose from. It may take a little digging, but you are guaranteed to find something suited to your project here.
3. Magnatune

Magnatune is one that I personally use, from time to time, when I'm not writing about video game design. The selection isn't quite as extensive as some of the others, but they do have great content. I've used several tracks from here for various Youtube projects with great success.

4. Audiofarm
Audiofarm pulls artists and tracks that are offered under creative commons licenses right from Soundcloud and presents them in a clean and common sense way. I've never used Audiofarm personally, but after researching them for this article, I think I will be using them for some upcoming projects.

5. Opsound
Of all the sites listed, Opsound is one of the easier to navigate. It has a nice, clean,  minimalist design that allows you to browse their content quite efficiently. The same can be said about this site, as all the others. Great artists, great audio, and overall great selection.

I hope this was helpful to all of you reading it. If you use any of these 5 places to get free music for your game, please let me know in the comments.

Tuesday, April 25, 2023

How to get FREE Music for Your Game

Music and sound effects are arguably one of the most important assets for your game. Whether your game is on a console and blaring through surround sound, or it's playing through ear buds on an android device, the audio of your game is crucial to the overall experience. Without great audio, the overall appeal of your game could drop off dramatically.

The music in your game should create some kind of emotional response in the brain of the end user. Heavier songs are often used for boss battles because they intensify the scene and often times create a sense of urgency. Softer, more melodic tunes are used when a beloved character in your story line has died or been critically injured. Casual soundscapes create an ambient atmosphere when navigating menus and skill trees. All of these things are absolutely essential to creating the exact kind of experience that all serious developers strive for.

All of the same can be said for sound effects. Have you ever been playing a first person shooter when suddenly several loud shots come smashing through your headphones? Instant adrenaline rush. The loud clink of swords clashing make you feel like you are swinging it yourself. Even the little clicks and beeps of menu buttons are essential to building the perfect look and feel. If the sound isn't right, the game isn't either.

One of the challenges for new independant game developers is acquiring adaquate game adsets. In game development obe usually has some kind of background in either programming, graphic design, sound engineering, or story writing. It's very rare that one gets in to game development and is already proficient in all four of those fields. If you are a programmer it can be especially difficult to get your hands on qualty sounds and graphics. Luckily, there are options out there that you can take advantave of.

Before we jump into the list of valuable sources that I have for you we should discuss the different types of copyright licensing that we will potentially be working with.

1. Public Domain

Public Domain is a way of saying that some piece of work doesn't have an outright owner. Most often this happens when someone doesn't file a copyright claim on their work, or they fail to maintain those copyrights. If no one owns the rights to any particular piece of work, it is considered to be the property of the general public. If something resides in the public domain then it can be used, shared, and even sold, by ANYONE. If you go this route, you have to be 100 percent certain that the work you are using is actually in the Public Domain.

2. Creative Commons

Creative commons is similar to Public Domain in the sense that it can be shared freely, and even used commercially. Where these two differ is in that someone does own the rights to that work and are allowing the public to use it royalty free under creative commons licensing. The biggest things to remember with creative commons licensing is that you are not allowed to change the work in any way and you absolutely have to give proper credit to the original author.

The idea here is to find quality music and soumds that fit your project that are either Public Domain or Creative Commons. Either one of the two can be a viable option, so long as you are using them the right way.

Now lets move on to the list of resources: