+ All Categories
Home > Documents > Lesson 7 Traffic Lights - Chulmleigh ICT...

Lesson 7 Traffic Lights - Chulmleigh ICT...

Date post: 24-Jan-2021
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
9
Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights Introduction to Scratch Programming (2 nd Edition) Page 1 of 9 © ZigZag Education, 2013 Lesson 7 – Traffic Lights What you will learn: how to set variable values to strings (sets of characters instead of numbers) how to use IF… ELSE… how to use Boolean logic NOT Contents Exercise 1: Creating the Traffic Light Sprite ...................................................................................................2 Exercise 2: Drawing the Road ........................................................................................................................3 Exercise 3: Introducing the Cars ....................................................................................................................5
Transcript
  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 1 of 9 © ZigZag Education, 2013

    Lesson 7 – Traffic Lights

    What you will learn:

    how to set variable values to strings (sets of characters instead of numbers)

    how to use IF… ELSE…

    how to use Boolean logic NOT

    Contents

    Exercise 1: Creating the Traffic Light Sprite ................................................................................................... 2

    Exercise 2: Drawing the Road ........................................................................................................................ 3

    Exercise 3: Introducing the Cars .................................................................................................................... 5

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 2 of 9 © ZigZag Education, 2013

    Exercise 1: Creating the Traffic Light Sprite

    1. Open a new Scratch Project. 2. Delete the cat. 3. Click the Paint new sprite option below the stage. 4. Draw the traffic light as shown.

    5. Working on the Costumes tab, make three copies and set the colours in each costume as shown.

    Name each costume as shown: green, amber, red, and

    redamber.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 3 of 9 © ZigZag Education, 2013

    Exercise 2: Drawing the Road

    6. Click on the stage icon and draw a new background. 7. Draw the road layout as shown.

    8. Make a variable called leftright.

    9. Still working on the stage, create the script as shown.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 4 of 9 © ZigZag Education, 2013

    10. Working on the traffic light sprite, create the script as shown.

    11. Now make three copies of the traffic light script and position them on the stage as shown.

    Check that the lights cycle through in the correct order before you continue.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 5 of 9 © ZigZag Education, 2013

    Exercise 3: Introducing the Cars

    12. Click the Choose new sprite from file option and get two cars as shown. 13. Resize the sprites to an appropriate size.

    We want the sprites to stop and start according to the lights.

    14. Make variables called gostop1 and gostop2.

    Remember: We want the sprites to start at opposite sides of the screen. We want the sprites to stop when the lights are not green.

    The thick white line around the area where the roads cross is very important.

    Choose new sprite from file and reduce size buttons as

    shown.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 6 of 9 © ZigZag Education, 2013

    15. Working on the first car sprite, create the script as shown.

    16. Working on the second car sprite, set the script as shown.

    This sets the variable gostop1 to go.

    If gostop1 = go, then the sprite will move 9 steps; if not (else), it will move zero steps.

    This sets the start position in this case to the left of the road (you have to decide the best position in your own project).

    If the car is touching the white line AND the lights are NOT set to green, then the variable sets to stop and the car stops.

    This sets the variable gostop2 to go.

    If gostop2 = go, then the sprite will move 9 steps; if not (else), it will move zero steps.

    This sets the start position in this case to the right of the road (you have to decide the best position in your own project).

    If the car is touching the white line AND the lights are NOT set to green, then the variable sets to stop and the car stops.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 7 of 9 © ZigZag Education, 2013

    The cars shown now go on the green lights.

    They stop at the white line on the red and amber lights (lights NOT green).

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 8 of 9 © ZigZag Education, 2013

    Extension Task – Setting the Lights for the Opposite Direction 1. Make a new variable called updown. 2. Working on the stage, create a new script that sets the variable updown to the opposite settings as

    the variable leftright.

    3. Copy one of your existing traffic light sprites and change the script as shown.

  • Introduction to Scratch Programming v1.4 (Second Ed) 7 – Traffic Lights

    Introduction to Scratch Programming (2nd Edition) Page 9 of 9 © ZigZag Education, 2013

    4. Copy your new up/down traffic light three times and arrange them on the stage as shown.

    Now introduce new sprites for cars travelling on the up and down road.

    What about pedestrians safely crossing?


Recommended