One of my educational and self-improvement goals, which I am trying to accomplish for quite a long time, is to finish the edX Computer Science course from Harvard University. The CS50 course from the Harvard professor, David J. Malan, has an essential place in my bucket list. When I started the online class with him about two years ago, I fell in love with his teaching style immediately not only because it was easy to understand and to follow him, but also because it brought and still brings a great pleasure just listening to his lectures. The passion in David’s voice, dedication, and commitment to student learning attracted me to his lectures even after the long break. 

Fear of Coding

The reason why I stopped my online programming classes was my fear of coding. I tried to skip some tasks and focus mainly on listening to online courses, but my conscience did not allow me to listen to the lecture peacefully, which later led to oblivion for a couple of years. The tasks which made me sweat were not in particular complicated; they were related neither to Java nor to C++. I just needed to create a simple game with two characters in Scratch, interacting with each other. 

Introducing Scratch

Eventually, I got confused with the Scratch environment, overwhelmed with features I had to play with, and gave up. This time, I decided to start over and practice more with Scratch.

Let me tell you a bit more about Scratch. It is a platform where you can create simple 2D games without actual coding. What you need to do is drag and drop objects and operators and design functions and variables. The neat feature is that you can see the result of your actions on the same page simultaneously. That gives you a lot of opportunities to test the newly added operations and features. Besides that, the website has excellent tutorials that help you to understand the basic features you can do in Scratch and gives you challenges to try by yourself.

One evening I was going through my tutorials, and I was “programming” a quite simple game when my boyfriend entered the room, observing my early attempts of the coding experience. I was working on the chase – and – catch the game about the dinosaur who was chasing the fortune cookie; once the dinosaur touches the cookie, his skin changes its color, and the score goes up.

 My boyfriend asked me if I can make another simple game for popping balloons using my Scratch skills. I had no idea, but I knew that we would figure it out together.

The Project: Balloon Game

We started creating the game with significantly small steps. First, we’ve managed to move the balloon up (that was not so hard); however, it has been abruptly ending on the edge of the screen. So wouldn’t it be great to have a balloon that slides smoothly, but also disappears when it touches the ceiling? It would be great! It took me quite a while to figure out the X-axis and Y-axis coordinates on the screen. I could not see the coordinates for a starting point and the endpoint of the balloon’s moving path. When I eventually got the coordinates and the balloon moved precisely where I wanted him to slide, the next question was “how to achieve a smooth repetitive process of reappearing balloons.”

Functions

We tried such functions as “repeat” and “forever,” but the process looked slightly mechanical. I decided to solve the problem by trying every feature, hoping that something would eventually work. Not the best strategy, I can tell. I started feeling devasted, as I could not come out with any solutions. My boyfriend gave me a hint: to create three balloons at the same time. The easiest, but not an efficient way, is to create three balloons (also known for the name “strikes” in Scratch) and insert the same code for each. It worked out, but they were moving at the same time, and they stuck around the ceiling, and they could not move. What a puzzle!

Cloning

The solution we came to later, was to create clones (yep, you can do it there too) for the infinite period. However, the catch was in balloons, reappearing at the same time and moving in the same direction all over again. We added the function called “wait X-amount of seconds” to create a little pause between reappearing clones. Besides that, we set up a clone machine that was producing from 4-9 clones at the same time, following each other. To finish up that operation, we wrapped it up with the infinite loop. One challenge solved!

Another challenge was in making balloons appear from any point of the bottom of the screen and slide vertically to the upper edge and disappear when they hit a particular point of the screen. I was thinking very slowly, but my boyfriend helped me a lot with the If-Then algorithms. (He teaches Python by the way)

Forever Loop

If you look at the picture, you can see that we added the function that makes the balloon start from the random position, slide vertically to any X position and disappear, when it reaches Y= 220 or higher. The deleted clone is not such a significant loss, by the way. Why? Because we have a forever-loop-clone-factory, running on the background, producing tons of balloons. Bam! That’s genius!

All right, what can we do to bring some diversity to the game? We added our color festival. The next morning, this little piece of “code” took me around an hour to replicate. The next question was how to make the balloon pop and how to make the game satisfying and addictive.

Events

Scratch has an event (the feature) called “When this sprite (balloon) is clicked,” and it has the option to play the sound “Pop.” You can make your sound, but usually, Scratch already has a collection of basic sounds.


I was confused with this part, because I did not know in which order to put the music and the disappear, and also add the change of the size. Oh my God, changing the balloon’s scope was already a big challenge for me. We wanted to change the size smoothly and gradually until it is getting teeny tiny and disappears. My boyfriend helped me by pointing into the “repeat” function, repeats ten times the change of size, let’s say by -10, and deletes the clone at the end. Perfect and easy.

Score

The majority of games have a score. In our game, it was not there. Not yet. So how to make a score which goes up every time the balloon is “popped” (simply saying – clicked)? We added a new function definition called “Change the Score,” and I dragged the function “change score by 1”. It worked perfectly, but we also wanted to change the background and level up the level score.

Next, we decided to implement a level score. Every time the score reached 5, the level score became 1, when the score is 10, the level score is two, and so on. I tried to use the If-function to increase the level score when the count reached 5, but the problem was the following: when the score reaches 5, the level score increases by one every time I popped the balloon. Why? Because I made a command if the score, if more than 5, change the count by 1. When the score became more than 5, it changed the score by 1, but we wanted the level score to get raised with a difference of 5 of the count. I felt frustrated with that problem, as I could not see the solution, which was simple.

My boyfriend helped me create a new variable called “the goal” and set its default value to 5.

He added the If-Function: if the score>goal (by default 5), then the level will change by 1, the background will be different, and the goal will be updated by 5, and so on.

Villain

Here is the question, how to make the game fun and addictive? We need to add a hilarious villain to the game! We chose the bat as the villain for the game. The concept is simple: add a spike (a bat), make a bat-clone-factory (again), and change the Score by -1 every time the bat is clicked.

Easy peasy! Though the creation of this game took us around 7-8 hours. If you are interested in playing it, be my guest and check it out here. If you are learning Scratch, you can check the “code” by clicking “See inside” on the project page. 

Lessons Learnt

  1. Getting frustrated is not a solution, and trying random things, hoping for the miracle, is not helpful. The primary key is to understand what you want and what is missing. The rest will come after meticulous thinking of how to make it work and try many things based on logic and assumptions (not pressing all buttons at the same time).
  2. Playing around and not being afraid to make a mistake is essential if you want to learn to code and be good at it.
  3. Repetition and practice help a lot to learn and remember.
  4. Having a boyfriend who knows a lot in programming is a game changer!

P.S. Scratch is perfect for kids and adults who started learning the basics of programming languages, as it helps to understand the simple logic behind the code and the algorithm.


Related Article: Hackathon Tips for Beginners


EDITOR’S NOTE: The post was created only with an educational purpose, not pursuing any profit or financial goals.