Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Puppet Master

Transcript

In this add on, you'll make the sprite perform one dance move when one key on the keyboard is pressed and another dance move when another key is pressed.

First, add some more frames to your animation for your sprite's second dance move.

In this example, the first six costumes starting with penguin one make the penguin do the happy dance and the last 14 costumes starting with penguin disco one make the penguin do the disco walk.

Your dance moves and number of costumes will be different so keep that in mind as you follow along.

In this example, when the green flag is clicked the penguin does the happy dance, then the disco walk.

Modify this code to play only the first dance move, the happy dance.

Instead of looping through all the costumes, this program needs to switch to the first happy dance costume, loop through only the happy dance costumes, then switch back to the first happy dance costume, then loop through the happy dance costumes and so on.

To switch to the first happy dance costume, click looks and add a switch costume to block to the beginning of the forever loop.

Change the value in the dropdown menu to the first costume in the dance sequence.

In this case, penguin one.

Next, click control, drag your repeat 10 loop and place it around the next costume and wait blocks.

A repeat block is a loop just like a forever block, but it only repeats a specified number of times.

Since there are only six happy dance costumes and the loop is repeating 10 times, the penguin does the happy dance and a bit of a disco walk.

To make the penguin only do the happy dance, change the loop to repeat five times, which is one less than the number of costumes in the happy dance.

Great.

Now the penguin only does the happy dance.

You may need to switch the order of the wait and next costume blocks so that the wait block comes first.

This way, there is a wait between each costume change.

Next, change the when flag clicked block to a when key pressed block.

Assign this dance move to any key you like such as the one key.

Now, duplicate these blocks by right clicking and selecting duplicate.

In the second code stack, change the key costume and repeat number so that it will trigger the second dance move.

Press the second key and make sure the sprite does the second dance move.

It does.

Great.

Now, try switching between the two dance moves by pressing the two keys.

Hm, it doesn't seem to work, but it looks like the penguin is trying to do two dance moves at the same time.

In fact, that's exactly what it's trying to do since forever blocks never stop.

To fix this, click control and find the stop all block.

Change this block to say stop other scripts in this sprite using the drop down menu.

Then, attach one of these blocks to the beginning of each stack.

This block stops forever loops from running so the sprite only does one dance move at a time.

Test your code again using the keyboard.

Great, now the sprite does the happy dance when the one key is pressed and the disco walk when the two key is pressed.

Now it's your turn.

Add a few costumes to create your sprite's second dance move.

Modify your code so that it plays through only one dance move when a key is pressed.

Finally, duplicate that code to play through the second dance move when a different key is pressed.

Choose an Add-On
Where's the party?
Add a background and a music track for your dancer.
Bounce Around
Make the sprite bounce around the stage while it dances.
Dance Team
Create a party with dancing clones!
Controlled movement
Make the sprite move using the arrow keys.
Add More Dancers (Part 1 of 2)
Add another sprite to your dance, and learn how to draw your own panda sprite.
Add More Dancers (Part 2 of 2)
Add another sprite to your dance, and learn how to draw your own panda sprite.
Puppet Master
Learn how to switch between dance moves using different keys on the keyboard.
Interpretive Dance
Create your own dance that tells a story.
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!