public Map(int width, int height, Texture2D createFrom) { NextText = 0; CurrentTextFrame = -1; PlayText = false; Spawn = Vector.Zero; WidthInTiles = width; HeightInTiles = height; Tiles = new Tile[width, height]; Entities = new List<Entity>(); LitAreas = new List<LitArea>(); Staircases = new List<Staircase>(); Particles = new List<Particle>(); Random = new Random((int)DateTime.Now.Ticks); Entities.Add(PlayerEntity = new Player(this)); InitMap(createFrom); AddMapObjects(); for (int x = 0; x < WidthInTiles; x++) for (int y = 0; y < HeightInTiles; y++) { if (Tiles[x, y].Background == Tile.BlockType.Node) Pentagram = new Vector(x + 1, y + 1); } }
private void InitMap(Texture2D texture) { Color[] textureData = new Color[WidthInTiles * HeightInTiles]; texture.GetData(textureData); for (int x = 0; x < WidthInTiles; x++) for (int y = 0; y < HeightInTiles; y++) if (textureData[x + y * WidthInTiles] == new Color(127, 127, 127)) Tiles[x, y] = new Tile(Tile.BackType.Ventilation, Tile.BlockType.None, Tile.BlockType.None); else if (textureData[x + y * WidthInTiles] == Color.Black) { if (y > 0 && textureData[x + (y - 1) * WidthInTiles] == new Color(127, 127, 127)) Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Ceiling, Tile.BlockType.Ceiling); else if (y < HeightInTiles - 1 && textureData[x + (y + 1) * WidthInTiles] == new Color(127, 127, 127)) Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Floor, Tile.BlockType.Floor); else Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Wall, Tile.BlockType.Wall); } else if (textureData[x + y * WidthInTiles] == new Color(63, 72, 204)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Crate, Tile.BlockType.None); } else if (textureData[x + y * WidthInTiles] == Color.White) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.None, Tile.BlockType.None); } else if (textureData[x + y * WidthInTiles] == new Color(237, 28, 36)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.None, Tile.BlockType.Lamp); if (x > 0 && x < WidthInTiles - 1 && textureData[x + y * WidthInTiles + 1] == new Color(237, 28, 36) && textureData[x + y * WidthInTiles - 1] == new Color(237, 28, 36)) LitAreas.Add(new LitArea(x + 0.6, y + 0.4, 5.5, 2.3, 8)); } else if (textureData[x + y * WidthInTiles] == new Color(200, 0, 100)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.None, Tile.BlockType.Lamp); } else if (textureData[x + y * WidthInTiles] == new Color(0, 255, 0)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Transparent, Tile.BlockType.None); } else if (textureData[x + y * WidthInTiles] == new Color(0, 128, 0)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Random.Next(2) == 0 ? Tile.BlockType.Filing1 : Tile.BlockType.Filing2, Tile.BlockType.None); } else if (textureData[x + y * WidthInTiles] == new Color(0, 192, 0)) { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.Photocopy, Tile.BlockType.None); } else if (textureData[x + y * WidthInTiles] == new Color(0, 255, 255)) { Tiles[x, y] = new Tile(Tile.BackType.None, Tile.BlockType.Node, Tile.BlockType.None); } else { Tiles[x, y] = new Tile(Tile.BackType.Wall, Tile.BlockType.None, Tile.BlockType.None); } }