Created
November 2, 2012 10:18
-
-
Save demonixis/3999959 to your computer and use it in GitHub Desktop.
2D Array to 1D Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Serializable] | |
public class Level | |
{ | |
public int Id { get; protected set; } | |
public Point3 Position { get; set; } | |
public Size3 Sizes { get; set; } | |
public string WallTexture { get; protected set; } | |
public string GroundTexture { get; protected set; } | |
public string TopTexture { get; protected set; } | |
public int Width { get; protected set; } | |
public int Depth { get; protected set; } | |
public int[] Tiles { get; protected set; } | |
public Level(int id) | |
{ | |
Id = id; | |
} | |
public void SetTiles2D(int[,] tiles) | |
{ | |
Width = tiles.GetLength(0); | |
Depth = tiles.GetLength(1); | |
int[] tiles1D = new int[Width * Depth]; | |
Tiles = new int[Width * Depth]; | |
for (int x = 0; x < Width; x++) | |
{ | |
for (int y = 0; y < Depth; y++) | |
{ | |
Tiles[x + y * Width] = tiles[x, y]; | |
} | |
} | |
} | |
public int[,] GetTiles2D() | |
{ | |
int[,] tiles2D = new int[Width, Depth]; | |
for (int x = 0; x < Width; x++) | |
{ | |
for (int y = 0; y < Depth; y++) | |
{ | |
tiles2D[x, y] = Tiles[x + y * Width]; | |
} | |
} | |
return tiles2D; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment