Category Archives: Game Development

Digital Arts Foundation—Final Project: Week 6 (Production)

For week 6, the lecturer provided me with a useful tutorial from the DEV community to set up a basic game in Unity.

I ignored the player movement part, since that part was already done.

I followed the camera part of tutorial, and then googled various sites in order to adapt their script to 2D top-down. I eventually got the camera working with lots of testing.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraScript : MonoBehaviour

   // Making a public variable for Player.

{
    public GameObject playerDiamond; 

    private Vector3 offset;

    // Start is called before the first frame update.

    void Start()
    {
        offset = transform.position - playerDiamond.transform.position;
    }

    // Update is called once per frame.

    void LateUpdate()
    {
        // Make Camera match player's transform position.

        transform.position = playerDiamond.transform.position + offset;

    }
}

Figure 1: Camera Script that follows the player from overhead.

The next stage in the tutorial was concerned with creating a game over screen. There were 3 steps involved: creating “Game Over” text that filled the screen; deactivating all the game objects for that screen; and constructing a way to reload the game.

There were numerous problems at every stage, but gradually I found solutions to the problems that came up. I think the tutorial was also slightly wrong, since it assigned a variable true, checked if it was true, and then assigned it to be true again inside the check. I could not see any other script that interacted with it, so I changed the first assignment to be false and then the check to look for false. The theory behind this is that it won’t execute more than once, which could possibly cause errors or slow down the execution depending on what code executed following the success of the check.

The tutorial showed me to put all the code inside a Game Manager script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

 public class GameManager : MonoBehaviour
{
    bool gamehasEnded = false;

    public GameObject Floor;
    public GameObject GameOverPanel;
    public GameObject Player;

    public void GameOver()
    {
        if (!gamehasEnded)
        {
            gamehasEnded = true;

            foreach (GameObject enemy in enemies)
            {
                enemy.SetActive(false);
            }
            Floor.SetActive(false);
            GameOverPanel.SetActive(true);
        }
    }

    void Restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
          Restart();
        }
    }
}

Figure 2: Game Manager Script.

I made the pressing down of the spacebar trigger restart, which just reloads the scene.

Next week, I’ll look at adding enemies and collision.

Digital Arts Foundation—Final Project: Week 5 (Production)

In week 5, I looked at a couple of in-program tutorials. The first was the Karting microgame. It helped familiarise me with the basic tools in Unity and how to publish a game. I also looked at the FPS microgame. It was also useful, this time teaching me more about moving the camera around in the scene view. While these tutorials were useful, they still didn’t really give me a good place to start.

Figure 1: Karting Microgame Preview (Unity 2023)

I asked a classmate where he started and he said he did player movement first, so I searched and found this tutorial (Stuart’s Pixel Games) on how to do simple 2D Top-Down movement. I copied the following code into a player script:

Rigidbody2D body;

float horizontal;
float vertical;

public float runSpeed = 20.0f;

void Start ()
{
   body = GetComponent<Rigidbody2D>(); 
}

void Update ()
{
   horizontal = Input.GetAxisRaw("Horizontal");
   vertical = Input.GetAxisRaw("Vertical"); 
}

private void FixedUpdate()
{  
   body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}

Figure 2: Player Movement Code (Stuart’s Pixel Games n.d.)

Once I put it in and attached it to a player game object with a rigid body, I noticed the player was drifting downwards. I simply had to zero the gravity value from the RigidBody2D and I now had basic movement.

For the final task this week, I decided to implement a feature that looked easy to do: changing colours with a keypress. This is essentially broken down to a key press event, and then switching between multiple predetermined values. The two common ways to do the latter are either using a switch statement or going with a hash table approach, such as using key value pairs to determine the next value to switch to. I chose to do the latter as it looks tidier in my opinion and is something I’m more familiar with.

