Dev Log #8

This week I worked on the assignment and made a start to it. I decided to make the camera orthographic and aiming at an angle, since it looks better than a perspective camera in this case. I also got the idea of doing that from the production assignment i'm currently working on, in which we have the same camera set up.

The player can't move and needs to kill a certain amount of enemies before moving onto the next area. In total there are going to be 4 areas with probably a boss battle at the end.

In the above image you can see the enemies with the text boxes above their head. For the assignment we needed a lot of visual and audible feedback. So when a player inputs a letter, it checks all the current enemies to see if their first letter is the one pressed. If so, then that word becomes the current word. The text box gets a green highlight and that UI element renders in front of everything else so that it is in full view and that the player can easily see it.

The text that the player hasn't typed is grey, typed is green and current letter is white. When an enemy dies the screen shakes. This is also the same screen shake effect from the previous assignment.

//Called if this is the current word and a letter is inputted.
    public void UpdateWord ()
        string fullWord = wordToType.word;
        string progress = wordToType.curTyped;

        if(fullWord.Length == progress.Length)
            wordText.text = "<color=lime>" + fullWord + "</color>";
            string green = progress.Substring(0, progress.Length);
            string curLetter = fullWord.ToCharArray()[progress.Length].ToString();
            string end = fullWord.Replace(progress, "");
            end = end.Substring(1, end.Length - 1);

            wordText.text = "<color=lime>" + green + "</color><color=white>" + curLetter + "</color>" + end;

        //Increase size of word box.
        transform.localScale += new Vector3(0.02f, 0.02f, 0.02f);

Each UI word object has the above script. The function is called when the OnLetterInput event is called. It updates the word's text to display what was mentioned above. There is a lot of cutting up and trimming of strings to create a final line of text. Also as a bonus for feedback, the word box increases in size with each letter input.

If the inputted letter is not the correct one corresponding to the current word then the text will flash red, with the same code as the enemy flash in the previous assignment.

The above code took me a bit to get working correctly. When I first wrote it, my understanding of Substring was totally backwards. I though it cut out that part of the string rather than cut out the other part. Sounds weird, but just think of Substring backwards. When I understood it though, the code ran pretty much perfectly. 

Another thing that I think should be mentioned, is how are the words selected. Well, I have 2 text files with 300 words each. One for easy words and the other for medium words.

//Loads the 2 easy and medium word files and puts them into lists.
    void LoadWords ()
        string[] easy = easyWordsFile.text.Split("\n"[0]);
        string[] medium = mediumWordsFile.text.Split("\n"[0]);

        for(int x = 0; x < easy.Length; x++)
            string e = easy[x].Replace("\r", "").Replace("\t", "");

        for(int x = 0; x < medium.Length; x++)
            string m = medium[x].Replace("\r", "").Replace("\t", "");

The above code loads in the words from the text files. It first gets the string value of each file and then splits it into a string array every new line.

Then, it just loops through those arrays, filters out any hidden characters and adds them to their corresponding lists.

Selecting words is just as easy. When the game wants a new word it send over a list of existing words that are currently on the screen. The script filters out all words beginning with those existing letters and sends back a random word to be used.