Just found this fab video made by a school to help children+teachers learn the term #algorithm http://youtu.be/od_zF0HZWGM #kidscancode #ukedchat
Techie Kodu needs to be installed on your machines to run this lesson. This can be downloaded from here.
Installation instructions are available on the download page.
Tell the children we are going to do an hour of code using a program called Kodu by Microsoft. Explain that we are going to create a simple game called Cycle vs Flying Fish. The idea of the game is to destroy 10 flying fish as quickly as possible.
Select new world. This will give you a blank world to start with. We aren’t going to spend much time messing with the world as this is more about coding but choose the world creation tool (paint brush) and click and drag your mouse around the green land already on your screen. This will give us more space to work in. (You could later extend the lesson by manipulating the world to add hills, water etc). Get the children to load Kodu and do this now.
Now we have a nice sized world to work in let’s add a character. Click on the object tool(face) and click on the land. This brings up the object insertion tool. We are going to add a cycle character by clicking on the option with the flying saucer, cycle and fish (under the apple). This pops out another menu with different characters. Click on the cycle. Now a cycle character should appear on your land. Let the children add the cycle character.
Now we have a character let’s give it some code to make it move using the keyboard. Make sure the object tool is still selected (yellow brackets around the face). Now right click on the cycle character and choose program. Explain to the children the way Kodu works is by giving objects lines of code that do something when something happens. Each line is numbered and the lines of code work in that order. This gives us simple sentences to code with.
Explain To make the cycle move when the arrow keys are pressed we are going to create a simple sentence of code saying ‘When Keyboard Arrows Do Move’. Let’s add this to our cycle by clicking on the + next to when this pops up a new menu. Select keyboard. This now added the word keyboard after when and the pencil moves along to the next +. Click the +. This time the menu only shows us keyboard options as Kodu knows we are looking at the keyboard from the first part of our sentence. Click arrows. Now click the + after do and you get a menu with do commands. Select move. This now completes our sentence. Press the esc key on your keyboard to exit program mode and click the green triangle. This takes you into play mode. Show the children your cycle moving around by pressing your arrow keys. Give the children a few minutes to do this on their screens.
Now we have a moving cycle let’s add the robot fish. Again click on the object tool and click somewhere on the world to open up the menu. Goto the option with the flying saucer, cycle and fish on and select a fly fish. Now we have a fly fish we are going to program him by right clicking him. The first thing we want him to do is move around randomly. To do this we are going to add the sentence ‘Do Move Wander’. Explain to the children that we want this to happen all the time so we aren’t giving it a ‘When’ instruction. Click the + next to do and select move. Now click the + next to move and select wander. Show this in action by escaping out of the code and pressing the play button. Let the children do this on their programs.
Now we have a fly fish and a cycle. Let’s make the game more interesting by giving the cycle a weapon! To do this we need to click on the object tool to put the yellow brackets around it. Now right click on the cycle and select program. We are going to add a second sentence to our cycle which will read ‘When Keyboard Space Do Shoot Missile Forward’. Click on the + next to when and select keyboard, click the + next to keyboard and point out that the option we want is under the section called misc. Click misc and select space. Now for the do section. Click the + next to do and select shoot, click the + after shoot and now select missile from the options, finally we need to tell the missile which direction to shoot in. Click the + next to missile and click on direction, now click forward. This should complete our sentence. Test it out and show the children the cycle shooting a missile but don’t hit the fish. Now let the children do this and get them to test theirs.
Talk Partners – What happens when you shoot the fish with a missile? Feedback and discuss. Talk about what happens in a normal computer game when you stop an enemy or collect something (you get points).
So let’s give our game a score option and make it so that when the fish is hit you score 1 point. To do this we need to give the cycle a third sentence. Again make sure you are using the object tool and right click on the cycle. Select program. We are going to make the sentence read ‘When Hit Fish Do Score 1 Point’. Explain that this will automatically create a score system and add a point to it if the cycle hits the fish with a missile. First click the + next to when and select hit, click the + after hit and select bots I followed by flying fish. This creates the first part. Now click the + next to do and click game. Explain that the game section gives us lots options to make our games more realistic. Now click score, click the + after score and select 1 point. Now get the children to do this and test it.
Now when we hit the fish we get a point but the fish still disappears so the max score we can get it 1. This doesn’t make much of a game so let’s change the fish’s settings so we can have lots of them. Explain to the children that In Kodu we can make any object become a creatable this means that another object can create it for you and it will automatically have the code you give it. Thus making it a fully working object in your game. Again while in the object tool right click on the fish and this time select change settings. Scroll down the list using the arrow keys until you see the option creatable. Click the on/off button to the left of the creatable option to turn it on. Now press esc to exit and notice that the fish has a green glow around it showing that it’s a creatable. Get the children to this now but do not run the program yet.
Now the fish is a creatable we need to add a new object to create it. We are going to add a castle to do this and create a sentence to create a fish every 3 seconds. Using the object tool click on the world to insert a new object. Select the option with a castle, missile and coin on next to the tree. Now click on the castle to insert it. You can reposition the castle by clicking and dragging it. With the castle in the correct position right click on it and select program. We are going to create the sentence ‘When Timer 3 Seconds Do Create Creatable Fish’. First click on the + next to when and select timer, now click the + after timer and select 3 seconds. For the do section click the + after do and select actions, within actions select create. Now click the + after create and select creatables (not this will not be available unless you have made the fish a creatable object). Finally within creatables click on the fish to select the fish we have programmed earlier. Escape out of the program screen and play the game to test it (don’t shoot the castle). Now get the children to do this.
Talk Partners – What happens when we hit the castle? Feedback and discuss. Explain that to fix the problem of the castle being destroyed and thus stopping any more fish from being created we need to make invulnerable. To this in the object tool right click in the castle and go to change settings. The seond option down is invulnerable. Click the on/off button to the left to turn it on. Get the children to do this now.
This will end the hour of code for lower ks2/yr2 you may wish to have a little challenge to see who gets the highest score within a time frame or extend the hour by following the steps below.
Now we have a working game but let’s make it even more interesting by making the fish shoot back. We are going to add a sentence to the fish saying ‘When See Cycle Do Shoot Missile Forward’. This make the fish shoot a missile when it sees the cycle you are controlling. Using the object tool right click on the fish and select program. Click on the + next to when and click on see. Click the next + after see and select bots I followed by cycle. Next click the + after do and select shoot. Click the + after shoot and select missile, now click the + after missile and select direction followed by clicking on forward. Get the children to do this now.
Talk Partners – What happens when you are shot? Feedback and discuss. We need to add a game end scenario for when you are shot. To do this we are going to add a sentence to the cycle saying ‘When Health 0 Points Do End’. Using the object tool right click on the cycle and select program. Now click the + after when and goto more followed by health. Click the + after health and select 0 points. Finally click the + after do and go to game followed by end. Get the children to do this now.
Finally all good games need a way for us to win. Let’s add a target score and a win scenario. We shall do this by getting the castle to keep track of the score and when the target score is reached to finish the game. To do this make sure you have selected the object tool and right click on the castle followed by program. We will create a sentence which read ‘When score 10 Points Do Win’. Click on the + after when and select scored. Click the + after scored and select 10 points. On the do side click the + followed by game and then win. Get the children to do this and test it.
This will end the hour of code for upper key stage 2
You can go beyond by changing the world, adding objects to hide behind, adding power ups, adding a timer or even adding more levels with different things.
Check out my Scratch Hour Of Code lesson for key stage 2 here
I’ve created a lesson to help teachers do the hour of code with key stage 2 children. This is a one off lesson that should last an hour but could be easily extended to go beyond the hour. The idea is create a game that where the player controls the diver to collect jewels. The lesson is below.
Tell the children we are going to use the computers to create a simple computer game. This is because we are doing an hour of code. This is something lots of schools are doing around the country.
We are going to use a website called scratch to do this.
Techie: Requires Flash v10.2.
Show scratch on your screen (you may want to create a shortcut on the computers to )
If the children haven’t used scratch before very quickly show them the basic areas (if you need help there are lots of videos on YouTube, the scratch website and there is a tutorial in scratch itself).
Explain that we are going to create a game where a diver has to collect the lost jewels. However he needs to be aware of the nasty shark.
Step 1 – Show how to add a background – click on the new backdrop from library button and filter to the underwater theme. Any of the 3 underwater backgrounds can be used. Now let the children do this. Give them 1 minute!
Step 2 – Now we have a background lets add a diver. First we need to use the delete tool (scissors) to remove the cat. Show the children how to do this. Now the cat is gone show how to add a new sprite from the library and again filter to the underwater theme. There are 2 divers to choose from. Now let the children do this. Give them 1 minute again!
Step 3 – Lets give the diver some movement instructions. We are now going to code the diver so he can move up, down, left and right. Show the children that by clicking on the diver the screen on the right changes. This allows us to edit him. Click on the scripts tab at the top this is the coding area. Explain that coding in scratch is done by dragging and connecting blocks (like making a jigsaw). These blocks are split into 10 different categories. Talk Partners – How can we control the diver, what inputs could we use? Feedback and discuss, bring the conversation round to using the keyboard and the arrow keys. Explain that we can tell the diver what to do when a key is pressed by using the events blocks. Show how to add an event block for if key is pressed and then select the right arrow from the dropdown list. Explain we now need to add some blocks under the event block to make the diver do something. Show adding a move block from the motion group. Explain that we also need to make sure he moves in the correct direction so we need to add the point in direction block and set it to right (90). Now press the right arrow key and see what happens. Get the children to add this set of blocks 4 times and change the dropdowns to represent the correct directions and keys for the up, left, down and right arrows. (Hint they could right click on a block group and duplicate it).
Step 4 – Now we have coded the diver to move around the screen. Talk Partners – What happens when the diver moves? Try it on their screens. Feedback and discuss he sometimes swims upsidedown. Explain that we have just tested our code and we have found a problem this is called debugging and it’s a very important part of creating code. So let’s fix the problem (bug). Show how to add a rotation style block from the motion categories and set the dropdown to left-right. To make this work we need to add it under a when green flag clicked event block. These event blocks make things happen when the program is first run. Get the children to add this to their code. Give them 1 minute!
Step 5 – Now our diver moves around let’s give him something to collect. Show how to add a sprite by drawing it yourself (explain that this is a simple paint program). Give the children 5 minutes to create a jewel sprite.
Step 6 – The diver now has a jewel to collect. Let’s give he jewel some code to make it randomly appear in different places and when the diver collects it to give the player a score. To do this we need to give the game a memory. This is called a variable and it will keep the divers score. Show the children how to create a variable called score and how to set the score to ‘0’ when the green flag is clicked. Let the children do this now.
Step 7 – The game now has a memory so let’s code the jewel to add on a score every time the diver touches it. To do this we need to use a sensing block called touching. Show this to the children. Explain that to make it only happen when the diver touches the jewel we have to use a wait until block with the touching block added in. After the wait until block we can add a change score by 1 block from the variable options. However his will only make the jewel add up once. We need to use a control block called forever now to make the jewel repeat (loop) through the code forever. Put the wait and change blocks inside the forever loop and connect it under the set score block on the when green flag clicked event. Show this on your screen and now let the children do it.
Step 8 – The last thing we need to do with the jewel is make it randomly appear and disappear when touched to stop the score going up to quickly. To make the block randomly appear we can use a motion block called go to x: y:. Explain this will set the exact position the jewel appears. To make it random we need to use a pick random block from the operators section. Explain that the center of the screen is x: 0, y: 0 and the numbers go down or up from there. You can see the x and y values when you move the mouse around the screen. Show this to the children now. Ask the children What’s the lowest number, what’s the highest number as you move the mouse to the edge of the screen. Explain if we used these values the jewel may appear of the edge of the screen so let’s pick a random number between -200 and 200 for both x and y using the pick random block inside the go to block. This now needs adding into the forever loop above the wait until block. Get the children to do this now.
For Lower Key Stage 2 your hour of code may end here. However you could carry on and extend your hour by following the steps below. Upper Key stage 2 should be able to fit these steps into there hour.
Step 9 – Let’s check our work. We now have a diver that swims and when he collects (touches) a jewel he gets a score of one. Also the jewel moves every time it’s touched to stop the score from going up really quickly and to make the game a bit harder. So let’s add the shark. Add a new shark sprite from the library using the underwater theme. Now we have the shark let’s make him follow the diver. To do this we need to add a block called point towards and select the diver from the list. Now the shark will always point to the diver. To make it move towards the diver we now need to a move block. Finally we want this to happen all the time so we need to add a forever loop around the blocks and to make it start when the game starts we need to add a when green flag clicked block. Let the children do this now.
Step 10 – Now we have a shark that follows the diver however what happens with the shark now. Talk Partners. Feedback and discuss. Steer the discussion towards the fact that the shark moves very quickly and sits on top of the diver. Let’s fix this. First we need to slow the shark down from moving 10 steps to 2 steps. We can also add a wait 1 second block from the control section under the green flag block. This will give the player time to get started. Some children have also noticed that the shark swims upside down when going to the left. To fix this add a rotation style block before the wait and under the green flag blocks. Let the children do this now and test.
Step 11 – So now the shark moves a bit slower and the game is a bit easier. Let’s add some code to take 5 points away when the shark bites (touches) the diver. To do this we need to add an IF block. Explain that this carries out a test and if the test results in true it follows some extra code otherwise the code is ignored. From the control section drag in the IF Then block. Inside the If then block add a change score by block and change the number to -5. Finally add a touching block from the sensing section and it to the If block so it reads ‘If touching diver then’. Get the children to do this now.
Step 12 – What happens when the shark touches the diver. Talk Partners. Feedback and discuss. Steer the discussion towards the score goes down very quickly. Let’s fix this by pausing the shark. Instead of just using a wait command though let’s make him say something. Add a say for 2 secs block from the looks section and change the words to say ‘Yum Yum’. Now add this block below the change score block. Get the children to do this and test their games.
This should complete the hour of code for Upper Key Stage 2.
However you can go beyond the hour by adding a timer, power up options or sounds.
Look out for my Hour Of Code – Kodu Lesson coming soon.