Are you ready to create a non-stop, looping game? Today, we are combining three advanced ScratchJr blocks to programme a dynamic game of tag that goes on forever: the Wait block, the Start on Bump block, and the powerful Repeat Forever block. This is a great exercise for teaching children how to create game loops and use collision detection to trigger actions.
Our project today will demonstrate this with Kitten and Tick playing an endless game of tag in the park.
Setting Up the Infinite Game
To start our continuous game, we need a wide-open space and our two characters positioned for a chase.
- Change the Background: Select the park background. [00:29]
- Add Characters: Add the Tick character to the project. [00:36]
- Position Characters: Place Kitten and Tick at opposite ends of the screen so they have a long distance to run when chasing each other. [00:43]
The game requires two separate scripts to run simultaneously and endlessly.
Script 1: Kitten (The Perpetual Runner)
Kitten’s code uses the Repeat Forever block to ensure their part of the game loop keeps running. Ensure the Kitten iconis selected.
- Start and Speed: Begin with the Green Flag trigger. Use the Set Speed block (orange category) and select the fastest setting, as this is a race! [01:07]
- Chase Action: Use the Move Right block (blue category) to make Kitten run towards Tick. Use a large number (e.g., 16) to ensure they run all the way across the screen and bump Tick. [02:15]
- Run Away Action: Use the Move Left block (blue category), using the same number (16), so Kitten runs back towards their original position. [02:21]
- Pause (Wait): Add the Wait block (orange category). This pause is crucial! It gives Tick time to chase Kitten before Kitten starts their next run. A long wait, such as 50 (5 seconds), works well. [04:02]
- The Loop: Finish the script by attaching the Repeat Forever block (red category) to the end. This guarantees the entire script repeats endlessly. [01:43]
Script 2: Tick (The Collision-Triggered Chaser)
Tick’s code uses the Start on Bump block to trigger their action only when Kitten tags them. Ensure the Tick icon is selected.
- Start on Bump: Start Tick’s script with the Start on Bump block (yellow category). This means Tick’s programme only runs when Kitten collides with them. [02:34]
- Pause (Wait): Add the Wait block (orange category). This small pause is necessary to give Kitten a head start running away. [02:45]
- Chase Action: Use the Move Left block (blue category), set to 16, to make Tick chase Kitten back across the screen. [03:26]
- Run Away Action: Use the Move Right block (blue category), set to 16, to return Tick to their original position, ready to be chased again. [03:04]
- End: Finish the script with the red End block. We do not use a Repeat Forever block here, because the entire cycle is controlled by Kitten’s loop, which will cause the next bump, re-activating Tick’s Start on Bump block. [03:12]
When you press the Green Flag, the game begins! Kitten runs and bumps Tick, Tick waits, then chases Kitten, bumps them back, and the cycle continues—a perfect endless game of tag! [04:26]
Mastering these looping and conditional ScratchJr blocks is essential for building complex, functional games. For more guidance on creating interactive projects, check out our coding tutorials. For structured activities, explore our collection of ready-made lessons. Happy coding!