I’ve just completed the first assignment of CS50: to develop a project with Scratch, a programming language by MIT’s Media Lab to create interactive stories, games, and animations.
I’ve decided to create a game where a baseball player is preparing for the upcoming season and wants to eat in a healthy way. To this end, he needs to eat apples and bananas and stay away from cakes and donuts. Eating fruits adds up to his score and sweets make him lose points. The game finishes when he scores 40 points. You can play the game here.
A copy of the exported project can be also found in my GitHub repo.
To create the game in Scratch, I first set up the stage with some sound effects:
I created two different backdrops: one to show the introductory text and another one to play the game:
Then, I added 5 sprites, the main character (baseball player) and the foods that he has to avoid or eat:
Next, I defined the motion behavior for the cake, donut, apple and bananas, and the coordinates where they should be shown when the game starts. This is an example for the cake:
With this in place, I started working on the player sprite. First, I defined the commands to be used for moving the player:
Then, I defined how the instructions would be presented (in the form of a dialog). There is also a prompt to enter the user’s name:
Finally, I set the conditions to score points, to make the game more difficult as the user approaches 40 points and I configured how to end the game:
In this caption you see some sprite clones and a bigger player to increase the difficulty of the game:
I’ve learnt a lot about loops, conditions, and variables and have had a lot of fun while developing the game!