Skip to content
Menu

Docs · Make it a game

Levels and endings

15 minutes Uses: Area, Shape, complete, fail, wait, change_scene, save_number

By the end

  • Your rooms listed as levels, in the order they are played
  • A goal that wins the level, and a time limit that loses it
  • The editor’s record of each level: won or not, and your best time
  • What an exported game does when a level ends, and what it keeps between runs
On this page

Your levels

A level is a scene with a name and a place in an order: level 1, level 2, and so on. The Levels panel lists them. Its tab is at the bottom right of the editor, beside Build. If it is not there, choose View → Panels → Levels.

  1. Click the Levels tab. A project with no levels says No levels yet.
  2. Type The Room into the box in the panel’s bar and press Add level. The new row names a scene for it, scenes/the_room.ron, and warns under it that the file does not exist.
  3. The row is selected, with its buttons under it. Press Scene and choose room.ron, the room you have built since Getting started. The warning goes, and the row says startup: it is the scene the project opens on.
  4. Type Cellar and press Add level again. This time press Create scene under the warning. The editor makes the scenes folder, writes an empty cellar.ron into it, and opens it. Build the next room there, and save it with Ctrl+S.
The Levels panel at the bottom right of the editor, its bar reading 2 in order and 1 complete. Row 1, The Room, opens room.ron and is marked startup and best 9.4s, with Up, Down, Open, Play, Scene and Remove under it and a button reading Music: (none). Row 2, Cellar, opens scenes/cellar.ron and reads 2 tries, not finished. Under the list, a slot reads Then open: (none)
Two levels, the first one selected. The best time and the count of tries come from the editor’s record of your runs: see What the editor keeps.
A row’s name
Click it to select the level. Double-click it to rename it. Drag the row up or down the list to move the level.
Up and Down
Move the level one place.
Open
Opens the level’s scene. The status bar says which level it is, such as Level 2: Cellar.
Play
Opens the level’s scene and starts Play in one press.
Scene
Points the level at another scene file in the project folder.
Remove
Takes the level off the list, once you confirm. Its scene file is not deleted.
Music
What plays as the level opens, in the editor’s Play and in an exported game. A sound file plays on the one music channel: it replaces the track that was playing, and a level that names the track already playing leaves it playing. Drag one from Assets onto the button, and press the play button beside it to hear it. A music asset dragged there opens on the track chosen in the Track list beside it, its first unless you choose another. Click the button to clear it. See Audio and Music that reacts.
Then open
The scene the game opens after the last level is won: a victory screen, say. Drag a scene from Assets onto the Then open slot under the list, and click the slot to clear it. With none, the last level’s win ends the run.

The panel also warns under a row about a level with no name, a name or a scene that an earlier level already has, and a scene file that is not there. Every change you make in it is written to project.rengy at once: there is nothing to save.

Win or lose

Two builtins end a level. complete ends it as won, and fail as lost. A script calls them from any hook.

A goal

A goal is an Area that wins the level when something walks into it. The player from Characters and physics has an Area of its own, so it can.

rgs goal.rgs
/// Wins the level when something walks into it.
component Goal : Area {
    fn on_enter() {
        complete();
    }
}
  1. Make a script called goal the way Rengy Script makes one, and replace its text with the one above.
  2. Open The Room with its row’s Open. Select Room, add a node with + Add node → Area, and name it goal. Set its Position to 254 and 132, between the door and the right wall, and its Shape’s Size to 32 and 48.
  3. An Area draws nothing, so press Add component, choose ShapeComponent and give the Shape the same Size.
  4. Press Add component again and choose Goal.
  5. Press F5. Jump the crate, climb the steps, step on the plate, and walk through the door into the goal. Play stops, the room goes back to how it was, and the status bar says Level complete, how long it took, and next: Cellar.

A time limit

This one loses the level if it has not been won in time. Put it on any node in the room, such as Room itself:

rgs time_limit.rgs
/// Loses the level if it has not been won in time.
component TimeLimit {
    /// Seconds the player has.
    #[suffix("s")]
    seconds: f32 = 30.0,

    fn on_create() {
        await wait(seconds);
        fail();
    }
}

Press F5 and wait. Thirty seconds in, Play stops and the status bar says Level failed, and after how long. Reach the goal first and the level is won instead: it ends once, however it ends.

What the editor does when a level ends

  • Play stops, just as Stop stops it, and everything the run changed is put back.
  • The status bar says how the level ended and how long it took. After a win it names the next level in the list. It does not open it: press that level’s Play when you are ready.
  • The editor adds the run to its record, and the level’s row shows it. See What the editor keeps.

The editor knows which level is playing from the scene that is open. Pressing F5 with room.ron open plays The Room as level 1, just as its row’s Play does. A scene that is not in the list still ends the same way, with no next level and no record. The exception is a Play started on a scene that is not a level, such as a title: it follows the list as an exported game does, from level to level, and a lost level opens again.

In an exported game

Run game and an exported game open the project’s startup scene. When a script there calls complete or fail in a scene that is a level of the list, the game moves on, as the list says:

  • complete opens the next level’s scene, as change_scene opens a scene: fresh. After the last level it opens the scene named in Then open.
  • fail opens the same level’s scene again, fresh.
  • What a script has kept, with keep_number and its kind, survives both, as it survives change_scene.
  • The level’s Music plays as its scene opens.
  • A change_scene asked on the step that ends the level is ignored: the level’s own exit wins. quit wins over both.

A scene that is not a level, and a last level that is won with nothing in Then open, have nowhere to go on to. The level is over, but the window stays open and keeps showing it:

  • No hook runs again, on any node. Waits, anneals and pulses stop where they are, and no signal is heard.
  • Every Character Body driven by the keys still walks and jumps on them, and sounds that are playing carry on.
  • Nothing else happens. The game does not close, start again, or open another scene by itself.

Everything the hooks ask for on the step that ends the level still happens. So when the end should show something, do it in the same hook, before the call: show a node you kept hidden, such as a sign made of Shapes, play a sound as Audio shows, then call complete(). A game that moves on has no need of this: the next scene opens as the level ends.

What the editor keeps

project.rengy
The Levels list, written as you change it.
progress.ron
The editor’s record of your runs: for each level, whether you have won it, and your best time. A level’s row shows its best time once you have won it, and a count of your tries before then, and the panel’s bar counts the levels won. The editor keeps the file in the project folder and reads it when the project opens. Delete it, with the project closed, to start the record again.
Your scenes
As you last saved them with Ctrl+S. Run game reads the files, so save before you press it.

Next

  • Rengy Script: more on waiting, anneals and signals, which a level’s scripts are made of.
  • Characters and physics: the plate and the door the goal sits behind.
  • Audio: sounds in the room, and music a script starts and changes.

The script reference lists complete and fail with the other builtins. Exporting makes the game you send.