How to Create Multi-Room Layouts For a 2D Game Using Arrays

4

Index

Stats

1,239 visits, 3,722 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Currently the game knows only one thing: where the rooms are on the array. What it does not know is literally everything else: where the player currently is, how to move between rooms, which room to go to, etc. We will tell the game this by using global variables.

Here are the global variables you will need:

roomX (number) - this tells the game which room on the X axis the player is in.

roomY (number) - this tells the game which room on the Y axis the player is in.

level (number) (optional) - this tells the game which floor the player is on, if your game has multiple floors.

roomName (string) - this tells the game the name of the room where the player currently is.

In the event sheet, below what you currently have, add the "System - every tick" condition. Then add the System action "Set value". Choose the variable roomName and set its value to "Array.At(roomX,roomY,0)" (you can omit the last 0 if your game only has one floor). What this does is tell the game to always set roomName to whatever the contents of the cell at roomX and roomY are.

You may have noticed a problem: roomX and roomY have not been defined yet, so the game does not know which cell to look for. Because the game cannot choose a room on its own, we need to give roomX and roomY some default values so that the game has a place to start.

Check your Array project file (in the Array Editor) and look for your spawn room. Take its horizontal and vertical cell positions, and use those for the default values of roomX and roomY. For example, if your starting room is in the 18th row and the 10th column, roomX would be 10 and roomY would be 18. Now the game knows the name of the starting room. This is important.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!