Ejemplo n.º 1
0
        private Map LoadMap(string fileName)
        {
            Map map = new Map();

            using (FileStream fileStream = new FileStream(fileName, 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.SetTile(x, y, new Map.Tile());

                            map.GetTile(x, y).Blocked = binaryReader.ReadBoolean();

                            foreach (Layers layer in Enum.GetValues(typeof(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();

                                var tileLayer = new Map.Tile.Layer
                                {
                                    SpriteRect = new Rect(tileLeft, tileTop, tileHeight, tileWidth),
                                    TextureNumber = tileSetTextureIndex
                                };
                                map.GetTile(new Vector(x, y)).SetLayer(tileLayer, layer);
                            }
                        }
                    }
                }
            }
            return map;
        }
Ejemplo n.º 2
0
        public void JoinMap(Map map)
        {
            if (this.Map != null)
                this.LeaveMap(false);

            map.AddPlayer(this);
            this.Map = map;
            this.MapNum = ContentManager.Instance.MapManager.GetMapIndex(map);

            this.InMap = false;

            Packet packet = new Packet(PacketType.MapCheckPacket);
            packet.Message.Write(this.Map.Name);
            packet.Message.Write(this.Map.Version);
            this.Connection.SendMessage(packet.Message, NetDeliveryMethod.ReliableOrdered, (int)ChannelTypes.WORLD);
        }
Ejemplo n.º 3
0
 public int GetMapIndex(Map map)
 {
     return _maps.IndexOf(map);
 }
Ejemplo n.º 4
0
 public void AddMap(Map map)
 {
     _maps.Add(map);
 }