예제 #1
0
        public static Map LoadMap(string filePath, List<Texture> tileSetTextures)
        {
            Map map = new Map();

            using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    map.Name = binaryReader.ReadString();

                    map.Version = binaryReader.ReadInt32();

                    int mapWidth = binaryReader.ReadInt32();
                    int mapHeight = binaryReader.ReadInt32();

                    map.ResizeMap(mapWidth, mapHeight);

                    for (int x = 0; x < mapWidth; x++)
                    {
                        for (int y = 0; y < mapHeight; y++)
                        {
                            map.tiles[x, y] = new Tile();

                            map.tiles[x, y].Blocked = binaryReader.ReadBoolean();

                            if (map.tiles[x, y].Blocked)
                            {
                                map.tiles[x, y].BlockedCover = new RectangleShape(new Vector2f(32, 32));
                                map.tiles[x, y].BlockedCover.FillColor = new Color(255, 0, 0, 100);
                                map.tiles[x, y].BlockedCover.Position = new Vector2f(x * 32, y * 32);
                            }

                            foreach (Layers layer in Enum.GetValues(typeof(Map.Layers)))
                            {
                                if (binaryReader.ReadBoolean() == false) continue;

                                int tileSetTextureIndex = binaryReader.ReadInt32();
                                int tileLeft = binaryReader.ReadInt32();
                                int tileTop = binaryReader.ReadInt32();
                                int tileWidth = binaryReader.ReadInt32();
                                int tileHeight = binaryReader.ReadInt32();

                                map.tiles[x, y].Layers[(int)layer] = new Tile.Layer(new Sprite(tileSetTextures[tileSetTextureIndex], new IntRect(tileLeft, tileTop, tileWidth, tileHeight)), x, y);
                            }
                        }
                    }
                }
            }

            return map;
        }
예제 #2
0
        private void newMapButton_Click(object sender, EventArgs e)
        {
            Map map = new Map();
            map.Name = "Untitled " + maps.Count;
            map.ResizeMap(25, 25);

            this.maps.Add(map);
            this.mapList.Items.Add(map.Name);
        }