Created on August 23rd, 2014. Built on the MacBook Air.
Devon hasn’t been as interested in Scratch lately, so we haven’t been building any new games. He did, however, just start kindergarten. We’re homeschooling, and I figured since he has to learn his math anyway maybe we could create a game for him. He wasn’t very interested in building it at first, so I told him I would do it and as soon as I started building it, he jumped right in and wanted to help type out the variable names.
I started with a google image search and imported the image to create a sprite of numbers:
The first version of the game was kind of silly in that I made a sprite out of each number and each sprite stored its own value. As with most programming, I generally try to get a working prototype first and then go back in and refactor it once I’ve proven the concept. The final version of this game comes complete with a displayed answer and much less complexity and duplicated code.
Once I changed things up, it was helpful to export the costumes as individual images (which I used the editor to obtain):
Here are the sprites for the left hand number, right hand number, 10’s place answer, and 1’s place answer:
Each sprite contained all of the numbers as costumes, named accordingly so we could access them via code:
Here’s the main stage code using variables for left, right, and answer:
The code for the left and the right is pretty straight forward, the only different being the variable we use to display the costume (either left or right):
Displaying the answer gets a little more tricky. You have to think about the one’s place and the ten’s place differently. I coded it this way in case I want to add more complex answers in the future beyond 18 (that’s the highest number you can currently get out of this):
The mod function wasn’t working as I thought it would, so I had to put in some test variables and display them on the screen to figure out what was going on. As with all programming, it’s really important to view the data and not make assumptions.
It would be easy enough to add other math functions to this such as subtraction and multiplication. You could add a menu and then just change out the functions used and the stage costume which currently shows addition.
This was a fun way to spend a bit of time on Saturday. I hope it gets you thinking about creative ways you can build tools to help educate your kids.
Here’s a demo:
Here’s the full Scratch file: Counting Refactored