Build Your Own Loop Runner Game: 6 Easy Code.org Steps
Loop Runner Game using Code.org (Loops):Overview
Loop Runner is a beginner-friendly Code.org Game Lab project where the player collects coins while a repeat/forever loop continuously updates the game. Students learn loops, variables, conditions, events, and scoring.
Innovation
Unlike a static animation, the game continuously runs using loops, making gameplay interactive.
Materials Required
- Computer
• Internet
• Code.org Game Lab
Learning Objectives
Understand loops, variables, events, collision detection and game logic.
Procedure
- Open Code.org Game Lab.
2. Create player and coin sprites.
3. Use the draw() loop to update the game.
4. Move the player with arrow keys.
5. Detect collisions and increase score.
6. Respawn coins and continue until timer ends.
Detailed Block-Based Coding Logic
-
Initialize Variables and Setup Sprites
Drag blocks into the workspace workspace (outside of the draw loop) to set up your starting game state:
- Create a score variable: Drag a var x = 0; block. Rename x to score and leave it set to 0.
- Create the player: Drag a var sprite = createSprite(50, 200); block. Rename it to player.
- Set player visual: Drag a player.setAnimation(…) block underneath and select your runner animation.
- Create the coin: Drag a var sprite = createSprite(400, 200); block. Rename it to coin.
- Set coin visual and speed:
- Drag a coin.setAnimation(…) block and choose a coin animation.
- Drag a coin.velocityX = -5; block to make the coin automatically glide from right to left.
-
Set Up the Draw Loop
Every game in Game Lab requires a repeating loop to refresh the screen.
- Drag out the green function draw() { … } block. Everything else from this point on goes inside this loop.
- Clear the screen background: Drag a blue background(“color”); block to the top inside of the draw loop.
-
Add Player Movement Controls
Inside the draw loop, add blocks to check if the arrow keys are pressed:
- Drag an orange if block.
- Place a keyDown(“up”) block inside the if condition slot.
- Inside the action space, drag a player.y = player.y – 5; block.
- Drag a second orange if block underneath.
- Place a keyDown(“down”) block inside the condition slot.
- Inside the action space, drag a player.y = player.y + 5; block.
-
Create the Continuous “Loop” (Coin Reset)
To make the game endless, you need to teleport the coin back to the right when it goes off-screen:
- Drag an orange if block.
- For the condition, use a math comparison block: coin.x < 0.
- Inside the if block, reset the X position: coin.x = 400;.
- Randomize the height so it’s unpredictable: Drag a coin.y = math block, and snap a randomNumber(50, 350) block into the value slot.
-
Collision and Scoring Mechanics
Detect when the player catches a coin to update the score:
- Drag another orange if block.
- For the condition, drag the player.isTouching(coin) block.
- Inside the action space, update the score variable: Drag a score = score + 1; block.
- Teleport the coin instantly so it doesn’t get stuck touching the player: Set coin.x = 400; and set coin.y = randomNumber(50, 350);.
-
Draw Objects and UI
At the very bottom inside your draw loop, finish up by rendering the visual assets and score counter:
- Drag the blue drawSprites(); block.
- Display the score text:
- Drag a textSize(20); block.
- Drag a fill(“black”); block to choose text color.
- Drag a text(string, x, y); block. Replace the string slot with a math addition block to combine text and variables: “Score: ” + score. Set the coordinates to 20 for X and 30 for Y.
Applications
Game development, coding practice, STEM education.
Conclusion
The Loop Runner Game project serves as an ideal foundational exercise for introductory computer science students using the Code.org Game Lab block-based environment. By designing and developing this interactive game, students successfully transition from viewing programming as static logic to understanding it as a dynamic, continuous process.
Ultimately, this Loop Runner Game project bridges the gap between pure coding syntax and practical design. It builds a robust cognitive framework for algorithmic thinking, preparing students for more advanced game development mechanics like physics, complex asset animations, and progressive difficulty systems.
FAQs
1. What is the Loop Runner Game?
The Loop Runner Game is a beginner-friendly Code.org Game Lab project where players move a character, collect coins, and increase their score. The game uses loops, variables, conditions, events, and sprites to create interactive gameplay.
2. Why are loops important in the Loop Runner Game?
Loops allow the game to run continuously. In Code.org Game Lab, the draw() loop repeatedly updates the player’s movement, coin position, collisions, score, and graphics so the game remains interactive.
3. What programming concepts does this Loop Runner project teach?
This project introduces loops, variables, conditions, events, sprites, keyboard input, collision detection, random numbers, scoring, and game logic. These concepts provide a foundation for learning more advanced programming.
4. Is Code.org Game Lab suitable for beginners?
Yes. Code.org Game Lab is designed to help students learn programming through interactive games and animations. Its block-based programming environment makes it easier for beginners to understand programming logic before moving to more advanced coding.
















