Tile[][] GenerateMap(int[][] layout, string[] sheets, Rectangle[] sources) { Tile[][] result = new Tile[layout.Length][]; float scale = 1.0f; for (int i = 0; i < layout.Length; i++) { result[i] = new Tile[layout[i].Length]; for (int j = 0; j < layout[i].Length; j++) { //the 0's and i's in the layout array corrrespond to //strings and rectangles in sheets and sources array string sheet = sheets[layout[i][j]]; Rectangle source = sources[layout[i][j]]; //we dont have to take scale into account, but we do need //to space our grid out accordingly. It might be smart //to have a width and height that's a constant, right now //we are assuming that all of the passed in rects in sources //will hav a uniform size Point worldPosition = new Point(); worldPosition.X=(int)(j * source.Width); worldPosition.Y = (int)(i * source.Height); result[i][j] = new Tile(sheet, source); result[i][j].Walkable = layout[i][j] == 0; result[i][j].WorldPosition = worldPosition; result[i][j].scale = scale; } } return result; }
Tile[][] GenerateMap(int[][] layout, string[] sheets, Rectangle[] sources) { Tile[][] result = new Tile[layout.Length][]; float scale = 1.0f; for (int i = 0; i < layout.Length; i++) { result[i] = new Tile[layout[i].Length]; for (int j = 0; j < layout[i].Length; j++) { string sheet = sheets[layout[i][j]]; Rectangle source = sources[layout[i][j]]; Point worldPosition = new Point(); worldPosition.X = (int)(j * source.Width); worldPosition.Y = (int)(i * source.Height); result[i][j] = new Tile(sheet, source); result[i][j].Walkable = layout[i][j] == 0; result[i][j].WorldPosition = worldPosition; result[i][j].Scale = scale; } } return result; }