Swim across the Ocean

Overview

  • Program the Orca to swim left and right across the ocean.

Objectives

  • Become familiar with visual programming.

  • Program the Orca to swim using basic motion commands.

  • Learn coordinate system with direction (0-360 degrees) and distance.

  • Understand sequential execution of commands, conditionals (if-then), and variables.

Steps

Create a Orca Project

  • Open Tickle app and go over the welcome tutorial that shows you how to drag and drop coding blocks. You can replay the tutorial in Settings -> Show Introduction as needed.

  • If you don't already have a Orca project open, create a new one by tapping "+ New Project" in "MY PROJECTS". Choose the template with the name "Orca".

Let's Swim to the Right!

  • In order to make Orca move across the screen, add the block forever to When starting to play. Then add the block move 10 steps inside the forever block.

Swim Left and Right

  • We use a variable to remember the direction the Orca should swim in. In computer science, a variable is a symbolic name associated with a value and whose associated value may be changed.

  • To add a new variable named "Direction" in this project, tap the + Add Variable button and type in the variable name "Direction".

  • To set the variable "Direction", you have to use the block set ... to ... in the newly added Data category. Here we initialize the variable to 1, to represent the direction right, and put it right below the block When starting to play.

  • Here we make use of the conditional block called if ... then, and put it into the forever loop. When the condition in the if ... then block occurs (ie. evaluates to TRUE), then the code inside that block runs; otherwise, none of the code inside runs.

  • Then we make use of one of the Sensing blocks called touching edge?, and put it inside the if ... then block. When the Orca touches an edge of the stage screen, the condition in block if ... then returns true and the code inside it runs.

  • To make Orca move in the opposite direction, change the variable "Direction" into its opposite value using the multiplication block in Operators, and typing in value "-1" (ie. Direction * -1):

  • Back inside the conditional block if ... then, now you can set the variable "Direction" with block set Direction to (Direction * -1). Remember to add the block flip horizontal to flip your Orca, otherwise it will swim backwards.

  • Change the block move 10 steps into move (Direction * 10) steps to make Orca move toward the right direction.