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 Jouer avec un ami

Transcript

A game that’s fun for one person can be even more fun for 2! In this screencast, you’ll create a second player sprite that will be controlled using the W, A, S, and D keys on the keyboard. You should only complete this screencast if you haven’t already programmed the other 2-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 by right clicking it and selecting “duplicate.”

It will be hard to tell which player is which if both players look the same.

To change player 2’s appearance, click on the costumes tab, then “choose new costume from library.” Pick a costume and click ok.

You may want to click the x to delete the other costume, because you won’t need it for this project. Right now, player 2 is programmed to turn when the arrow keys are pressed, just like player 1. That won’t work – two players can’t control 2 different sprites using the same keys.

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

First click on the scripts tab, and change the left arrow key to “a” and the right arrow key to “d.”

Test your code.

Did that work? Great! Now the two sprites are being controlled by different keys.

The "go to" block at the end of the space key block stack tells the sprite where to start.

In this case, the sprite starts at -222 and 3.

You should make your sprite start somewhere different.

Change the y-value in your "go to" block to something different.

In this project, the sprite will have a value of -100, but you can make it whatever you want!

Ok! That looks much better. Wait! both players only have 1 score!

To give player 2 a different score, you’ll need to make a new variable to store player 2’s score. You can call this one “player2 score.”

Now, when player 2’s sprite crosses the finish line, you need to make sure player 2’s score goes up, instead of player 1’s.

To do that, click the drop down menu next to “change score by,” and select “player2 score”.

Then, start player 2’s score at 0 by clicking the drop down menu at “set score to 0” and selecting “player 2 score.”

What happens when you test it now?

Good! Both players can score points now.

Choisir une extension
Hourras de la ligne d'arrivée
Programme un son à jouer si le joueur touche la ligne d'arrivée.
Jouer avec un ami
Ajoute un second joueur au jeu.
Défier un ami
Défie un ami en le laissant contrôler les ennemis.
Réduire
Programme la ligne d'arrivée pour qu'elle rapetisse à mesure que le joueur marque des points.
Points bonus !
Crée un lutin qui, lorsqu'il est touché, apporte au joueur des points supplémentaires.
Changer la conception des niveaux
Programme l'arrière-plan pour qu'il change chaque fois que le joueur marque 5 points.
arrow_backward Retour
Suivant arrow_forward
Instructions
  1. Clique sur l'une des fenêtres pour accéder à la vidéo sur les extensions.
  2. Quand tu as fini, reviens à la page des extensions et essaies-en une autre !