h c t Ca e m a G




























- Slides: 28

h c t Ca ! e m a G g g E e Th Lesson 4

Outcomes Create a ‘catch the egg’ game, the egg is a single LED that ‘falls’ from the top of the micro: bit display and can be caught in a moveable basket at the bottom of the display. • By default, the first ‘egg’ LED starts to drop from the centre of the top line of the display. • The following ‘eggs’ will then fall from random positions at the top of the display • The ‘basket’ will be moved by tilting the micro: bit Which features are we using?

Recap! What do we call the numbers on the top and side of the LEDs? What is ‘var’ and what is it used for?

Concentrate and follow EVERY step. If you miss just one step your game will not work correctly!

Choose Touch Develop

When adding commands you can either: Type a command OR select from the blocks

Catch The Egg Game Step One Rename your script “catch the egg”

Catch The Egg Game Step Two, Three & Four THEN 8

Catch The Egg Game Step Five, Six & Seven What is a global variable? Name the variable ‘basket x’ THEN Be descriptive when naming variables! Don’t name them 1, 2, 3, etc. 9

Catch The Egg Game Repeat! Repeat Step Two to Step Seven to create two more global variables. egg x – to control the horizontal position of the egg y – to control the vertical position of the egg 10

Catch The Egg Game Assign a value to the variables As with any programming language, when we create variables, we have to assign an initial value to them. 11

Catch The Egg Game Step Eight, Nine, Ten & Eleven THEN We then type ‘ 2’ because we want the basket to sit at the bottom and centre of the LEDs Why don’t we need to enter a number for the Y axis? 12

Catch The Egg Game Repeat! Repeat Step Eight to Eleven so your code looks like the one below: Why have we set ‘egg x’ at 2, but ‘egg y’ at 0? 13

Catch The Egg Game Plot the LEDs By default, all the LEDs are set to OFF. We’re going to program the starting positions of our lights 14

Catch The Egg Game Step Twelve, Thirteen, Fourteen Repeat these steps to plot ‘basket x’ Where is the basket going to start when we run the program? 15

Catch The Egg Game Run It! Let’s check what we have so far works! It should look like this 16

Catch The Egg Game Step 16 - Forever Loop What is a forever loop? 17

Catch The Egg Game Step 17 What is a forever loop? 18

Catch The Egg Game Step Eighteen & Nineteen These steps are the same as when we turned the LEDs on, but this time we’re using the ‘unplot’ block so we can move the egg and the basket. 19

Catch The Egg Game Step Twenty – Drop The Egg 1 20

Catch The Egg Game Step Twenty One Why do we need to add a pause? 21

Catch The Egg Game Checkpoint! Your code should look like this so far: 22

Catch The Egg Game Step Twenty Two – Moving the basket This line goes ABOVE the pause What feature of the micro: bit are we going to use to move the basket? 23

Catch The Egg Game Step Twenty Two – Moving the basket This line goes ABOVE the pause What feature of the micro: bit are we going to use to move the basket? 24

Catch The Egg Game Step Twenty Four Change (0, 0)) / 200 25

Catch The Egg Game Step Twenty Five Create the following line below the one you just created 26

Catch The Egg Game Final Step! Twenty Six We need to create an IF statement that sends the egg back to the top when it ‘hits’ the bottom of the board. 27
