Scratch has emerged as one of the best platforms for kids to explore while learning computer programming. The platform, developed at the Massachusetts Institute of Technology in 2003 and released in 2017, provides a high-level block-based programming language. Because it is block-based, meaning that codes ar e already embedded in the blocks, children do not perceive it as complex; rather, it makes learning to code more fun and interesting. Scratch allows children to create a variety of game in scratch, animations, and simple applications. In this blog, we will discuss one such type of game that is simple to create while also being fun and interesting to play, the Cozmo Mobile Game.
Scratch allows kids to create a variety of games, animations, and applications. In this blog, we discuss how to create a Cozmo Mobile Game
Creating this game will help you to understand how we can play scratch games on mobile.
Table of contents
Create a Cozmo Mobile Game in Scratch – Step-by-Step guide
Let’s start with the Cozmo mobile game’s journey.
Before you start to create the game make sure that you are logged in and to log in you must be a registered Scratch user. If you already have an account, that’s great, but if not, you can create one by clicking on Join Scratch.
Follow the steps below to start creating!
STEP 1: Go to the scratch menu and select Create.
STEP 2: Firstly, select your first sprite. Go to the right bottom corner of the editing project page and select a sprite. There are numerous sprites available for us to choose from.
We will also need an appealing background. We must return to the right bottom corner and select a backdrop. Choose a background based on your preferences.
Now that we’ve completed the design, it’s time to write the code for our sprite (car). Similarly, we will select one more sprite as a block that will provide us with a score when we collect it. Adjust the sprite’s size based on the sprite’s compatibility with the screen.
If we want to upload our own sprite, Scratch also allows that.
Now it’s time to upload our new sprites, such as a button that will cause our sprite to move around when clicked. We use the same procedure mentioned above to select the sprites.
We must rename all of the buttons as Up, Down, Left, and Right, and arrange them accordingly.
STEP 3: To make our car move in all directions (Up, Down, Left, Right), we will use the event block in the coding section and create an event for our buttons, which we have already selected. Go to the event in coding, click on it, and then select the green flag that was clicked. We will apply conditions that will allow the buttons to be clicked from a phone or a computer.
- Choose the green flag code from the event block.
- Take out forever block from control.
- Now take the if block from control and put it inside the forever to make the condition run continuously.
- We go to the operator, pick it out of the logic block, and put it in the if block.
- Now we will choose to touch the mouse pointer and mouse down (for playing from mobile click) for sensing.
- Choose a broadcast message from the event block and make the new message (any) “up” for making your up button work.
STEP 4: It’s now time to do codes for the car to receive the broadcasted signals and move around the stage.
Please ensure that you have chosen the correct sprite.
- Go to the event block and select ‘When I Receive,’ as we will for all other buttons (Up, Down, Right, Left).
- Go to motion and pick a point in direction 90 to make your Cozmo move perfectly.
- For Up, the point in direction will be 0
- For Down, the point in direction will be 180
- For the Left, the point in direction will be -90, and for the Right, it will be 90.
- Choose the moving block from the motion to allow our Cozme (sprite) to move as instructed.
- The number of move steps will be +ve for ‘up,’ ‘down,’ ‘right,’ and ‘left.’ You can use the following images as a guide.
Similarly, we write code for when the arrow keys on our keyboard are pressed. Take when key is pressed from the event block for all buttons and choose broadcast message as any arrow keys pressed for this. For a better understanding, look at the images below.
STEP 5: Now we’ll make our block sprite move to a random position when our car (cosmo) hits it, and we’ll calculate the score.
- Choose your block sprite and, in the script area, select when the green flag is clicked from the event.
- We’ll make a ‘SCORE’ variable from the variable block and set it to 0 before placing it below the green flag.
- Now, from the control panel, select the forever block.
- Move the If block to the forever block from control once more.
- Now apply the condition if the car (sprite name) touches take touching sprite block from sensing.
- Take the change score by 1 from the variable block.
- Go to the motion and insert the go to random position block inside the if block.
- This step is an extra feature to add sound for collecting the score, choosing it from the sound block pick play sound.
All of the above steps are shown below in the picture.
STEP 6: Now we must execute the code for backdrop go, select the stage, select a new backdrop, and write ‘game over’ on it. This will help us in displaying the message game over.
- Now we have to create a variable named timer from the variable.
- Back to the code area and choose again the green flag clicked for backdrop because we need to start the game in scratch with the first backdrop and take the switch backdrop block from looks.
- Choose the set timer variable to 30 sec.
- Next, we need to repeat the timer until it reaches 0. For this takeout repeat until blocked from control. Go to the operator block choose and put it in repeat until.
- Here we are setting the timer to 0 so we will take the timer from the variable. As the timer reaches 0 the game will stop and the backdrop will switch to the game over the backdrop.
- Choose to wait 1 second from control and choose change timer by -1 from variable put it in repeat until block.
- Now choose switch backdrop to game over and put it outside of repeat until block.
All codes are shown below in the picture.
Congratulations, our Cozmo mobile game is complete. In this game, you can change your sprites to your liking.
Conclusion
The capabilities of the scratch platform and programming language do not stop here. Scratch also allows you to create a plethora of other game in scratch and projects.
The creation of each project on Scratch leads to the unraveling and learning of computer programming fundamentals. It’s also a fantastic way to bring your imagination and creative ideas to life.
Learn Scratch at BrightChamps with its specially designed curriculum that makes learning programming easy for students in Grades 1-12.
The coding game for kids immerses them in a fun and interactive experience that promotes learning and creativity through programming.
BrightChamps also teaches a variety of other programs that help kids build a foundation in computer programming through activities, interactive lessons, and other means.
Frequently Asked Questions (FAQs)
No, you don’t need a Cozmo robot to create a Cozmo mobile game in Scratch. However, you can connect your Scratch project to a Cozmo robot using the Cozmo Scratch Extension to control Cozmo’s movements and actions in your game.
The Cozmo Scratch Extension is a Scratch extension developed by Anki that allows Scratch users to control Cozmo’s movements, actions, and sensors in their Scratch projects.
Scratch is not optimized for mobile devices, so it’s recommended to use a desktop or laptop computer to create a Cozmo mobile game in Scratch.