# How to define an area as a room on a 2d screen ?

Attention Topic was automatically imported from the old Question2Answer platform.

Hi ! I’m extremely new to game development and it’s pretty confusing. I’m trying to do a 2d game where you can click on one of your characters, then on an hallway or a room and they move there. I’m not asking for advice on pathfinding, but rather how I can define areas as individual hallways or rooms. I tried looking on this forum but all I can find is questions about roguelikes. My game would have a single map.

You could do a lot of things depending on how you want to handle it. I’m not sure why you want to know that, whatever it’s for creating events, managing rooms or their properties, or searching for something based on the room and its location. But knowing the “id” that represents the room, you could find everything else.

Here some ideas:

• Create different scenes as rooms and make your character or your
mouse aware of which scene (room) you are trying to go to when you click or press a key. You can
use variables, signals or area2d in them to notify that to keep track of the current room and the room you want to go.
• Use an Area2D node with a CollisionPolygon2D or CollisionShape2D to
define the size of each room. Assign an ID to each room and set it in
the Area2D node to identify the current room.
• Manage doors: When moving from one door or passage to another room,
store the ID of the destination room in a variable. Pathfinding
algorithms can be useful to determine which doors to use to reach a
specific room, and to know what room its.
• Create different tilemaps for each room and determine the current
room based on which tilemap the character is moving on, and what the mouse it’s clicking on.
• Ensure that all rooms have the same size, for example, if all rooms
are 10x10 tiles. By knowing the character’s tile position (e.g.,
22,15), you can calculate the room’s coordinates (e.g., x=3, y=2), and with different sizes you could make roules that even with different sizes room you could predict whats the hallway/room. and knowing that you know in what tile the room start and in what tile the room end.
• Save the tiles in a matrix (Array ) where [y] (position) and the value it’s the id room. This matrix
would represent the entire map, with each position corresponding to all your tiles. You can initialize the matrix at the start of the game to
assign each tile’s room, especially if you are procedurally
generating the map. Alternatively, if you know which tiles represent
doors, you can differentiate between rooms based on that information.

for example if you set the matrix you would look like somenthing like this where the number it’s the door
11111–2222
11111D2222D3333333
--------------------3333333
--------------------3333333

• If you create each room as a separate scene, you can use collisions to determine the adjacent rooms in each direction and store this information. For example, if you click on the hallway3 room, you can navigate between variables (South, North, East, West) to find the room your character is currently in. This way, you can determine all the rooms you need to traverse and identify each room along the way.

I hope this helps! I’m just throwing out some ideas. Feel free to mix and match them or simplify them as you see fit.

This is very helpful. Thanks !

SUPERFREAK | 2023-05-30 05:29