Dan Kenny Game Design
  • Home
  • Portfolio
    • Game Design
    • 2D & Animation
  • Blog
  • About Me
  • Contact
  • Home
  • Portfolio
    • Game Design
    • 2D & Animation
  • Blog
  • About Me
  • Contact

C# Beginners Tutorial: If Statements

31/3/2018

Comments

 
Hey there, Gamers and Game Makers!

Welcome back to the third part of this introduction to C# tutorial series. This week, we're going to be looking at a if statements and how they are used. So let's dive right in!

So, what exactly is an if statement? We can use if statements to check for certain conditions and then run a chunk of code if those conditions are met.
Picture
Let's make a simple example. I've declared a variable of type int called level and given it a value of 11 for now. I'm going to create an if statement that will check the value assigned to level and if the level is a match, it will run the print function that will display the string "Hello" to the console. I create the if statement as follows:

if (level == 12) {
print ("Hello");
}


This if statement checks if the variable level is equal to 12. If it is then it will run the print function. if we  try running it as it is, we'll see nothing displayed to the console as the condition is not met. Let's change the level value to 12 and see what happens.
Picture
Picture
Since the value assigned to the variable level is now 12, the condition of the if statement has been met and it can run the code inside of it which in this case is to print the word Hello to the console. However, it's not very helpful if the player is not the right level as then the condition is not met and nothing is printed. We should do something to tell the player they are not the right level yet. We can add something to help with this.
Picture
Ok,I've introduced two new things to the if statement now. The first thing to notice is I've added an else just below the if statement. This will run anytime the condition of our if statement is not met. In this case we'll use it to tell the player that they are not the right level.

The next thing to note is, I've changed the condition of our if statement. Now instead of the variable level having to be equal to exactly 12, if it is greater than or equal to 12 then the condition is met and the code will run. If I run it as is, the word Hello will be printed to the console again.

Picture
Picture
However, as you can see if I drop the value of the variable level to 10 which is less than 12 and run the script, I'll be given the test "You are not the right level" in the console. This is because 10 is less than 12 so obviously the condition of our if statement is not met and as a result the else section of the statement kicks in. Ok, let's try something else.
Picture
I've added a new string variable called name and given it the value of "Dan". So, if you want to check multiple conditions at once the best way to do this is to use the "and" or "or" operators in your if statement. Let's start with the "or" operator which is represented by ||. Using the || operator means that you can check multiple conditions and the code will run provided at least one of the conditions is met. In this example, both conditions are met and the word "Hello" will be printed to the console.
Picture
Picture
In this example, my level isn't high enough but the string condition is met so the word "Hello" is still printed to the console.
Picture
In this case the level condition is met but the string condition is not met but because at least one of the conditions has been met the word "Hello" will still get printed to the console.
Picture
Picture
In this case, none of the conditions are met so the if statement does not execute its code but the else kicks in to let you know "You shall not pass!" Ok, let's take a look at the "and" operator which is represented simply as two && symbols.
Picture
With &&, the code will only run if both conditions are met. In this case both the level and string condition are met so the word "Hello" will be printed to the console.
Picture
Picture
In this example, the string condition is met but the level condition is not met. Since we are using the && operator, both conditions need to be met in order for the code to run. So the else will kick off in this case.
Picture
Here the level condition is met but the string condition is not met so once again the code will not run and the else will kick in. Have a go at trying your own combinations of if statements and see what you can come up with.

That does it for this week's tutorial. If you have any questions or suggestions, feel free to leave a comment below or get in touch.

Until next time!

Comments

C# Beginners Tutorial: Methods

30/3/2018

Comments

 
Hey there, Gamers and Game Makers!

In part two of this introduction to C#, we're going to take a look at methods. What exactly is a method? A method is code you write that performs a task. We write this code in a way that we can re-use it through out our programming. The idea behind a method is that we can call the method easily and it performs a task without us having to re-write similar code over and over again. Ok, let's get into it!

Picture
I'll be using the same script from the last tutorial on the introduction of variables. If you missed that one,I suggest going back and reading over it before moving on to this.
Picture
Ok, to start off, let's do something very simple. We will create a method that will print a string of text to the console when called. To create a method we first need to declare the method type. For this example lets leave it as a void method as we aren't returning any value. I'm going to call this method "helloWorld" We write it as follows:

void helloWorld() {
}


