Animated ASCII Art!


I wanted to mention that I DO have previous C# experience, mostly from @ben 's Unity 2D course. So if you’re looking at this thinking, “How did he do that for the FIRST LESSON?! I must be slow! :scream: :sob:”… you’re not! Just keep CODING! :muscle: :smirk_cat:

Also, yes, only after I built the game, uploaded it, made the gif, and everything else… did I realize I spelled “congratulations” wrong. :man_facepalming: :sweat_smile:


So for my version of the Terminal Hacker project, “Animal Liberation Force”, I wanted to bring some life into the Win screens, but I also wanted to only use coding, nothing else in Unity (just like the rest of the project). Turns out it was pretty simple! (Also, I’m sure there’s a bunch of ways to do this, some probably way simpler :man_shrugging: But here’s what I came up with…)

void DisplayWinScreen()
{
    currentScreen = Screen.Win;
    Terminal.ClearScreen();
    StartCoroutine(ShowLevelReward());
}

We’re using a Coroutine to allow for a delay between animation ‘frames’, so we have to use “StartCoroutine” to invoke the method.

IEnumerator ShowLevelReward()
{
        switch (level)
        {

Then to setup the Coroutine, we have to use IEnumerator rather than void, and we’re just going to set up a loop using ‘switch’

                case 1:
                    Terminal.WriteLine(@"
                      ,_     _,
            /)-_-(\   |\\___//|
             (o o)    |=^   ^=|
     .-----__/\o/     \=._Y_.=/
    /  __      /       )  `  (    ,
\__/\ /  \_\ |/       /       \  ((
     \\     ||        |       |   ))
     //     ||       /| |   | |\_//
"
                    );
                    Terminal.WriteLine("CONGRATUTATIONS! The pets have been");
                    Terminal.WriteLine("freed! Type 'menu' to free the rest:");
                    yield return new WaitForSeconds(animDelay);
                    goto case 4;
                case 4:
                    Terminal.WriteLine(@"
            _     _   ,_     _,
             )-_-(    |\\___//|
             (^ ^)    |=o   o=|
     .-----__/\o/     \=._Y_.=/
 /  /  __      /       )  `  (  ,
 \_/\ /  \_\ |/       /       \ ))
     \\     ||        |       |((
     //     ||       /| |   | |\\\
"
    );
                    Terminal.WriteLine("CONGRATUTATIONS  The pets have been");
                    Terminal.WriteLine("freed  Type 'menu' to free the rest:");
                    yield return new WaitForSeconds(animDelay);
                    goto case 1;

Our ‘frames’ are case 1 and case 4. We use ‘goto case’ to cycle between the two, but what makes the animation visible is the pause between switching. This is accomplished using WaitForSeconds. And we’re using a float variable ‘animDelay’ so that we can tweak the cycle speed during runtime to find what works best.

The last step is stopping the coroutine.

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            StopAllCoroutines();
            ShowMainMenu();
        }

Without the code above, if the player types ‘menu’ from the animated win screen, the menu will flash for an instant but then our dancing pets pop right back up. That is because the code will prioritize the Coroutine still running. So we add StopAllCoroutines() which will stop our animation and let the rest of the code run normally.


*Side note, you may be wondering why it goes from case 1 to case 4 rather than to case 2?

Our OnUserInput() method retains the variable the player used to select the level (1, 2, or 3), so the case# chosen by this switch will correspond to that level selection. That means you can use this 1 method for animation in all of the win screens, but the win screen for level 2 must be case 2, and so on. But from there you can use goto case # for however many frames you want to use, as long as the last frame has goto back to the starting frame.


I hope you liked that explanation. Thanks for reading! :smiling_face_with_three_hearts: Please ask any questions in the comments and PLEASE let me know if you try some ASCII animation in your game!


my version of Terminal Hacker can be played HERE

1 Like

Congratulations on the game! :clap: You did a phenomenal job with the knowledge you learned from the courses! I love your gif and funny explanation post. Keep spreading the message that if you keep it up you will get there. A lot of people need to hear that it’s okay if it takes a while. Slow and steady wins the race and the only person you are competing against is yourself :100: Great explanations throughout your lost and a gem for anyone going through the forum looking for inspiration and insight into C# code. Keep it up! You’re doing an amazing job!

1 Like

Thanks so much for the comments!

A forum like this is great, not just to get inspiration from others, but to inspire all of us to share no matter where we are on our GameDev journey. :slight_smile: :nerd_face:

Privacy & Terms