Back to Course
Class 6 - Coding, AI & Robotics Course
0% Complete
0/0 Steps
-
Coding
Session 1: Introduction to Coding3 Topics -
Session 2: Backdrop, Costume, and Animation3 Topics|1 Quiz
-
Session 3: Basics of Algorithm and Flowchart3 Topics|1 Quiz
-
Session 4: Basics of Pseudocode3 Topics|1 Quiz
-
Session 5: Getting Started with Quarky3 Topics|1 Quiz
-
Session 6: Variables: The Multitaskers4 Topics|1 Quiz
-
Session 7: Arithmetic Operators4 Topics|1 Quiz
-
Session 8: Conditional Statements3 Topics|1 Quiz
-
Session 9: Logical Operators4 Topics|1 Quiz
-
Session 10: Nested Conditional Statements2 Topics|1 Quiz
-
Session 11: Loops3 Topics|1 Quiz
-
Session 12: Touch Based Piano2 Topics
-
Session 13: Criterial in Loops5 Topics|1 Quiz
-
Session 14: Catch the Fruit Game - Part 12 Topics
-
Session 15: Catch the Fruit Game - Part 22 Topics|1 Quiz
-
Artificial IntelligenceSection 16: Introduction to Artificial Intelligence3 Topics|1 Quiz
-
Session 17: Basics of Face Detection2 Topics|1 Quiz
-
Session 18: Face Expression Detection2 Topics|1 Quiz
-
Session 19: Mimic Face with Quarky1 Topic
-
Session 20: Face Filter - Part 12 Topics
-
Session 21: Face Filter - Part 22 Topics
-
RoboticsSession 22: Basics of Robotics2 Topics|1 Quiz
-
Session 23: Wirelessly Controlled Robot2 Topics
-
Session 24: Introduction to Sensors3 Topics|1 Quiz
-
Session 25: Introduction to Actuators3 Topics|1 Quiz
-
Session 26: Face Tracking with Robot2 Topics
-
Session 27: Obstacle Avoidance Robot - Part 13 Topics
-
Session 28: Obstacle Avoidance Robot - Part 22 Topics|1 Quiz
-
Session 29: Edge Detector Robot - Part 13 Topics
-
Session 30: Edge Detector Robot - Part 22 Topics|1 Quiz
-
Capstone ProjectCapstone Project
Lesson 6,
Topic 4
In Progress
Activity: Tracking a Sprite’s Position Using Variables
Lesson Progress
0% Complete
In this activity, we will track the change in Tobi’s position using the up, left, down, and right arrow keys on the keyboard. We will track his X and Y positions using variables.
Follow the steps below:
- Open PictoBlox and create a New File.
- Select the coding environment as Block Coding.
- Create two variables X and Y. We’ll use them for Tobi X and Y positions respectively
- Change the background to Xy- Grid to visualize the position.
- Add the when flag clicked block to start the script.
- Next, set the X and Y positions as 0 by setting the X and Y variables as 0 using the set () to () block.
- Now, add a forever block below the when flag clicked block.
- Then, from the Motion palette, add a go to x:() y:() block and drag and drop the X and Y variable blocks inside it as shown. This will set Tobi’s position to the current value of X and Y.Now, to make Tobi move around and track his position, we need to change the values of X and Y. How do we do that? Here’s how:
- To move left, we will change X by -10 whenever the left key is pressed. Add a when () key pressed block from the Events palette and change X by -10 by using a change () by () block.
- To move right, we will change X by 10 whenever the right key is pressed. Repeat the above step and select the right arrow key from the drop-down of the hat block and change X by 10 in the change () by () block.
- To move up, we will change Y by 10 whenever the up key is pressed.
- For down, we will change Y by -10 whenever the down key is pressed
- Now run the script and enjoy it.
- Save the file with the name Tracking a Sprite’s Position Using Variables.
Assignment
Before you move on to the next lesson, a small assignment awaits you!
You must upload the PictoBlox program you created in this activity to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.
Follow the steps below to upload your assignment:
- Click on Browse.
- Search and Select your saved Project file(.sb3) and Click Open.
- Click on Upload to submit the assignment.
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.
Good luck!