public static Map Generate(TiledSharp.Map map)
        {
            var go = new GameObject();
            go.name = "Level";

            var ret = go.AddComponent<Map>();
            ret.Load(map);
            return ret;
        }
Exemplo n.º 2
0
 /** Constructs a tile. The position is subtracted from the tile count to account for up=down issue.*/
 public Sprite(TiledSharp.TmxLayerTile tile, Tileset tileset, int genericTileWidth, int genericTileHeight, int tileCountY)
     : base(new Util.Rect(tile.X * genericTileWidth,
         (tileCountY - tile.Y - 1) * genericTileHeight,
         tileset.tileWidth,
         tileset.tileHeight))
 {
     visible = tile.Gid != 0;
     setUV(tile.Gid < 1 ? 0 : ((tile.Gid - tileset.firstGid) % tileset.tileCountX) * tileset.tileWidth,
         tile.Gid < 1 ? 0 : ((tile.Gid - tileset.firstGid) / tileset.tileCountX) * tileset.tileHeight);
     this.tileset = tileset;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TiledMapObject" /> class.
        /// </summary>
        /// <param name="tmxObject">The TMX parsed object</param>
        public TiledMapObject(TiledSharp.TmxObjectGroup.TmxObject tmxObject)
        {
            this.Name = tmxObject.Name;
            this.ObjectType = (TiledMapObjectType)((int)tmxObject.ObjectType);
            this.Type = tmxObject.Type;
            this.X = tmxObject.X;
            this.Y = tmxObject.Y;
            this.Width = tmxObject.Width;
            this.Height = tmxObject.Height;
            this.Rotation = tmxObject.Rotation;
            this.Visible = tmxObject.Visible;

            this.Properties = new Dictionary<string, string>(tmxObject.Properties);
            if (tmxObject.Points != null)
            {
                this.Points = new List<Tuple<int, int>>(tmxObject.Points);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method create one specific object
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="zIndex"></param>
        private void CreateOneObject(TiledSharp.TmxObjectGroup.TmxObject obj, Int32 zIndex, Boolean isLayerVisible)
        {
            String name = obj.Name;

            String type = obj.Type == null ? String.Empty : obj.Type;

            Vector size = GetObjectSize(obj);

            Double rotation = GetObjectRotation(obj);

            Vector center = new Vector(obj.X + size.X, obj.Y - size.Y);

            Locator loc = new Locator(center, rotation, tmxMap.Layers.Count + zIndex);

            Viewer viewer = GetObjectView(obj.Tile, isLayerVisible && obj.Visible);

            CollisionShape shape = GetObjectShape(obj);

            builder.BuildSpecialObject(name, type, loc, size, shape, viewer);          
        }
Exemplo n.º 5
0
        public void Load(TiledSharp.Map map)
        {
            foreach (var tile in map.Layers[0].Tiles)
            {
                var coor = new Coor(tile.X, MapHeight - tile.Y);
                GameObject go = null;

                switch (tile.Gid)
                {
                    case StartGid:
                        StartPoisition = coor;
                        break;

                    case StarGid:
                    {
                        var star = MapFactory.InstantiateStar(coor);
                        Stars.Add(star);
                        go = star.gameObject;
                        break;
                    }

                    default:
                    {
                        var gid = MapHelper.MapGidToBlockType(tile.Gid);
                        if (gid.HasValue)
                        {
                            var block = MapFactory.Instantiate(gid.Value, coor);
                            go = block.gameObject;
                        }
                        break;
                    }
                }

                if (go != null)
                {
                    go.transform.SetParent(transform, false);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method return object size
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private Vector GetObjectSize(TiledSharp.TmxObjectGroup.TmxObject obj)
        {
            Vector size = new Vector(0, 0);

            switch (obj.ObjectType.ToString())
            {
                case "Basic":
                    {
                        size = new Vector(obj.Width / 2, obj.Height / 2);
                    }
                    break;
                case "Circle":
                    {
                        size = new Vector(obj.Width / 2, obj.Height / 2);
                    }
                    break;

                case "Tile":
                    {
                        int sizeX = tmxMap.TileWidth / 2;
                        int sizeY = tmxMap.TileHeight / 2;

                        size = new Vector(sizeX, sizeY);
                    }
                    break;
            }

            return size;
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method check, what object collision type is(Circle or rectangle)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private CollisionShape GetObjectShape(TiledSharp.TmxObjectGroup.TmxObject obj)
        {
            CollisionShape shape = CollisionShape.None;

            switch (obj.ObjectType.ToString())
            {
                case "Basic":
                    {
                        shape = CollisionShape.Rectangle;
                    }
                    break;
                case "Circle":
                    {
                        shape = CollisionShape.Circle;
                    }
                    break;

                case "Tile":
                    {
                        shape = CollisionShape.Rectangle;
                    }
                    break;
            }

            return shape;
        }
Exemplo n.º 8
0
        /// <summary>
        /// This method return rotation angle of object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private Double GetObjectRotation(TiledSharp.TmxObjectGroup.TmxObject obj)
        {
            Double rotation = -obj.Rotation;

            while (rotation < 0) rotation += 360;

            rotation %= 360;

            return rotation;
        }