Teach Your Kids to Code Apps With Pocket Code

Education Geek Culture Software Technology
Image: Catrobat
Image: Catrobat

You probably know about Scratch, the graphical programming environment developed at MIT that allows kids to code interactive stories, games, and animations. Researchers at the Graz University of Technology in Austria have been working hard at creating Pocket Code, a Scratch-like environment for the Android platform.

Pocket Code is an Android app that allows you to code apps right on your phone or tablet, be it games, interactive stories, animations, or something else. And it is absolutely free, even Open Source! You can get it via Google Play; if that is not an option (e.g., for Amazon Fire tablets), you can download some reasonably recent binaries for manual installation from the developers’ website.

I discovered Pocket Code a few days ago, and since then I have used my tablet for little else than done playing around with Pocket Code. Let me show you a how easy it is to create the beginnings of a little game.

First, we need a Space-themed backdrop and two types of starships. For the background, I went outside and snapped a photo of the nightly sky. For the spaceships, well, with the imminent awakening of The Force, I went to my kids’ room and photographed LEGO  models of an X-Wing and a Tie Fighter. Below, you see the backdrop and the two spaceships in Pocket Paint, the companion app of Pocket Code.

The background (left), Tie Fighter (middle) and X-Wing (right) in Pocket Paint.
The background (left), Tie Fighter (middle) and X-Wing (right) in Pocket Paint.

Now for the coding. In Pocket Code, you associate scripts with  the background as well as the objects. The script for the Tie Fighters (eventually, there will be three copies of the Tie Fighter object), does the following (see image below in the middle): When the script receives the message to start, it places the object at the top of the screen at a random location and then gradually moves it downwards. When the Tie Fighter has traversed the whole screen, this process repeats. After each downwards step, the object checks for a collision with the X-Wing — unfortunately, in Pocket Code there is no high-level support for collision detection (yet), so a comparison between the coordinates of the Tie Fighter and the X-Wing has to be carried out.

Scripts associated with the background (left), a Tie Fighter (middle), and the X-Wing (right).
Scripts associated with the background (left), a Tie Fighter (middle), and the X-Wing (right).

The script associated with the background (see in the image above on the left) gets the Tie Fighters started one by one; I could have built the delay into the respective Tie Fighter objects, but I wanted a central location to control the timing.

Finally, the script associated with the X-Wing (see in the image above on the right), reads out the left-right inclination of the tablet and moves the X-Wing (placed on the bottom of the screen) accordingly. A second script (not shown) reacts to a message sent by any of the Tie Fighters when a collision has been detected: The X-Wing then changes shape into a pile of LEGO bricks (another photo taken in the children’s room).

After adding a “Game Over” object that appears when a collision has been detected, this first version of our little game is done. Below, you can see the overview as shown by Pocket Code (left-hand side), a scene in mid-game (middle) and the “Game Over” screen with destroyed X-Wing (right).

The components of our game (left), during the game (middle), and game over (right)

 

The logical next step is to enable the X-Wing to shoot laser beams: If we allow for at most one laser beam on the screen at any time (as was good tradition in many Arcade games of yore), all we need is another object and an associated scripts for movement. The script for the Tie Fighters would have to be modified so as to detect collision with the laser beam and react to it.

As you can see, coding simple game apps for Android is made quite easy and intuitive by Pocket Code, a great tool for teaching kids the first steps of programming. The creators of Pocket Code are making more and more teaching materials available: A few days ago,  the new educators’ community for Pocket Code was launched with materials for teaching coding with Pocket Code inside or outside the classroom. One particularly helpful resource are the so-called pocket cards that give a concise introduction to the most frequently used techniques and concepts when coding in Pocket Code.

Overview of pocket cards available on edu.catrob.at.
Overview of pocket cards available on edu.catrob.at.

Do you already have a project for the upcoming Christmas vacations? If not, consider teaching your kids to code games using Pocket Code!

Liked it? Take a second to support GeekDad and GeekMom on Patreon!
Become a patron at Patreon!