Notice that the brackets directly after the method name are empty? Remember that a void method does not return anything, so we don't need to provide it with any parameters.
Picture
So, like before in our main body of code, we can do things like print strings. The only difference here is that the string will not be printed unless the method is called. For this simple example I've added:

print ("Hello world! Lovely day isn't it?");
Picture
Now that we have our method, it's time to see how we call it from the main body of our code. As you can see, I've commented out the line from our previous tutorial and added a line that will call my helloWorld method. To call the method, we simply write:

helloWorld();
​
Now, let's try running our script in the unity scene.
Picture
As you can see, the console displays our string. What's happening here is in the main body of code, called our method which then runs the code that is in it. In this case that's a print function that displays the text we now see. This is a very basic example and seems rather pointless in practice. We can make more complex methods that make use of our variables and parameters. Lets do another one!
Picture
Ok, we're going to look at how we can add numbers using a method. For the purpose of this I've declared three new variables. firstNumber, secondNumber and total. All of which are ints. I've initialized firstNumber to 10, secondNumber to 15 and given total an initialized value of 0.
Picture
Now for the method that will actually do the addition for us. I've declared this method as a type int because we'll be returning an integer value from the method. I've called the method addnumbers. Now, because we are going to be passing variable values from our main to this method, that means the method needs to be able to take parameters. So, inside the brackets next to the method name I'm declaring two int variables. These basically act as the placeholders for the variables that will be passed to them.

Now for the calculation part of the method. Since we're going to be adding two numbers, we'll need a variable to store the result of the addition. So, I've simply declared an int variable called totalSum and given it a value of 0. Next we'll do the actual addition by saying totalSum is equaled to num1 + num2. This takes care of the addition but we still need to return the answer so that we can see the result. To do this I simply say, return totalSum; Now the result will be passed back to the main.
Picture
Now, how do we actually make use of this method? Back in the main we call the method in a similar way that we did with the helloWorld method. Except this time we'll be making use of the variables we've declared. If I want the method to calculate the total sum of firstNumber and secondNumber, I have to first say my variable total = addNumber (firstNumber, secondNumber)

As you can see, this time I have to provide parameters to the method. Which in this case is firstnumber and secondNumber. This values will be passed to the method which will add them together and return the value which will be stored in the variable total. To then display the value of the variable total, we simply use a print function but provide the variable total as its argument.
Picture
Picture
As you can see, the value of our result which was calculated by our method is now displayed in the console window. That just about does it for this introduction into methods. You can create all kinds of methods to do just about anything and methods are very important as we can re-use them again and again to save time and make our programs more efficient.

Until next time!

Comments

C# Beginners Tutorial: Variables

19/3/2018

Comments

 
Hey there, Gamers and Game Makers!

In the this week's blog, we are going to take a look at the first in a series of C# tutorials that are aimed at absolute beginners. The first tutorial will look at variables are and how to use them. So, let's dive right in!

We'll be using unity for this series of tutorials. You can grab the latest version from the Unity site here.

Ok, so first off, what exactly is a variable? A variable is essentially something that stores information. A variable has to have a name. This can be anything you want but it is best practice to your variables meaningful names. For example, it would be confusing if you had your variable for health named something like damage. This would cause confusion later when you need to tweak your code. A better name would simply be health.

While we can call a variable anything we want, we do have to specify what type the variable is. In C#, we have variable types such as:
  • int
  • float
  • Bool
  • String

A variable of type int can hold an integer value. This can be a positive or negative value. For example, we could declare an int variable called health for our player as their health can be best represented as an integer value.

A variable of type float can hold a decimal number such as 6.84. These can also be positive or negative values. We can use floats to store more accurate readings for things such as speed, force and other physics related methods in Unity.

A variable of type Bool is used to store a true or false value.. We can use Bools to trigger events in our scenes. For example if you had an area of lava in the game that would kill the player if they were to come in contact with it, you could have a Bool called playerHitLava set to false by default. It could check a collision trigger (don't worry, we'll cover triggers in later tutorials) on the lava that once the player comes in contacts with updates the Bool variable to true. Once that variable is set to true, it could run a sequence of events that would set the players health variable to zero and fade out the camera. 

A variable of type String is used to contain text information. You can put whatever you want in a String but you must use quotation marks. For example, "This is the contents of a String". We use Strings all the time to relay information to a player.

