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 Power Ups

Transcript

In this add on, you will create a power up that makes a racer shrink so it can avoid obstacles more easily.

To start, click the choose sprite button to add a new sprite to be your power up.

You can choose any sprite.

In this example, we'll use an apple.

Make the sprite the right size for your game.

Then, name it power up.

To make the power up sprite move across the screen like the obstacle sprite, copy all the code from the obstacle sprite to the power up sprite.

First, select the obstacle sprite.

Then drag each code stack over to the power up sprite.

When you select the power up sprite, you'll see that all the code has copied over.

The power up only has one costume, so get rid of the switch costume's two block at the top of the stack.

Drag the bottom part of the stack away, drag the block back into the block menu, then snap the rest of the stack back together.

Test your code by clicking on the flag.

Great, the power up sprites are moving across the stage along with obstacle sprites.

Next, program the racer to shrink when it touches the power up.

Select the racer, then open the looks menu and drag out a change size by 10 block.

Change it's value to negative 10, then click on the block to see what happens.

The sprite shrinks a little bit.

To make it grow again, click on the change size by 10 block in the blocks menu.

Great, put that block underneath the change size by negative 10 block and click the stacks to try it out.

The sprite doesn't look like it did anything.

It's changing sizes too quickly for you to see.

Make the sprite wait a little bit before it switches back to it's normal size using a wait block.

This example uses a wait value of three seconds.

Use any value that works for your project.

Click on that block stack to see the sprite shrink, wait, and then grow again.

Next, add an if statement around this stack.

Add a touching block from the sensing menu to the if block condition, and select power up from the drop down menu.

Add the entire stack to the forever loop below the other if block, then click the flag to test it out.

The sprite shrinks when it touches the power up, but there's one problem.

You can't control the sprite when it's shrinking.

The go to block and the shrinking blocks aren't running at the same time.

To fix this, add another block stack beginning with one flag click, and a forever block.

Move the if statement stack from the old forever loop to the new forever loop.

Test the code again.

Great, your power up works.

Lastly, the power up sprite should appear less frequently.

Power ups are a rare treat.

Select the power up sprite and place higher numbers in the wait and pick random blocks.

This example uses pick random five to ten seconds, but tweak these values until you're happy with your game.

Alright, here's the game plan.

First, add a power up sprite.

Next, make the sprite move across the stage by copying the code from the obstacle sprite.

Make the racer shrink when it touches the power up sprite by using the change size by, wait, if then, and touching blocks.

Finally, adjust how often a power up appears by tinkering with the value in the the pick random block.

Choose an Add-On
Keeping Score
Keep track of how long a racer stays alive and display the score.
Extreme Tricks
Program your racer to do a cool trick at the press of a button.
Power Ups
Create a power up that shrinks the racer.
Crash Sound
Add a sound that plays when the racer crashes into an obstacle.
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an add-on, and click "Watch" to learn how to customize your project.
  2. When you finish, come back to the add-ons screen and try another add-on!