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