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 add-on, you’re going to do something completely different and change how the game is played and won. Before, the object of the game was to get to the goal as fast as possible.

In this add-on, you’ll program the goal sprite to chase the player sprite. Instead of trying to catch the goal, the player will have to stay away from it.

To start, click on the goal sprite. For the goal sprite to chase the player, it needs to point towards the player, then move forward repeatedly. To do that, go to the motion menu, and drag out a "point toward" block. Then, change the value to the name of your player sprite. When that block is clicked, the goal sprite will point toward the player. Next, the goal sprite needs to move toward the player. Drag out a "move” block, and attach it to the point towards block.

When that block stack is run, the goal sprite points toward the player, then moves.

Add a forever loop to make this block stack run forever.

Test this. The goal sprite points towards the player, moves ten steps, and so on. This ensures that no matter where the player is, the goal sprite will point towards it, then move forward. Hmmm, that seems way too fast. Tinker with the value of the move block to slow it down. Great!

Now the goal sprite moves. Program the goal sprite’s position to reset when the game begins. Drag the goal sprite to where it should start, then add a “go to x y” block, and place it at the top of this stack. Add a "when flag clicked" block to start this code stack.

Click the flag to test it. Great, it works, but it could be better. The player says “You win!” when the goal sprite touches it, but that no longer fits how the game works. Select the player sprite, and change the text in the “say” block to something like “You got caught!”

Notice that the goal sprite bounces back and forth really fast when it touches the player sprite.

That’s because the goal sprite is still trying to move toward the player over and over. Since the player isn’t moving, the goal sprite just bounces.

The goal sprite should move until it touches the player sprite, not “forever.” A “repeat until” block will repeat the actions inside it until its condition is met. In this case, it will make the goal keep moving and pointing toward the player until it touches it.

Select the goal sprite. Replace the “forever” block with a “repeat until” block from the control menu. From the sensing menu, add a “touching” block as the condition. From the dropdown, select the name of the player sprite. Now this reads, “repeat moving until touching the player sprite.” Click the flag to test.

Great! It works. Now, it’s your turn: Make the goal sprite chase the player using “point towards,” “move” and “forever” blocks. Change the message at the end of the game.

Stop the goal sprite from moving by replacing the “forever” block with “repeat until” and “touching” blocks.

Scegli un’estensione
Ostacoli ruotanti
Rendi il gioco più impegnativo facendo ruotare un ostacolo.
Superato
Crea un ostacolo che cresce lentamente durante il gioco.
Vendetta
Programma lo sprite Obiettivo a inseguire lo sprite Giocatore.
Tieni il tempo (Part 1 of 2)
Crea un timer per segnare il punteggio del gioco e programma un modo per memorizzare il miglior tempo.
Tieni il tempo (Part 2 of 2)
Crea un timer per segnare il punteggio del gioco e programma un modo per memorizzare il miglior tempo.
Ridisegna il tuo labirinto
Cambia l'aspetto del labirinto o disegnane uno!
Racconta una storia
Coinvolgi i giocatori con una trama emozionante per il tuo gioco.
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Una volta terminato un componente aggiuntivo, scegline un altro da provare!