Skip to content

Specific Rooms

kobewi edited this page Feb 27, 2024 · 2 revisions

Room-specific things that show various features.

Right Staircase - map collectible, secret wall

RightStaircase.tscn has a map item collectible that discovers part of the world's map. It also has a secret, which is a storable object without marker and creates a cell override to show the newly discovered path. Notice how the map updates when you enter the fake wall area (it's located on bottom right of the room).

TileMap node has a script that disables collision on the Fakeground layer (i.e. fake wall). MapItem is it's own scene, Secret node handles the override.

Lava Corridor - room group override, scene assign override, custom object IDs

A corridor with lava. The interesting fact about it is that it uses 2 scenes: LavaCorridor.tscn and LavaCorridorAfterwater.tscn. After a certain condition is met, the assigned scene is changed to the latter one, so entering this room's cell will switch to a different scene without lava. The color of the cells on the map also changes.

Overrides are performed in LeftStaircase.tscn, but another interesting thing is the orb in this room. It exists in both scenes, yet MetSys can correctly deduce that you collected the orb previously registered in another scene (the orb is inaccessible until you get rid of the lava). It's thanks to object_id metadata, which for both orbs is lava_orb. This allows to register and store the same object in different scenes.

Left Staircase - unlocking shortcut, one-time switches

LeftStaircase.tscn shows how to make a persistent event button. When the player touches the blue button, it will switch to pressed state and emit the pressed signal. The button is a storable object; it's stored on the first press, so when entering the room afterwards, it's pressed immediately (it still emits the signal to notify other objects).

The receivers of the signal is GateOpen node and Pipe. GateOpen will disable the Gate TileMap layer, opening the shortcut. The pipe will start animation when it receives the signal. However it keeps a separate event (in an event array unrelated to MetSys), so when the button notifies it again when entering the room, the animation will be skipped.

Portal Room - moving between map layers

PortalRoom.tscn is one of the portal rooms. It has a Portal node responsible for changing layers. Although in fact the layer changing comes indirectly. What the portal does is changing the scene, the actual layer is assigned in MetSysGame.gd in load_room() method.

Dark Staircase - irregular room with off-map drawing, teleport between rooms

When a room is not rectangular, there will be space where camera can go outside the map. This can be handled in multiple ways. The simplest one is just drawing tiles outside the map, so that player won't see empty space. This approach can be unreliable. Other ways involve drawing a plain color/pattern outside the map or constraining the camera to be only within the used cells. Both can be achieved by using get_local_cells() method. DarkStaircase.tscn shows the latter approach, i.e. drawing plain color; the code is in Outside node.

In this room there is also a small portal. When you enter it, you get teleported to another room on the same layer. This is done simply by loading the other room, but ensuring proper player position after exiting is not obvious, because the previous map is freed before the new one is loaded. The trick is to use a static method to perform something after changing maps.

Dice Room - procedurally generated rooms

DiceRoom.tscn and the related Junction.tscn contain the most complex logic in the sample project. Touching the dice inside the Dice Room will generate a couple of procedural rooms and put a collectible into the furthest one of them.

The whole script for generating rooms is in the Dice node. The general idea is that it "generates" and saves scenes, puts them on the map and picks the further room to insert an orb. Check the Dice script for details. The Junction.tscn has an orb with a custom ID.

Important to remember is that while the MetSys editor works with scene paths relative to the map root directory, when assigning an override you can assign it any absolute path (e.g. from user://). Do note that for RoomInstance to work correctly, the path still needs to point to a valid, unique scene resource.

Misc

Some rooms not really related to MetSys itself.

  • ElevatorRoom.tscn shows how to make a Metroid-esque elevator to move between rooms. Related: Elevator.tscn.
  • EndingPoint.tscn has example ability and an ending point based on collectibles.