Skip to main content
edited body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
//In Your Game manager or whatever
public setRoom(Room r, startX, startY){

   Tile[][] tiles = r.getTiles();
   int sizeY = tiles.size();
   int sizeX = tiles[0].size();        

   for(int y=0; y < sizeY; y++)
      for(int y=0;x=0; yx < sizeY;sizeX; y++x++)
          //Adds the tile, for any empty tile you need additional checking
          worldGrid.setTile(tiles[y][0],startX+x,startY+y);
}
 //In Your worldGrid or whatever
  
  private Tile[][] grid;
  
 public function setTile(Tile t, x, y){

    grid[y][x] = t;
 }
//In Your Game manager or whatever
public setRoom(Room r, startX, startY){

   Tile[][] tiles = r.getTiles();
   int sizeY = tiles.size();
   int sizeX = tiles[0].size();        

   for(int y=0; y < sizeY; y++)
      for(int y=0; y < sizeY; y++)
          //Adds the tile, for any empty tile you need additional checking
          worldGrid.setTile(tiles[y][0],startX+x,startY+y);
}
 //In Your worldGrid or whatever
  
  private Tile[][] grid;
  
 public function setTile(Tile t, x, y){

    grid[y][x] = t;
 }
//In Your Game manager or whatever
public setRoom(Room r, startX, startY){

   Tile[][] tiles = r.getTiles();
   int sizeY = tiles.size();
   int sizeX = tiles[0].size();        

   for(int y=0; y < sizeY; y++)
      for(int x=0; x < sizeX; x++)
          //Adds the tile, for any empty tile you need additional checking
          worldGrid.setTile(tiles[y][0],startX+x,startY+y);
}
 //In Your worldGrid or whatever
  
  private Tile[][] grid;
  
 public function setTile(Tile t, x, y){

    grid[y][x] = t;
 }
added 97 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

Just realized by looking at your image, it looks like it's more like " Data structure 1"

Edit:

Edit:

Just realized by looking at your image, it looks like it's more like " Data structure 1"

Edit:

added 488 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

Or should I pick data structure 2? Rooms are 4-way linked lists of tiles

If you go with a "world grid" as in my example you don't need to. Simply request the surrounding tiles and see if they are passable once the player overlaps with a tile. Unless you move from tile to tile, as in snapping to another tile, then it would be as easy as checking player input. When the player hits the down arrow key, you simply test if the tile below the current one; which is [y+1][x]; is passable. If not, nothing happens.

Or should I pick data structure 2? Rooms are 4-way linked lists of tiles

If you go with a "world grid" as in my example you don't need to. Simply request the surrounding tiles and see if they are passable once the player overlaps with a tile. Unless you move from tile to tile, as in snapping to another tile, then it would be as easy as checking player input. When the player hits the down arrow key, you simply test if the tile below the current one; which is [y+1][x]; is passable. If not, nothing happens.

added 140 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 140 characters in body; Post Made Community Wiki
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 247 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
deleted 2961 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 1169 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 107 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 131 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 131 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 131 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 131 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
added 131 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28
Loading