Today was the first day of Mr Boo’s new project (for more information about Project Based Homeschooling see this post). He has chosen to create a video game using the program Scratch. He has used it before, but not much, and he wanted my help in creating a proper game. This turned out to be a great project – I didn’t realize what a wide variety of learning would be involved.
He started by importing a generic background image from Minecraft. He chose a crab to be his first character (or “sprite”, as they are called). Eventually he added another sprite, coloured the “ground”, and added an obstacle (the brown block). Here’s a screen shot showing where he left off today:
But first, he started with just the red crab and the background (the pink bar was originally white). He attempted to program the sprite to move right or left with the right or left arrow keys, respectively. However, he ran into trouble when he could not get the sprite to change direction – it just rotated about its axis instead.
I suggested we watch a tutorial and Mr. Boo searched YouTube. He chose this one by MrMattperrault that shows how to make a sprite jump more realistically by incorporating gravity and velocity changes into the motion of jumping and falling.
At the beginning of the video the narrator reviews how to make the character move left and right. By looking at the scripts Mr. Boo learned where he had gone wrong: to change direction left or right you need to set x to positive or negative numbers (the magnitude of the number is how many steps the character takes when the key is pressed). He also saw that to get a character to jump (and thus fall back down rather than just moving up higher) he needed to set y to positive and negative numbers (with a slight delay in between).
The main topic of the video was how to get a character to jump realistically – in other words, incorporating acceleration due to gravity. Mr Boo immediately wanted to try this, and so he copied the scripts from the video. Not only did he get a lesson in physics about why things bounce, but he was introduced to the concept of velocity and how that relates to gravity for the sake of programming movement. And, he was also introduced to the concept of conditional phrases: “if/then”. Finally, he learned that multiplying anything by -1 changes it’s sign (and thus, in this case, the direction of motion). Here is a script that causes the character to drop onto the ground:
Basically this says if the character is touching the colour blue (which was the ground in the video demo) then it needs to stop moving, and if it isn’t touching blue (the ground) it needs to fall. Mr Boo programmed his sprite according to these directions and, at first, the character wouldn’t move. With some assistance from me, we figured out the problem. There was a white rectangle along the bottom of the background, and we’d programmed the sprite to stop falling when it touched white. However, there is also white in the sky so that’s why the character wasn’t moving. When Mr Boo changed the ground to pink it worked.
Before wrapping up for today he added a second character and a block to jump over. He’ll program them next Project Time.