Skip to content

A top-down adventure

A dark dungeon lit by your lantern, a key, a locked door and a treasure behind it, all built from the Entity menu and the Inspector.

Make a project: File → New Project (Ctrl+Shift+N), name it Dungeon, pick the Empty template and Create.

A top-down game looks down on the world, so there is no gravity and the hero moves in eight directions. Start from the Empty template and make the hero.

  1. Choose Entity → Characters → Top-down Player.

The Body has Gravity Scale 0, and Top Down Movement reads the arrow keys, WASD or the stick. Now make the room dark and give the hero a light to see by.

  1. Click Add Component and add Light.
  2. In the Inspector, set Light → Radius to 5.
  3. In the Inspector, set Light → Shadows to true.
  4. Select Main Camera in the Hierarchy.
  5. In the Inspector, set Camera → Size to 6.
  6. In the Inspector, set Camera → Ambient to #4A5270.

A camera’s Ambient color is the light a scene has everywhere. A dark blue one makes the room dim, and any Light brightens the part it reaches. With Shadows on, walls block it.

A hero with a lantern (the editor)
  1. Choose Entity → Basics → Sprite.
  2. Rename it Wall (F2).
  3. In the Inspector, set Transform → Position to 0, 5, 0.
  4. In the Inspector, set Sprite → Size to 20, 1.
  5. In the Inspector, set Sprite → Tint to #484B55.
  6. Click Add Component and add Box Collider.
  7. In the Inspector, set Box Collider → Size to 20, 1.

A wall is a sprite with a box collider. Make one, then copy it with Ctrl+D and move and resize each copy.

  1. Press Ctrl+D.
  2. In the Inspector, set Transform → Position to 0, -5, 0.
  3. Press Ctrl+D.
  4. In the Inspector, set Transform → Position to -10, 0, 0.
  5. In the Inspector, set Sprite → Size to 1, 10.
  6. In the Inspector, set Box Collider → Size to 1, 10.
  7. Press Ctrl+D.
  8. In the Inspector, set Transform → Position to 10, 0, 0.

Four walls make a room. Press F5 and walk into them: the hero stops, and the lantern’s light stops at the walls too.

Walls (the editor)
  1. Choose Entity → Basics → Sprite.
  2. Rename it Divider Top (F2).
  3. In the Inspector, set Transform → Position to 3, 3.25, 0.
  4. In the Inspector, set Sprite → Size to 0.5, 2.5.
  5. In the Inspector, set Sprite → Tint to #484B55.
  6. Click Add Component and add Box Collider.
  7. In the Inspector, set Box Collider → Size to 0.5, 2.5.
  8. Press Ctrl+D.
  9. Rename it Divider Bottom (F2).
  10. In the Inspector, set Transform → Position to 3, -3.25, 0.
  11. Choose Entity → Basics → Sprite.
  12. Rename it Door (F2).
  13. In the Inspector, set Transform → Position to 3, 0, 0.
  14. In the Inspector, set Sprite → Size to 0.5, 4.
  15. In the Inspector, set Sprite → Tint to #E3B341.
  16. Click Add Component and add Box Collider.
  17. In the Inspector, set Box Collider → Size to 0.5, 4.
  18. Click Add Component and add Switch.
  19. In the Inspector, set Switch → Mode to Button.
  20. In the Inspector, set Switch → Key to Key.
  21. In the Inspector, set Switch → Hides to Door.

A wall with a gap in it, closed by a door. A Switch in Button mode turns on when something touches it, and one that has a Key only turns on for someone carrying that item. While it is on, it hides everything it names in Hides, and here that is the door itself.

A locked door (the editor)
  1. Choose Entity → Basics → Sprite.
  2. Rename it Key (F2).
  3. In the Inspector, set Transform → Position to -3, 0, 0.
  4. In the Inspector, set Sprite → Size to 0.35, 0.6.
  5. In the Inspector, set Sprite → Tint to #E3B341.
  6. Click Add Component and add Circle Collider.
  7. In the Inspector, set Circle Collider → Is Trigger to true.
  8. Click Add Component and add Pickup.
  9. In the Inspector, set Pickup → Layers to Player.
  10. In the Inspector, set Pickup → Item to Key.
  11. Choose Entity → Basics → Sprite.
  12. Rename it Treasure (F2).
  13. In the Inspector, set Transform → Position to 5.5, 0, 0.
  14. In the Inspector, set Sprite → Size to 0.5, 0.5.
  15. In the Inspector, set Sprite → Tint to #57AB5A.
  16. Click Add Component and add Circle Collider.
  17. In the Inspector, set Circle Collider → Is Trigger to true.
  18. Click Add Component and add Pickup.
  19. In the Inspector, set Pickup → Layers to Player.
  20. In the Inspector, set Pickup → Amount to 5.

A Pickup with an Item puts it in the hero’s pockets when they touch it. The key is that item, so the door will open for whoever picked it up. The treasure is worth five points.

  1. Choose Entity → Basics → Text.
  2. Rename it Score (F2).
  3. In the Inspector, set Transform → Position to -8, 4, 0.
  4. In the Inspector, set Text → Value to Score: 0.
  5. Click Add Component and add Counter.
The key and the treasure (the editor)
  1. Choose Entity → Basics → Sprite.
  2. Rename it Bat (F2).
  3. In the Inspector, set Transform → Position to 8, 3.5, 0.
  4. In the Inspector, set Sprite → Size to 0.7, 0.5.
  5. In the Inspector, set Sprite → Tint to #9B6BD6.
  6. Click Add Component and add Chase.
  7. In the Inspector, set Chase → Range to 3.
  8. In the Inspector, set Chase → Needs Sight to true.
  9. Click Add Component and add Damage On Touch.
  10. In the Inspector, set Damage On Touch → Layers to Player.
  11. Select Player in the Hierarchy.
  12. Click Add Component and add Health.

A Chase follows the hero once it is near and can see them, and gives up when they get away. Needs Sight makes the walls hide the hero from it. The hero needs Health to be hurt, three hits by default.

A bat (the editor)
  1. Press F5 to play.
  2. In the game, hold Right for 3 seconds.

Run for the door first and it stays shut: the hero has no key yet.

  1. In the game, hold Left for 6 seconds.

Fetch the key from the left of the room.

  1. In the game, hold Right for 10 seconds.

With the key the door opens as the hero touches it, and the treasure is theirs: one point for the key, which scores like any pickup, and five for the treasure.

Play it (the game)
  1. Press Shift+F5 to stop.

That is a small adventure. Add Dialogue Boxes for talking, portals between rooms, and more rooms of your own, each a scene.