Tuesday, January 14, 2025

CS Inspired by Literature #WAOTL Challenge 3 - Adding and Controlling a Diver Sprite

In  my recent posts, I introduced a #WAOTL series where you and your students experience computer science by using Scratch to create and code an interactive experience with bioluminescent characters from the children's book "Whose Afraid of the Light" by Anna McGregor.  

Here are the posts in the series so far

Today's post will introduce Challenge 3 where we will learn to code a new DIVER sprite that you can move through the deep ocean with your arrow keys. The Diver will explore the 'balls of light' in the ocean to discover  the sea creature that each ball of light belongs to. 

By completing this challenge you will  create confidence with code using the following blocks; the challenge will be divided into two parts. 






Let’s get started by adding a diver sprite to your Scratch project from the last challenge.
Click on the purple Choose a Sprite bar and use the MAGNIFYING glass to search for a sprite from the library of sprites built into SCRATCH.  Type in the word DIVER and choose the one you want. 
You can resize the diver by changing the SIZE from 100 to whatever size you prefer. 
You can also drag the diver around the screen to position it to a new location.


 We will now Code the Diver by dragging out 4 copies of the EVENT block "When Space Key is Pressed. 
We would like to control the Diver Sprite with the 4 arrow keys.  You can do this by clicking on the little black arrow next to the word SPACE and selecting a different arrow key for each of these 4 Event Blocks. Your code blocks for the diver should look like this. 


Pull out 2 more blue code blocks



Does your code look like this?

Can you add code to the other 3 Event blocks so that the Diver moves
in the same 
direction as each arrow Key for each of the 4 events. 

Teachers might use an unplugged game to help the students learn how the POINT in DIRECTION block works. 


Now that you understand how to CODE an ALGORITHM when an EVENT occurs, 
 there are so many cool games and projects you can create.   
You are now ready for the second part of Challenge 3 where. you learn to use IF .. THEN logic.  

Let's change from coding the diver to coding one of your sea creature sprites.  Click on the sea creature sprite you want to code.  Let’s add some code to your  sea creature so that when the diver touches its light, the sea creature costume changes from "light only". to the costume showing the sea creature with the light on and  starts to blink.  

We’ll need to drag out this SENSING block, and change it from ‘touching  mouse pointer”to “touching Diver”
Make sure you are in the CODE section for the sea creature (not the diver)


Now let's add some IF .. THEN logic to our code. 


Now here is a challenge for you.  Your goal is to move the algorithm that made our sea creature blink inside the IF THEN block. 

Start by pulling  the FOREVER BLOCK. away. Look at your blinking animation code. 


See if you can rearrange these blocks so that when the Green Flag is pressed, the program is forever checking to see if you are touching the diver.  If the answer is YES to the question (Are you touching the diver) then the sprite should blink.

Chat with a classmate and experiment.  This is called PAIRED PROGRAMMING and is used by computer scientists every day in their job. 



Test your program.  If you got it right.  Let’s code the rest of the sea creatures with the same code. 

Test your program again.  Debug any unexpected results.

Are you ready for another challenge?

What would you like to happen to your Sea Creature Sprite 
when the Diver is NOT Exploring (Touching) it?



Here is a sample  Scratch solution  to this challenge. Click "SEE INSIDE" to compare this solution to the ones you and your classmates have come up with.  Remember that there are many different ways to solve these challenges. 

What type of game play rules  might add in future lessons?  How do you know if you WIN or LOSE the game? What would you like to happen if you WIN or LOSE? 

What if you trade computers  with your class mates and see who can explore all 4 sea creatures first.

Congratulations! You have mastered some important computer science concepts that computer scientists use every day.  Stay tuned for Challenge 4 where we will learn to change the backdrop and add sound to our project. 



Here is a teacher guide to Challenge 3

You can subscribe to this blog to get notified when the next challenge is posted.

Originally created for  CSTA-Vermont during Computer Science Education Week 2024

CS Inspired by Literature © 2024 by Lucie deLaBruere is licensed under CC BY-NC-SA 4.0






No comments:

Post a Comment