Skip to content

ReimuDodge Tutorial Part 1

Barley edited this page Oct 23, 2017 · 75 revisions

Intro

Welcome to the NitorInc microgame coding tutorial!

In this guide, you'll learn, step by step, how to make a simple microgame code-named: ReimuDodge. In the microgame, the player will control Reimu with their mouse and attempt to dodge a series of danmaku bullets.

The tutorial is quite detailed, so if you are not totally new to Unity it's ok to skim through bits of it; the end result is what matters. Just make sure you pay attention to what needs doing at each stage and hopefully you'll learn some useful things along the way.

Don't feel the need to pump this all out in one sitting either. It's a good idea to take small breaks between parts of the tutorial, or to walk away from a problem you're having and come back to it with a fresh mind. Making games is a marathon, not a sprint. Pace yourself well.

If you get stuck at any point or you notice something about the tutorial we could explain better, let us know on the Discord server.

This tutorial also assumes you've been following the Coder Intro up to part 2 and that you've already got NitorInc (NitoriWare) open in Unity and created a new branch in a local fork of NitorInc called "Microgame/ReimuDodge/basic-functionality".

But before you start, an important note: The "basic-functionality" part of the branch name is what defines the scope of your pull request. For this tutorial, we'll be making one pull request from one branch where the game works as a whole. In a real microgame, however, you should be taking smaller steps (i.e. "prototype", "add-difficulties", "add-sound-effects") and submitting a PR for review when that step is met. This is about more than just making sure your code works. The more the NitorInc. team can look at what you have so far, the more we can advise you on what to change and how to make your game more fun to play! Plus, if something ever comes up and you have to resign from a game, we have a good milestone to pick up from.

All good? OK, lets begin.


Preparation Phase

The helpful folks at NitorInc have kindly provided some art and music to go with this tutorial. Before you start, download the ReimuDodge assets ZIP file. You'll need it shortly.

1. Make the microgame folder

