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 Play with a Friend Option 1

Transcript

In this add-on, you'll create a second player that will be controlled with a different set of keys.

Complete this add-on only if you haven't already programmed the other two-player option.

The Player 2 sprite will have a lot of the same code as the first-player sprite you programmed.

So copy the Player 1 sprite.

Right-click the sprite, and select Duplicate.

Next, change the appearance of Player 2.

Click the Costumes tab, then Choose New Costume from Library.

Pick a costume.

To delete the other costume, click the X next to the costume.

Click the flag and the arrow keys to test.

Oh no!

Player 2 turns when the arrow keys are pressed, just like Player 1.

That's a bug.

Two players using the same keys won't work for this game.

Two-player computer games generally use the W, A, S, and D keys for the second player.

In the dropdown menu, change the left-arrow key to A and the right-arrow key to D.

Test your code.

Great!

Now the two sprites are controlled by different keys.

But they still start right on top of each other, which is a little weird.

To fix this, set the sprite starting position.

The code currently reads, when the flag is clicked, set the score to zero.

Then go to a specific spot.

The spot where the sprite starts needs to change.

This example will make Player 2 start a little lower by entering Y equals negative 60.

When the fish is hit by a shark or touches the finish line, it goes back to a specific spot.

So, change that to y equals negative 60 as well.

Now, go back and make the other player start a little higher, maybe at y equals 60.

Click the flag to test.

There's another bug.

Both players only have one score.

To give Player 2 a different score, make a new variable called player 2 score.

Make player 2 score increase when it crosses the finish line by clicking the dropdown menu next to change score and selecting player 2 score.

Start player 2 score at zero by clicking the dropdown menu on the set score to 0 block and selecting player 2 score.

Test your code.

Perfect.

Both players can score points.

Now it's your turn.

Add a new sprite and program the sprite to move with its own set of keys.

Set the sprite score and starting position, then ask your neighbor to play your game.

Choose an Add-On
Finish Line Cheer
Program a sound to play if the player touches the finish line.
Play with a Friend Option 1
Add a second player to the game.
Play with a Friend option 2
Challenge a friend by having them control the enemies.
Shrinking Finish-Line
Program the finish line to get smaller as the player scores more points.
Bonus Points!
Create a sprite that, when touched, gives the player extra points.
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!
Attributions
  • The song “Magic Marker” is © YouTube-- CC-BY-SA 4.0 does not apply.