Picture
Ok, let's try making some variables. With your Unity editor open, the first thing you'll want to do is create a new C# script. To do so, right click in the assets window, go to create and then click C# script. This will make a new blank C# script in your current asset folder. You can name this whatever you want. For the purpose of this tutorial, I'm going to call mine, VariableTest. Next, double click on it to open the script in Mono Develop. This is the code editor used by Unity.
Picture
You'll be presented with a window like this. this is the current contents of your script. The code you already see is what unity creates when making the script as it's the required format for C# scripts in the engine. For now, let's not worry too much about the stuff at the top. These are import utilities used by Unity and I'll cover them in a future post. Right now, we're going to look at declaring our variables.
Picture
Ok, so I've created a variable for our players health simply called playerHealth. I did this by first declaring the variables type which in this case is an int. I then gave the variable a name, playerHealth Notice how the name begins with a lower case character but the second word begins with an uppercase character? This is called camel casing and is standard practice when writing variable names in programming. I now need to assign an initial value to the characters health.
Picture
I do this by simply adding an = sign followed by the value I want to assign. In this case, I'm giving the player an initial health value of 100. Make sure you always add a semicolon at the end. That's it. you've now declared your variable type, gave it a name and assigned a value to it. So, as you can see, declaring variables follows a simple pattern of type, name and value.

example: int playerHealth = 100;

Ok, let's declare some more variables and display them.

Picture
Right, so now I've also declared a String variable called playerName and it's value is "Jack". So how would we go about displaying the information from these variables? First off, I now need to explain the next two sections of our scripts code sequence. The first line saying viod start, this is a start function and gets called once at the beginning of our game. I'll go into more detail on functions in a future tutorial.

The section, void Update gets called once every frame. So say for example your game is running at 60 frames per second, then this code is checked 60 times a second.

Picture
So, if we want to display information to the unity console, we can use the print function which is written simply print(); Whatever we put in the brackets is what will be displayed to the console window. For example I could put a string inside the brackets saying "Hello" and it will be printed to the console. Let's try displaying the word Hello in the console. Type print followed by brackets within the curly brackets of the void start function. Once you have done this save the script and go back into the unity editor. In order for our script to work, we first need to assign it to an object. Drag the script onto the main camera. Now run the scene.
Picture
Picture
As you can see, the script is now active at runtime and is printing our Hello string to the console window. 
Picture
We can also print our variables to the console or to be more exact, their values. For example, if I type the health variable name in the brackets of the print function, it will print the value of the variable to the console.
Picture
As you can see the value of the variable playerHealth has been printed to the console window.

Ok, now let's try displaying multiple variable values at once in a meaningful way. How would I get the console to say hello to the player and tell them their current health? We use a method called concatenation. This is where we join multiple things together to display them all at once in the console window. So, as before in the brackets of our print function type a string "Hello " now add a + followed by the playerName variable followed by another + then followed by a string " your health is " followed by another + finally followed by the playerHealth variable. It should look as follows:

print("Hello " + playerName + " your heath is " + playerHealth)
Picture
Picture
As you can see, the console now displays Hello Jack your health is 100. Concatenation is a great way of combining many variables to give us various results in our games. That about does it for this tutorial on variables. We'll dive a bit deeper into what we can do with our code in the next tutorial.

As always, if you have any questions,leave a comment below or feel free to get in touch.

Until next time!

Comments

Making Hide The Body With Subtractive Game Design

14/3/2018

Comments

 
Hey there, Gamers and Game Makers!

Recently I gave a little presentation on making Hide The Body using Subtractive Game Design. So, for this week's blog I've decided to post those slides and talk a bit about them.
Picture
So, why specifically Subtractive Game Design? Well Game Design is such a broad topic, you could spend hours talking about the various aspects of it. I decided to speak about Subtractive Game Design because I most recently applied this design method to my latest game Hide The Body.
Picture
My approach to subtractive game design on Hide The Body started by first applying subtractive design to my game design document. I reduced the document from a large document spanning multiple pages down to a one page design document under the following headings.
  1. Game Overview
  2. Objective
  3. Gameplay and Mechanics
  4. Style
This allowed me to focus on the core design of the overall game.
Picture
So, what exactly is Subtractive Game Design? With subtractive game design, you reduce a project down to its most effective features. This allows the games core gameplay to stand out. By using subtractive game design, we also avoid the risk of feature creep which often is a problem with projects once they have established a core gameplay loop. 

