Teach Primary Issue 19.6
player’s sprite is touching the star sprite. If it is, then we are going to hide the star sprite. Ask children if they can think of other instances of cause and effect. Discussing real-world IF/THEN statements can help them to grasp this new concept. Traffic lights are a good example: IF the light is red, THEN stop. There are lots of others. Show them the IF/THEN block and explain that this is how Scratch programs choose a course of action. Add the <Touching> block and choose Sprite1 to allow us to check for contact between the two sprites. The children will quickly find that this code doesn’t quite work! Debugging is a key skill, so invite them to try and work out why. The program fails because we are only running the collision detection algorithm one time. When you click the green flag, it checks to see if the player’s sprite is touching the star, and then it stops checking. For the game to work, that collision detection algorithmmust be running constantly. That will bring us to the concept of loops in week 3. Assessment Can children offer real-world examples of IF/THEN logic? Can children build a conditional statement in Scratch? Can pupils explain what debugging means? WEEK 3 Learning objective l Use loops to check for collisions, and to create multiple stars As before, it is worthwhile recapping on the key vocabulary we have covered so far: X/Y axes and IF/THEN statements. Reintroduce the concept of debugging and reflect on the code from lesson 2. Did we figure out why the code didn’t work? Howmany times is the star checking to see if it is being touched by the player’s sprite? Now, we can fix the code for the star sprite. Explain that loops are blocks that enable us to repeat instructions in our code. Instead of writing the same code lots of times, we use a loop to repeat it for us. There are different kinds of loops, but in this game we are only going to use the forever loop. Show the children how the code flashes once when we click the green flag. If we put the IF/THEN block inside a forever block, it will remain lit when we run it. That means it is continuously checking to see if the two sprites are touching. Explain that if we hide the star sprite when it comes into contact with the player’s sprite, the star will remain invisible even if we re-start the game. Scratch sprites don’t automatically reset or become visible at the start. If you hide something, Scratch assumes you intended to keep it hidden. The solution is to make sure we show the star sprite when the game starts. Assessment Can children make predictions based on their existing understanding of creating sprites? Can they explain why we might need to use loops in our code? WEEK 4 Learning objective l Create a variable to keep track of our score Begin with a recap of loops. Questions might include: What does a loop do? Why do we use them? Revisit the code from lesson 3 and review our progress so far. For this to be a real game, we need to keep score. This brings us to the introduction of variables . Children encounter variables in science, so they may already understand that variables are things that we can change. In coding, a variable is like a box with a value stored inside. Imagine a box labelled ‘score’, and inside we have a value of 0. If we earn a point in our game, the name of the variable remains the same, but the value inside increases by 1. This can be a difficult concept for children to grasp, so encourage plenty of discussion and lots of real-world examples, such as keeping score of team points on sports day: the variable is the team name – like Red, Blue or Green – and the value is the number of points they have, which goes up as they win events. The name doesn’t change, but the value attached to it does. To create your score, go into the ‘Variables’ section and choose Make a Variable . Variables should always have meaningful names, so we will call it ‘Score’. We will then add a new [when green flag clicked] event block and connect [Set my variable to 0] to it. With the drop-down arrow, select ‘Score’. Now that we have our score on the screen, we need to add some code to increase our score each time we catch a star. Go into the code for the star sprite. Explain that we are going to add the [change my variable by 1] underneath the [hide] block, remembering once again to click the drop-down arrow and select ‘Score’. Run the game and demonstrate that the score changes when the player’s sprite touches the star. F EATURE S S C I ENC E www.teachwire.net | 31
Made with FlippingBook
RkJQdWJsaXNoZXIy OTgwNDE2