public static void chooseFrames(Map map) { for (int x = 0; x < map.Width; x++) for (int y = 0; y < map.Height; y++) { map.TileMap[x, y].updateTile(getNeighbors(map, x, y)); } }
public static TileType[,] getNeighbors(Map map, int x, int y) { TileType[,] result = new TileType[3, 3] { { TileType.none, TileType.none, TileType.none }, { TileType.none, TileType.none, TileType.none }, { TileType.none, TileType.none, TileType.none } }; Rectangle mapRec = new Rectangle(0, 0, map.Width, map.Height); Rectangle neighborhood = new Rectangle(x - 1, y - 1, 3, 3); Rectangle intersect = Rectangle.Intersect(mapRec, neighborhood); for (int i = 0; i < intersect.Width; i++) for (int j = 0; j < intersect.Height; j++) { result[i + intersect.X - neighborhood.X, j + intersect.Y - neighborhood.Y] = map.TileMap[i + intersect.X, j + intersect.Y].TileType; } return result; }
internal static void decodeMap(Map map, MapData mapData, Color[,] rawMap) { map.Width = rawMap.GetLength(0); map.Height = rawMap.GetLength(1); map.TileMap = new Tile[map.Width, map.Height]; for (int y = 0; y < rawMap.GetLength(1); y++) { for (int x = 0; x < rawMap.GetLength(0); x++) { TileType type = TileType.none; COLOR_DECODER.TryGetValue(rawMap[x, y], out type); map.TileMap[x, y] = new Tile(map, type, new Vector2(x * GameState.TILE_SIZE, y * GameState.TILE_SIZE), mapData.levelTemplate); } } chooseFrames(map); }
public static Map loadRawMap(MapData mapData, GameScreen parent) { Map map = new Map(mapData.name, parent); Texture2D mapTexture = Engine.Content.Load<Texture2D>("levels/maps/" + mapData.mapImage); Color[] colors1D = new Color[mapTexture.Width * mapTexture.Height]; mapTexture.GetData<Color>(colors1D); Color[,] rawMap = new Color[mapTexture.Width, mapTexture.Height]; for (int x = 0; x < mapTexture.Width; x++) for (int y = 0; y < mapTexture.Height; y++) rawMap[x, y] = colors1D[x + y * mapTexture.Width]; decodeMap(map, mapData, rawMap); Dictionary<String, SpawnPoint> spawns = new Dictionary<string,SpawnPoint>(); foreach(SpawnPoint point in mapData.spawnPoints){ spawns.Add(point.name, point); } map.SpawnPoints = spawns; map.LevelDoors = mapData.exitPoints; return map; }