How to Make Subway Surfers - Scratch 3.0 Tutorial - Episode 2

3 min read 4 hours ago
Published on Oct 26, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, we will learn how to create a scrolling background in Scratch 3.0, similar to the game Subway Surfers. We will use clones and a unique MOD block to enhance the gameplay. Additionally, we will implement a size hack to allow sprites to move off-screen, add multiple truck costumes, and introduce a ground pound feature for better player control.

Step 1: Setting Up the Scrolling Background

  1. Create the Background:

    • Open Scratch and create a new project.
    • Choose a suitable background that resembles the Subway Surfers environment.
    • Import your background image or draw one using the Scratch editor.
  2. Add Clones for Continuous Scrolling:

    • Select the background sprite and add a script to create clones:
      • Use the when green flag clicked event.
      • Create a loop to generate clones continuously.
    • Example code:
      when green flag clicked
      forever
        create clone of [myself v]
        wait (2) seconds
      
  3. Manage Clones:

    • In the clone's script, ensure that it moves down the screen to create a scrolling effect:
      • Use the when I start as a clone block.
      • Move the clone downwards and reset its position when it goes off-screen.

Step 2: Implementing the Size Hack

  1. Using the Size Hack:

    • Adjust the size of your sprites to allow them to move off-screen:
      • Set the sprite's size to a small percentage (e.g., 10%).
    • This allows for better gameplay as sprites can extend beyond the visible area without being cut off.
  2. Control the Size Dynamically:

    • You can use a variable to control the size dynamically:
      • Create a variable named sizeFactor.
      • Set sizeFactor to a low value (like 10).
      • Use it to adjust the size of the sprite when it spawns.

Step 3: Adding Truck Costumes

  1. Create Multiple Truck Costumes:

    • Import various truck images to your project.
    • Make sure each truck sprite has a different costume.
  2. Switching Between Costumes:

    • In your truck sprite's script, randomly choose a costume each time a truck is spawned:
      • Use the switch costume to [costume v] block within the clone script.
    • Example code:
      when I start as a clone
      switch costume to (pick random [1 v] to [number of costumes v])
      

Step 4: Implementing Ground Pound Feature

  1. Creating the Ground Pound Mechanic:

    • Add a new sprite for the ground pound effect.
    • Create a script that detects when the player presses a specific key (e.g., spacebar) to trigger the ground pound.
    • Example code:
      when [space v] key pressed
      create clone of [ground pound effect v]
      
  2. Control Player Movement:

    • Modify the player sprite's script to allow for a fast fall when the spacebar is pressed.
    • Ensure the falling speed is increased temporarily to simulate a ground pound effect.

Conclusion

In this tutorial, we covered the essential steps to create a Subway Surfers-style scrolling background in Scratch 3.0. We learned how to use clones for continuous movement, implement a size hack for dynamic gameplay, add various truck costumes, and introduce a ground pound feature for enhanced player control.

Next steps could include refining the player controls, adding obstacles, and implementing scoring mechanics to further develop your game. Happy coding!