The Unity scripting reference API was useful in finding the information out. The pages GetKeyDown Event and Colors provide the information to create the function, while TutorialsTeacher provided information on C# dictionaries, which help with the organization.

    public Color activeColor;
    private SpriteRenderer render;
    private Dictionary<Color, Color> colorChange = new Dictionary<Color, Color>();
    public Color colorWhite = new Color(1f, 1f, 1f);
    private Color colorGreen = new Color(0.25f, 1f, 0.25f);
    private Color colorRed = new Color(1f, 0.25f, 0.25f);
    private Color colorBlue = new Color(0.25f, 0.25f, 1f);

 void Start()
    {
        ColorChangeSetUp();
    }


  void ColorChangeSetUp()
    {
        colorWhite.a = 0.75f;
        activeColor = colorWhite;
        render = GetComponent<SpriteRenderer>();
        colorChange = new Dictionary<Color, Color>
        {
            { colorWhite, colorGreen },
            { colorGreen, colorRed },
            { colorRed, colorBlue },
            { colorBlue, colorWhite }
        };
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            if (colorChange.TryGetValue(activeColor, out Color newColor))
            {
                activeColor = newColor;
                render.color = newColor;
            }
        }
     }

Figure 3: Player Colour Switching Code

The tricky parts were trying to get the right colours to display. It took me a while to learn how to generate custom colours using the “new Color” constructor.

Next week, I will look at making a very basic working game.

Digital Arts Foundation—Final Project: Week 4 (Pre-Production)

For this week, our lecturer tasked us with summarising our pre-production by producing a milestone video. I thought about what I wanted to show: my plan document and the flowcharts. I also wanted to talk about the languages I explored in Week 2 and also my inspirations. I came up with the following document:

Figure 1: Finalized Plan of Final Project

It outlines my inspirations, as well as the game mechanics. I neglected to mention the blue/red/green rank concept was inspired by Mario Bros. , the arcade game featuring Mario and Luigi, where they bump enemies from below, and the spin-off of the Donkey Kong arcade game.

I’m big into Pokemon and I’ve played a battle mod where your inherit other abilities from the previous Pokemon you sent out. This led me to adapt the brief to something incorporating inheritance. I settled for gaining abilities of defeated enemies. As mentioned, I was also interesting in getting past walls that you wouldn’t normally be able to get past, which features in many 2D games, including Mighty Switch Force and Mutant Mudds. The brief also strongly reminded me of The Legend Zelda on the NES.

Along with this document, I also wanted to present the flowcharts that I’d produced on Lucid Chart and link to an article that showed the benefit of making a 2D game on Unity as opposed to Unreal Engine. I found a comparison article here.

My final page of flow charts looked like this:

Figure 2: Page of Flow Charts

Once I had all these elements in place, I recorded my screen and did a commentary on my pre-production. I wrote a quick script that I could read from, and kept re-recording until I produced something of 2 minutes length, as per requirements, and that I was also happy with.

Figure 3: Pre-Production Milestone video

I realized after I forgot to make a proper theme and name for the game, and also summarise what the game was about. I was happy otherwise.

That concludes this week. Next week I will describe my exploration on Unity and start of my game, which will come under the first week of production.

Digital Arts Foundation—Final Project: Week 3 (Pre-Production)

For week 3, I mind-mapped my project with flowcharts, making pseudo-code that will help me once I enter production. I started out by describing the start of the game, the damage received, and the game over / restart sequence.

Figure 1: Game Start and Player Damaged on Lucid Chart (2023).

Next, I thought about all the key variables that I thought would need to be accessed in the game events to make the game flow. For instance, I planned three different types of enemies, and depending on the type, they were to be weaker or stronger; but at the same time, sharing the basic characteristics of an enemy. The variables indicate what specific code is needed execute to generate the desired differences in strength.

Figure 2: Enemy Variables on Lucid Chart (2023)

The final stage of making the flow charts was to add the events in the game. For example, I presented some approximate logic for player movement, such as changing the orientation of the player sprite, and also how the player interacted with walls. Other events included player and enemy attacking, and the points gained when defeating enemies.

