Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (February 2023)
Reason: Informal language

An Endless Runner is a type of game where the player jumps over obstacles. The ground and obstacles scroll, making it appear that the player is running along the ground.

Making the Backdrop

The backdrop can be anything you like. Make sure to draw a platform at the bottom to serve as a ground.


Making the Player

The player will jump over obstacles in the game. In Scratch runners, the design is often simple, usually a cube. However, the creator can make it look however they want. Call the Sprite 'Player'
Here is a simple jump code:

when green flag clicked
go to x: (0) y: (0) // Change these values so the player starts on the left side on the ground.
forever
    if <mouse down> then // Detects clicks.
    repeat (20)
        change y by (5)
    end
    repeat (20)
        change y by (-5)
    end
    wait until <not <mouse down>> // Stops player from holding down (optional)
end

Here is a more advanced and realistic jump code using velocity. The ground will need to be a sprite for this to work.

when green flag clicked 
set [yv v] to [0] // yv = y velocity
forever
    change [yv v] by (-1) // Gravity.
    if <touching (Platforms v)> then
        set [yv v] to ((yv) * (-1)) // Reverses the movement in the previous frame so the player isn't stuck in the ground.
        set [yv v] to [0] // Stops the player from falling.
    end
    if <<mouse down> and <touching (Ground v)?>> then // Detects clicks, though only if the player is touching the ground.
        set [yv v] to (25)
    end
    set [yv v] to ((yv) * (0.9)) // Slows the players movement so they don't jump extreme heights.
    change y by (yv)
end

Coding Dangers

In a typical endless runner, the player will jump over objects, such as spikes, to dodge them. Draw a hazard, call it 'Hazard' and put in this code:

Cloning Script

when green flag clicked
hide
forever
wait (2) seconds
create clone of (myself v)

Movement Script

This script lets the obstacle move along the x axis:

when I start as a clone
go to x: (240) y: (-100) // Adjust the y position so it starts on the ground.
show
forever
    change x by (-5) // Makes the obstacle move left.
end

This script deletes the clone once it reaches the left side of the screen:


when I start as a clone
wait (1) seconds // Stops the obstacle from being instantly deleted as it starts touching the edge of the screen.
forever
    if <touching (edge v)?> then
        delete this clone
    end
end

Ending the Game and Score

The game is over in a endless runner when the player touches the obstacle. It then gives the player a score based on how long they survived.

Score

This script keeps track of the score:

 
when green flag clicked
set [score v] to [0]
forever 
    wait (1) seconds
    change [score v] by (1)
end

Ending the Game

First of all, create a sprite called 'Game Over'. In the costume editor, draw a box with 'Game Over' in big letters. Then, add some smaller text saying 'Click the flag to try again'. Put this script in the sprite:

when green flag clicked
hide

Go to the Player sprite and put this code in:

when green flag clicked
forever
if <touching (Hazard v)?> then // Continuously checks if the player is touching an obstacle.
    broadcast (Game Over v)
end

Go back to the 'Game Over' sprite and put:

when i receive [Game Over v]
show
stop [all v] // Stops everything on all sprites

This is a finished endless runner game. You can always add your own special features if you want!

Cookies help us deliver our services. By using our services, you agree to our use of cookies.