Tuesday 14 May 2013

Runes: Songs of the Gods - Version 0.2

Version 0.2 – Adding particle effects and a datastructure

In this build I wanted to start putting in the core functionality. I wanted the build to cover:

  • Data structure implemented to store the selected rune states
  • Match-making implemented to run a check and see if the player scores
  • Add particle effects into the game for when the user scored a point
  • Make it so the wobble effect only plays when three runes are selected

The first part was to add a data structure. I went for the simplest one that fit – an array. I did not use a dynamic list as I knew I only ever wanted to store 3 values and work with those. Never would I want to compare more than three values.

I implemented a simple string array after thinking (but not designing) what the best type of data would be to store and work with. The main choices I was considering was assigning a numeric ID to each rune type or simple searching for their name and using that as an ID. I eventually settled on the latter as it was easier to implement.

    public string[] RuneSet;

A mistake I make here is declaring it public. There is no reason to do this and it makes code messy. I should be declaring it private or in a local scope and use get/set methods to access the data. I do this later on but some remnants still exist. What can I say – I’m real rusty! I populated the array using a simple iteration and a count variable which was reset by a separate reset function. Later I changed this as it was not complex enough to keep track of runes separately and caused many bugs.

Rather than post all my source code the pseudo-code below describes how this worked:

    If (count < 3)
        Array[count] = Rune Selected
        count++
    else
        Debug.log “Array full – run check”
    End If

The string was received from the rune class (actually a C# script called RndRune) It accesses the RuneSaver class (RuneSaver script) using code like the line below.

    public RuneSaver runesaver;
    […]
    runesaver = GameObject.Find("Main Camera").gameObject.GetComponent<RuneSaver>();

    [onMouseDown function]
    runesaver.AddToArray(gameObject.name);
    yield wait for X time
    runesaver.RemoveFromArray();

I simply use the gameobject (so the runes) name as an ID and I use this name to compare runes in future builds.

After getting all this up and running I decided that to debug this properly I wanted to have a little debug menu so I put one in. This allowed me to check if the score incremented and to see if the correct runes were being added to the array in the correct position and if the array was being reset properly.

I made a simple DebugGUI script and use the Unity OnGUI() function seen in the Unity tutorial. This resulted in the debug seen below. Pretty swanky! :D



The next part was to add a nifty particle effect. I used the Unity3D particle system and at first tried using my own textures for the particle (to make it look like lightning). This looked very bad and I took it out. Instead I used the default Unity3D particles. I used a simple smoke one in this build.

I ran into a bug here where the particles would play properly once the array was populated by three runes but the particles were going the wrong direction. I tried solving this by rotating the Rune model asset tied to the parent game object but this broke my prefabs and caused a major head ache as the runes would spawn in with different (the default since I don’t change this in the code )rotations.

I added the code to enable the wobble and particle effect only if three runes were selected. In this build I did it by accessing RuneSaver’s count from RndRune and using an If statement in the RndRune’s Update().

Basically:

    If count = 3 //Meaning there are three values in the array
        Do wobble effect
        Do sexy particles

I check to see if everything works. The match making check is calling properly and incrementing the score but does not perform any match making. It doesn’t really match runes, it just adds to score as long as the array is full. This is fine for now since I know a least it’s called at the right time (when the array is full).

To summarise, this build does:
  • Data structure implemented to store the selected rune states
  • Match-making not implemented fully and buggy
  • Particle effects in game but not called when user scores, just when array is full
  • Wobble effect only played once three runes were selected
V0.2 - Sexy Patricles going sideways!

No comments:

Post a Comment