Figure 3: Player Movement Function on Lucid Chart (2023)

That concludes week 3. Week 4 will look at the penultimate stage of pre-production, summarising my planning before exploring Unity in Week 5.

Digital Arts Foundation—Final Project: Week 2 (Pre-Production)

For my project in week 2, I looked into C++, which is used in Unreal Engine. I mainly went through the C++ section on W3Schools and completed the exercises where you have to complete the missing input. I found the cin and cout (C-input and C-output) concepts intriguing, as well as reference and pointer variables. I’d not come across anything similar in JavaScript, my main coding language, which I actually only script in, rather than program.

Figure 1: C++ Introduction Exercises (W3Schools 2023)

I also looked at the more complicated part, how C++ is used in conjunction with Unreal Engine. It certainly looked more intimidating, because of having to learn about its templates, its way of doing things.

Figure 2: Programming Quick Start Tutorial for Unreal Engine (Epic Games 2023)

I then went on to look at C# very briefly on W3Schools, the language used in Unity.

Figure 3: C# Tutorial (W3Schools 2023)

I found the syntax comfortable (and C++’s too), so I came to the conclusion I’d be comfortable working with either engine regardless of the language.

Due to my experience last semester and even before on gaming news websites, I knew that Unity was deemed the more natural choice for a 2D game, so I decided I would choose Unity and work with C#.

That concludes Week 2. In the next week, I will look at creating flowcharts to mind map all my code before using Unity.

Digital Arts Foundation—Final Project: Week 1 (Pre-Production)

Hi, my name is Jack Ralls.

I’m learning computer games programming in Solent University. I will be making a development log of my ‘final’ game project in the foundation year, which will detail my journey from pre-production to post-production.

In the 1st week, we were given a brief by our Lecturer. We were to make a 2D top-down hack ‘n slash computer game. The following were our requirements:

Figure 1: Final Project Brief (Solent University 2023).

I thought these requirements were a bit ambitious for a first game, but nevertheless I took on the challenge and came up with the following plan (between the first week and second week):

Level

2D-Top-Down with camera tracking the player and scrollable in every 2D direction.

Single level with a few different areas to explore some basic combinations.

Health

3 ranks of enemy: blue have 3 HP, red have 2 HP and green have 1 HP.
The player has 3 HP.

Attacks

The player has two attacks:

  1. A strong attack that deals 2 damage and activates twice as fast as the weaker one, but the player can’t move or attack following the activation/usage for a second.
  2. A weak attack that deals 1 damage with no recovery time.

The green enemy uses weak attacks.
The red enemy uses blocks and weak attacks.
The blue enemy uses blocks and strong attacks.

Movement (Translation) Speed

Player moves faster than the enemies, enemies move different speeds according to rank.

Abilities

There are 2 different types of enemy: one type can walk through walls of their colour and the other type can teleport to squares of their colour.
The player inherits their abilities by defeating them (reducing them to 0 or negative HP) and you can hold multiple abilities.
The player will able to swap between green, red and blue costumes with a key, which will tell the player which colour wall they can walk through or colour square they can teleport to.
There will be a teleport key and only one teleport square of each colour at most within the area surrounding the player, so there’s no ambiguity about which square they teleport to.
There will be icons to show that the player has acquired the ability to walk through walls or teleport.

The player has a default ability to hide (become translucent, stay in the same place, but not interact with enemies).

AI

???

Points

The Player receives 6 points for defeating a blue enemy, 3 points for defeating a red enemy and 1 point for defeating a green enemy.
If the player defeats all coloured enemies of one type, they gain 10 bonus points. If they defeat all coloured enemies of both types, they gain an additional 10 bonus points. (up to 30 bonus points)

I felt more motivated once I came up with my plan, but I recognized I had barely any programming experience in a gaming engine.

That concluded the first week. In the next week, I will continue to describe what I did in my pre-production.