To start off, find the project window in Unity (Window > Project if it's not already docked) and navigate to the microgame folder in Assets > Resources > Microgames

Now, create a new microgame folder here (Right click > Create > Folder), call it "ReimuDodge".

All of the assets and code for the microgame will be kept inside here.

2. Copy scene and traits

The first thing to add is the microgame scene files and traits. Create a new folder in ReimuDodge called "Scenes":

Unity games are composed of scene files. Each microgame is made via three separate scenes: one for easy, medium, and hard difficulties. NitorInc has a microgame scene template ready to use with a bunch of things already set up, so we'll copy that (as well as use it for every microgame you start).

2a. Copy scenes

Navigate to /Assets/Resources/Microgames/_Template/ and right click on the Template file. Select Show in Explorer.

All files imported by a Unity project automatically generate .meta files which will be visible in your OS's file explorer. They're simple YAML text files that Unity uses to store information about assets. For the most part, they can be ignored. Do commit them however.

Since Unity wont let you copy things from the project window we have to do this step ourselves. Copy Template.unity (ignore the .meta file) to your new Scenes folder in ReimuDodge.

Now rename the file to something more appropriate. Microgame scenes files should have the same name as the game itself, with a number on the end to indicate the difficulty level. So, we'll call this file "ReimuDodge1" for difficulty level 1.

We're also going to need scenes for difficulty levels 2 and 3 but it's simpler to create those later after the first difficulty is complete.

2b. Copy traits

Open up the Template folder again and look for the .prefab files called: Traits1, Traits2 and Traits3. Ignoring any .meta files, copy all of these files into the root of your ReimuDodge microgame folder. We'll modify these in the next section.

These need to be in the root "ReimuDodge" folder and not in any subfolders or the game will not work properly!

Your project should now look something like this:

3. Microgame traits

The Traits1, Traits2 and Traits3 prefabs you now have in your ReimuDodge folder contain meta-info about each difficulty stage of the microgame. For instance, Traits1 contains information used by the ReimuDodge1 scene, and so on.

Select Traits1 and take a look at the inspector window to see all of the customizable settings:

Breakdown:

  • Control Scheme Determines whether the game is controlled by keyboard or mouse.
  • Hide Cursor Only applicable to mouse-controlled games. Will make the player's mouse cursor invisible.
  • Duration Microgames can either be short (8 music beats) or long (16 music beats).
  • Can End Early If this is checked, the microgame will end as soon as it can when a win/loss condition has been set (in about 2 seconds max). Unnecessary dead-time if the player is fast. For most cases, set this to true if and only if the duration is 16 beats.
  • Command The text that will appear at the start of the microgame to inform players of what to do. Since the game will be localized from a text file, this is mostly for debug purposes.
  • Default Victory If checked, the game will be be won by default. Applicable for games such as this; where the player must avoid a failure.
  • Victory Voice Delay / Failure Voice Delay Delay (in seconds) before different voice clips are played. Used for sound-design purposes in case the game should wait for a sound effect to finish before a voice clip is played.
  • Music Clip The music for the microgame stage is placed here. We'll revisit this.
  • Is Stage Ready Ignore for now, checked when the microgame stage is at a game-ready level.

3a. Customize stage settings

For our microgame stage, we will change the following variables:

  • Set the Control Scheme to Mouse.

    • The player character will be controlled by mouse movement.
  • Check the Hide Cursor checkbox.

    • We can hide the cursor since Reimu will be moving with the mouse; effectively replacing the cursor.
  • Check the Default Victory checkbox to indicate that the game is won as long as Reimu hasn't been hit.

    • The goal is to dodge bullets so you should only lose if you get hit.
  • Add the text "Dodge!" to the Command text box.

    • Usually, you'd discuss what command to put here with your team. This one, however, is fairly obvious.

You will also need to set these values in Traits2 and Traits3, since the gameplay will be identical for each of our stages.

There are still some things we could tweak, but this should be enough for now.

4. Open the ReimuDodge1 scene

Open up the ReimuDodge1 scene in Unity. This will bring up the scene view for the scene along with a view of the object hierarchy. You'll notice in the hierarchy window there are two objects already in the scene (from the template we're using): Microgame Controller and Main Camera. In Unity speak, these are GameObjects.

We don't need to mess with those just yet. For now it's enough to know that they need to be in the scene in order for the scene to function as a microgame.

5. Set the game aspect ratio to 4:3

Hit the play button at the top of the scene view or switch to the Game tab. This is where you'll be able to test the game while developing it. However, the default aspect ratio, Free Aspect, is not correct. Make sure this is set to 4:3, since this is what NitorInc is fixed at.


Commit to Git

It's good programming practice to do regular, small commits every time you add something new.

Open up to your Git program of choice (I prefer Github desktop) and, making sure you're on your newly created Microgame/ReimuDodge/basic-functionality branch, add the contents of your ReimuDodge folder and commit the new files with a short message. Remember not to commit any files that are outside the ReimuDodge folder.

Refer to part 1 of the coding intro for a git refresher if you're having any trouble.

Warning: because Unity automatically creates .meta files for anything in a resource folder, having an empty folder in your project will cause problems with the repository when switching branches (git wont commit a folder but will commit its .meta file). Make sure you only commit new folders if they have files in them.

Your commit should look something like this:

Take note of how Github is tracking every file in the project you change, add, or remove. Take advantage of this extremely useful feature by making sure that everything edited is within your microgame's folder (excluding the auto-generated .meta for said folder). If you find a changed file out of place, either revert its changes by right clicking it and selecting "Discard Changes" (WARNING: this will revert the file's contents to before you changed it, so think before you act) or simply uncheck the checkbox on the left to tell Github not to include this file in your commit. If you must change something outside of your microgame's folder for any reason, notify us beforehand so we can work out any potential issues.

Clone this wiki locally