what kind of structure do I need for two-way look-up? (e.g. mapping room coordinates)

jjg27

Member
I'm working on a 2D flickscreen game where hitting the edge of the screen triggers a transition which moves to the next room. I'm wondering how to tell the game which room is the next room.

Each room in my game will have coordinates from a grid. So, I need a structure like this.
[Structure storing Coords - Room Name]
(0,0) - Room 1
(1,0) - Room 2

After triggering the room transition, I need some kind of structure in Gamemaker than can handle this kind of look-up:
[start transition to room on right]
1) Get current room coordinates (input Room 1, (0,0) is retrieved from the structure)
2) Since a right transition, add 1 to x direction of current room coordinates to get the new room coordinates (operation performed on (0,0) to get (1,0))
3) Get next room name from the new room coordinates ((1,0) is searched for in the structure and Room 2 is retrieved)

I've tried reading about 2D arrays and ds_grid / ds_map, but I'm a bit stuck.

Thanks for any help!
 

Slyddar

Member
Sounds like a classic ds_grid scenario. It's basically just a grid, and in each grid entry you can hold the details of the room in a struct, or an array. You also need a room index so you know which room you are in. This can be as simple as 2 variables like room_x = 2 and room_y = 2, or an array holding it like room_index = [2, 2]. As long as you can use it on the grid to retrieve your data structure you store in the cell, and use that however you like.
 

TheouAegis

Member
Could do is with the basic array, either 1D or 2D. You could do this with a buffer. You could do this with a grid. This is nothing special. As Slyddar said, your only requirement is a variable to keep track of where inside that data structure you presently are. You also need to make sure that the target position in the data structure when trying to move will be a valid position inside the data structure. For example, if you use a 2d array for grid, and you try to move up oh, you need to make sure the variable holding the Y position is not already 0. Or if you use a buffer or 1D array, make sure the current position minus the width value of your map will not be less than 0.
 
Top