With subtractive game design, the games is built purely around minimal mechanics and systems which as a result allows more time to focus on polishing these systems which should result in far fewer bugs in the game.

A few examples of games who are built around subtractive game design include, Angry Birds, Flappy Bird, Crossy Road and even Minecraft at its core. 

Picture
To better explain the subtractive game design process I took, I'll be using Hide The Body as my main example.
Picture
When starting out with your games design, you'll need to come up with a quick overview of the game. This is so you or people you are describing the game to can quickly understand what the game is about and what it might be like.

For Hide The Body, the game is about covering up the scene of a crime in a very short space of time before the cops bust in and catch you. The game takes its inspiration from Noir crime in terms of its aesthetics.

Picture
Your Objective should be a quick summery of the goals of the game and its structure. In the case of Hide The Body, the goals are:
  1. Hide all incriminating objects
  2. Advance in levels of difficulty
  3. Complete all levels
Picture
When talking about the gameplay and mechanics in your game design document, you want to describe a typical scene from the game and how it should play. Explain the core mechanics of the and the features of the game.

You should have an established core gameplay loop at this point. It's also always very good practice to prototype your ideas as early as possible. They may sound good on paper but you won't know for sure until you prototype a scene to test them.

Picture
As you can see, even though the prototype on the left is a very rough representation of what the game aimed to be, you can still see that even at prototype stage the game had quite a clear vision of how it should be laid out. 
Picture
The design of the win and fail states of the game where simple enough. While the game does not use much text to convey information, it does make use of audio and animation to a great extent to convey the current tone of the game. 

Win State

Picture

Fail State

Picture
Above you can see the win state on the left and the fail state on the right. When the player beats a level the win state is represented by the player character doing a slow motion fist pump into the air along with an audio cue that plays a positive track.

The fail state is represented by the player dropping to their knees crying along with an audio cue that plays a dramatic music clip associated with defeat.

Picture
When talking about the style of the game you'll want to describe the art style as well as the audio sfx and music and how they will be used in the game.

For Hide The Body a low poly art style was used as it allowed for a lighter take on the games dark premise. A more high fidelity realistic style may have made the game more disturbing than fun. Low poly also allows for better optimization of the game too. The B&W color scheme created a more uniform look to the game that prevents the player from being distracted by other colors in the game while searching for objects.

Picture
As you can see, Subtractive Game Design has its pros such as it reduces feature clutter and allows for a more polished game.However, it may not always be suited to your game. If you are working on a larger game that requires many systems beyond just the core gameplay loop, then you have to look beyond Subtractive Game Design and think about Additive Game Design. It all depends on the type of game you want to make.

Until next time!

Comments

Steam: A Week Later

7/3/2018

Comments

 
Hey there, Gamers and Game Makers!

This week, I'm going to be talking about the initial reactions to Hide The Body being a week after release.

Hide The Body has gotten some really good feedback after release and it's really helped to shape some of the updates. There's already been two gameplay updates rolled out that have improved the game as a result of early feedback. The main thing I've noticed since releasing the game on Steam is the huge increase in traffic compared to other marketplaces. Steam has definitely put more eyes on the game than before.

What's very interesting to see is the regions that most enjoy the game. For the first couple of days, China was ranking very high in terms of player base before the USA and Europe caught up in player base. The pros to the Steam release are increased visibility of the game, new fan base and more feedback.

While the Steam release has been mostly good, there are downsides. The increase in emails from scammers asking for free keys is rather annoying and vetting legitimate reviewers from scammers is difficult and tedious. For those who find themselves in a similar situation, make sure you verify the source who is asking for keys. If it's a Youtuber, check that the email they used to contact you is the same that is linked to their channel. You could also ask them to verify this request by contacting you via a DM through Twitter using their official account. Most legitimate contacts won't mind doing this as they know you have to protect the keys from scammers and they will most likely be used to being vetted and may even have already provided a method of doing so based on past requests.

You may get a lot of offers from sites asking you to also sell your game through their portal. Some of these are fine but some are scams also. Make sure you take great care when vetting these too.

It's still very early days on Steam and I hope for it to grow even more. Either way it's been a huge benefit releasing on the platform. I'll do a follow up post possibly after a month where I'll go into more detail on figures and analytics of the game.

Until next time!

Comments

    Archives

    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    August 2014
    November 2013
    September 2013

    Categories

    All

    RSS Feed

© COPYRIGHT 2020. ALL RIGHTS RESERVED.