Skip to content

Please update your browser

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

Choose an Add-On
Spinning Obstacle
Create a more challenging game by making an obstacle spin.
Create an obstacle that slowly grows throughout the game.
Program the goal sprite to chase the player sprite.
Keeping Time (Part 1 of 2)
Create a timer to keep score for this game, and program a way to store the fastest time.
Keeping Time (Part 2 of 2)
Create a timer to keep score for this game, and program a way to store the fastest time.
Redesign Your Maze
Change the look of the maze or draw your own!
Tell a Story
Engage game players with an exciting story for your game.
  • 1. Remix the Maze Starter Project
  • 2. Following the Mouse Pointer
  • 3. Stay Inside the Lines
  • 4. Using If-Statements to Win
  • 5. Add-Ons
  • 6. Reflection
  • 7. Wrap-up: Maze Game
  • 8. Wrap-up: Share Your Project
  • 9. Wrap-up: Show Your Project
arrow_backward Back Next arrow_forward

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.

  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!