Objective 2

Objectives for today’s class: Students will learn how to make a Sprite repeat on the screen similar to a game of Crossy Road.

Outline:

  • Robot controller game
  • Hands on Simulation: Sunday Drive
  • Checkpoint Activity
  • Creative Time

—————————————————————————————

Activity 1: Robot Controller Game 

  • Ask students– So what’s an Event?
    • An action that causes something to happen
  • Mention to the class the following – “I’m going to ask you a question. Raise your hand if you want me to call on you for the answer.”
    • Ask a simple question:
      • How many students are there in the class?
      • What color is the sky?
    • Call on a student who has their hand raised and let them give their answer.
    • Upon finishing that display, ask the class how you knew that the student wanted you to call on them.
      • Your class will likely mention the raising of the hand.
    • Explain to everyone that when students raise their hand, it is an “event” that causes you to know that they want to be called on.
  • Ask students can you think of any other events that gives signals
    • You may need to remind them that you’re not talking about an event like a birthday party or a field trip.
    • If they have trouble, you can remind them that an event is an action that causes something to happen.
      • What about an alarm clock going off? What does that make happen?
      • What about pressing “Start” on the microwave? What does that do?
      • What about pressing the power button on your tv remote?
  • Today, we’re going to create programs with events.
  • Do you remember displaying different LED images on the micro:bit or displaying strings?
    • In those activities, you knew in advance exactly what you wanted to display with the LED images or what strings to display
    • In most real programs, we can’t do that because we want to have options, depending on what the user needs.
      • Say that I only want to display an image when I shake the micro:bit or when I press button A

What happens when you don’t know everything that you want your friend to do in advance? This is where events come in!

  1. Project the Event Controller onto your classroom screen and zoom in so the controller is in full view.
  1. Pick on 3-4 students from the class to take turns deciding what control each button has. Start with one student and give them the power to decide what each button does then repeat with a few more students. Here are some examples (make sure they’re safe for a classroom setting so no student gets hurt- avoid cartwheels or any harder movements for the students):
    • Pink Button -> Do a dance
    • Teal Button -> Clap your hands
    • Purple Dial -> Spin around
  2. Practice having the student in charge of the actions or yourself as the instructor tap the buttons on the screen and having the class react.
  3. Add some button sequences into the mix and have the students try to keep up with the actions.
  4. Let your class know that every time you push a button, it is an “event” that lets them know what they are expected to do next.
  5. Get the class started on a planned task before interrupting them again with the buttons. We suggest:
    • Counting to 10
    • Singing their favorite song as a class
  6. Once their plan is underway, interject button presses sporadically.
  7. Continue the blend until they understand the difference between actions that are guided by a plan and those that are event driven.

Activity 2: Crazy Cars

  • Games often need actions to occur repeatedly – enemies and collectibles need to be created, winning conditions need to be checked, and so on. The `on game update interval` event allows you to set code to run on a set time period, so that it will occur repeatedly.

Instructors should watch the video tutorial which demonstrates how to complete the checkpoint activity ahead of time and create the file. Instructors should show students the output of the code to give them an idea of what they will be developing.

  • Remove anything that is currently in the workspace, and find on update interval 500 ms in Game. Drag it into the workspace.
  • In the on game update interval 500 ms, replace the 500 with 1000. This will make it so the event occurs once every second, because 1 ms is a thousandth of a second.
  • Find projectile from side in Sprites, and drag it into the on game update interval. Open the image editor for projectile, and select or create an image of a car that is facing right
  • In the projectile, set the vy to 0, so that the cars drive only to the right.
  • Find set mySprite x to 0 from Sprites, and drag it after the set projectile to. Change mySprite to projectile, and change x to y.
  • Find pick random 0 to 10 in Math, and replace the 0 in set projectile y to 0 with the it. This will place the projectile in a random y position between 0 and 10
    • Ask each student in the class to pick a random number from 0 to 10? Write their answers on the board and discuss what a random number means. 
  • Find screen height in Scene. Replace the 10 in pick random 0 to 10 with it. screen height is the height of the screen (120), so this will place the projectile in a random position on the left side of the screen.
    • Explain to students that we want cars to randomly appear on the screen and we use screen height, because we want cars to appear at different positions in the screen – not all from one place or else it gets boring! 
    • Show them the final output and have students point out the different heights that the cars are coming from. 
  • Wow, you have made cars randomly drive across the screen! You can use this to start your own version of a road crossing game – for example, the game crossy road with the chicken who’s crossing the road to get to the other  side. 

Activity 3: Crazy Ducks Checkpoint 

  • Ask students who’s ready to try this on their own now! 
  • This is a perfect time for students to test their knowledge of the concept they just learned! Instructors should create the code for the checkpoint ahead of time and show students what the final outcome looks like to give students the space to ask questions and see an example.
  • Don’t show students the answer, instead give them time to explain the task either by screen sharing or writing it on the board and make sure students clearly understand the outcome of the checkpoint.

Student Task: 

  • Instructors should watch both video tutorial which demonstrates how to complete the checkpoint activity as well as an enhancement ahead of time and create the file. Instructors should show students the output of the code to give them an idea of what they will be developing.
  • Before starting the simulation, ask students if they’ve ever heard of the game Crossy Road? Have they ever played it before?
  • Mention that today they will make a similar version of the game Crossy Road using MakeCode!
  • Create a new file and name it “Crazy Ducks
  • Similar to how we just made our cars move across the screen repeatedly – this time students will try it with ducks and have them move across the screen like crazy! You can set your own background – for example, create a pond, or even create a road for them to have the ducks cross 
  • Here’s a tip, if you forgot how to make the code, you can use the code we just made as an example and feel free to have it open and refer back to it! 

Enhancements to the checkpoints for those students done early and looking for a challenge:

Activity 4: Creative Time

Duration:  Remainder of Class Time

  • Once students are finished with the checkpoint activity and you review their work, give them time to pick their own themes, Sprites, and game objectives to design their own game. Encourage them to use the topic they learned in today’s class with sprite velocity and find ways to incorporate it into their game.
  • If students are stuck on idea help them brainstorm by asking them the following questions:
    • What is the theme of your game?
    • What is the game’s objective?
    • What’s the main character sprite?
    • Is there an enemy sprite?
    • Do you have any characters that keep looping through the game similar to how we explored it in class today?