3. Interactive Sprite-Controlled Turning for the Zeus Car

In this lesson, we’ll dive deeper into controlling the Zeus Car by learning how to program it for clockwise and counterclockwise turns. You’ll also learn how to use sprites as interactive controls, enabling dynamic programming and user-friendly interaction with the Zeus Car.

This lesson builds on your knowledge of movement blocks and introduces the use of broadcast messages to manage communication between sprites and the Zeus Car.

With these new skills, you’ll be able to create a more interactive and visually engaging project, bringing your Zeus Car to life in exciting ways!

../_images/zeus_turn_left.jpg ../_images/zeus_turn_right.jpg

You Will Learn

  • Program the Zeus Car to turn clockwise and counterclockwise using blocks.

  • Control the Zeus Car with sprites like arrows and stars.

  • Broadcast messages to coordinate actions between sprites.

  • Create interactive scripts using blocks and events.

Turn Clockwise and Counterclockwise

Now let’s learn how to program the Zeus Car to turn in both clockwise and counterclockwise directions. There are two blocks used for controlling rotation.

1. “turn (Clockwise) (1) secs” Block

  • This block allows the Zeus Car to turn clockwise or counterclockwise for a specified number of seconds.

    ../_images/3_code_turn.png
  • Drag the “turn (Clockwise) (1) secs” block from the Zeus Car category into the script area.

    ../_images/3_code_turn_drag.png
  • Click the block, and you will see the Zeus Car turn clockwise for 1 second and then stop.

    ../_images/zeus_turn_right.jpg
  • You can also select “Anticlockwise”. After clicking the block, the Zeus Car will turn counterclockwise for 1 second and then stop.

    ../_images/zeus_turn_left.jpg

2. “turn (Clockwise)” Block

  • This block makes the Zeus Car continuously turn in a clockwise or counterclockwise direction without stopping.

    ../_images/3_code_turn_no.png
  • To stop the car after a specified duration, you need to add a “wait (1) seconds” block followed by a “stop moving” block.

    ../_images/3_code_turn_stop.png

Controlling Zeus Car Turns Using Sprites

In this section, you will learn how to use sprites to control the Zeus Car’s clockwise and counterclockwise turns, as well as stopping its movement.

  • Use two Arrow sprites to control the Zeus Car’s clockwise and counterclockwise turns.

  • Use a Star sprite to stop the Zeus Car’s movement.

../_images/3_code_star_arrow.png

1. Adding Arrow Sprite and Programming it

  1. Click the delete icon on the top right corner of the default sprite.

    ../_images/3_code_delete_sprite.png
  2. Click Choose a Sprite.

    ../_images/3_code_choose_sprite.png
  3. Select the Arrow sprite.

    ../_images/3_code_arrow_sprite.png
  4. Rename this sprite to Right, and optionally adjust its size.

    ../_images/3_code_right.png
  5. Program the Right Arrow Sprite:

    • Drag the “when this sprite clicked” block from the Events category into the script area. Program the Zeus Car to turn clockwise when the Right Arrow sprite is clicked.

      ../_images/3_code_click_sprite.png
    • Use the “broadcast message1” block to send a custom message. This allows other sprites to respond to the action.

      ../_images/3_code_right_turn.png
    • Click the dropdown menu and select New message.

      ../_images/3_code_broadcast.png
    • Finally, naming it “right”.

      ../_images/3_code_broadcast_right.png

2. Duplicate the Arrow Sprite

  1. Long-press the Right Arrow sprite and select Duplicate to create a copy. This also copies its scripts.

    ../_images/3_code_arrow_copy.png
  2. Rename the duplicated sprite to Left, and adjust its position.

    ../_images/3_code_arrow_left.png
  3. Select the Left Arrow sprite, then go to the Costumes tab. Set its costume to arrow1-b.

    ../_images/3_code_arrow_cos_b.png
  4. Modify the script so that when the Left Arrow sprite is clicked, the Zeus Car turns counterclockwise and broadcasts the “left” message.

    ../_images/3_code_arrow_left_message.png

3. Adding the Star Sprite and Programming It

Next, you’ll program a Star sprite to control the Zeus Car’s movement based on received broadcast messages, and stop its movement when clicked.

  1. Choose the Star sprite from the library and increase its size.

    ../_images/3_code_star_choose.png
  2. Write a script so that when the Star sprite is clicked, the Zeus Car stops moving.

    ../_images/3_code_star_sop_all.png
  1. Handle Broadcast Messages:

    • Drag the “when I receive (left)” block from the Events category into the script area.

      ../_images/3_code_star_receive.png
    • When the Star sprite receives the “left” message, it will also rotate counterclockwise.

      ../_images/3_code_star_turn_left.png
    • Similarly, program the Star sprite to rotate clockwise when it receives the “right” message.

      ../_images/3_code_star_turn_right.png
  2. Add the “stop (other scripts in sprite)” block to each action to prevent interference between different scripts.

    ../_images/3_code_start_stop_other.png
  3. Adjust the sprites’ positions on the stage. If the Zeus Car is successfully connected to the app, you will observe the following setup:

    • When you click the Left sprite, both the Zeus Car and the Star sprite turn counterclockwise simultaneously.

    • When you click the Right sprite, both the Zeus Car and the Star sprite turn clockwise simultaneously.

    • When you click the Star sprite, both the Zeus Car and the Star sprite stop turning.

    ../_images/3_code_star_arrow.png
  4. Finally, remember to save this script.

Summary

In this lesson, you learned how to use blocks to program the Zeus Car for clockwise and counterclockwise turns. You also explored how to use sprites like Arrow and Star to control the Zeus Car’s movement dynamically. With this knowledge, you can now create interactive projects and customize the behavior of your Zeus Car!