Exemple #1
0
        public Map(TmxMap tmxMap, string name)
        {
            this.TmxMap = tmxMap;
            Name = name;

            Width = tmxMap.Width;
            Height = tmxMap.Height;

            Tilesets = new List<Tileset>();
            foreach (TmxTileset tmxTileset in tmxMap.Tilesets)
            {
                Tilesets.Add(new Tileset(tmxTileset));
            }

            Objects = new List<MapObject>();
            foreach (TmxObjectGroup group in tmxMap.ObjectGroups)
            {
                foreach (TmxObject obj in group.Objects)
                {
                    Tileset tileset = GetTileset(obj.Tile != null ? obj.Tile.Gid : -1);

                    if (obj.Type == "npc")
                    {
                        Objects.Add(new NPC(obj, tileset, Name));
                    } else if (obj.Type == "player")
                    {
                        PlayerReference = new Player(obj, tileset);
                        Global.defaultObj = obj;
                        Global.defaultTileset = tileset;
                    } else if (obj.Type == "teleport")
                    {
                        Objects.Add(new Teleport(obj, tileset));
                    }
                    else if (obj.Type == "item")
                    {
                        Objects.Add(new ItemObject(obj, tileset));
                    } else
                    {
                        Objects.Add(new MapObject(obj, tileset, Name));
                    }
                }
            }

            // Populate above layers
            AboveLayers = new List<TmxLayer>();
            foreach (TmxLayer layer in tmxMap.Layers)
            {
                if (layer.Properties.ContainsKey("above") && layer.Properties["above"] == "true")
                    AboveLayers.Add(layer);
            }

            // Gets the song
            if (TmxMap.Properties.ContainsKey("song"))
            {
                song = TmxMap.Properties["song"];
            }

            PopulateCollisions();
        }
Exemple #2
0
        public void UpdatePlayers(List<PlayerInfo> players)
        {
            visiblePlayers.Clear();

            foreach (PlayerInfo info in players)
            {
                if (info.id == GameState.Instance.playerInfo.id)
                    continue;

                //TODO player factory
                Player p = new Player(Global.defaultObj, Global.defaultTileset);
                p.SetInfo(info);
                visiblePlayers[p.id] = p;
            }
        }