Skip to content

Please update your browser

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

Transcript

In this game, the computer controls the enemies. But, in this screencast, you’ll program the enemies so they can be controlled by a second player. You should only complete this screencast if you haven’t already programmed the other 2-player option.

You have already completed some of the programming for the sharks. Right now, every time a new clone appears they point in a random direction, then keep moving in whichever direction.

If a shark hits the edge of the screen, it bounces, then keeps moving forward again.

You still want the sharks to act like that, but now you also want them to move when a player presses keys. Often, in two-player games when player 1 uses the arrow keys, player 2 uses the leters W, A, S, and D, with “w” meaning “up,” “a” meaning “left,” “s” meaning “down,” and “d” meaning “right.”

Try programming a single key first, like the “a” key.

First, click on the shark sprite.

Then, select a “when key is pressed” event and change the value to “a.”

When the 'a' key is pressed, the sharks should turn left. So, select a “turn” block from the motion menu.

Before going any further, test your code to make sure it works.

When you press the green flag, the first shark should bounce around the screen, just like it did originally. But, when you press the “a” key, it should turn left. It does! Great.

Now that you created code for turning left and you know that it works, you can use similar code to make the shark turn right.

You can duplicate your block stack to make it easier.

Change the "turn" block to a right turn.

Then, change the key to “d.”

Now, it’s time to test the code again.

Perfect! The shark moves, and when you press “a” it turns left. Press “d,” and it turns right.

As the game progresses, player 2 builds a larger swarm of sharks, and all additional clones are also controlled by the “a” and “d” keys.

Great!

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 !