Esempio n. 1
0
        public SpriteSheet(int textureId, Tileset tileset)
        {
            this.Tileset = tileset;

            int sheetsWide = tileset.TilesWide / 3;

            int y = textureId / (tileset.TilesWide * 4);
            int x = ((textureId - (y * tileset.TilesWide * 4)) / 3) % sheetsWide;

            GidDown = 1 + (x * 3) + (y * 4 * tileset.TilesWide);
            GidLeft = GidDown + tileset.TilesWide;
            GidRight = GidDown + tileset.TilesWide * 2;
            GidUp = GidDown + tileset.TilesWide * 3;
        }
Esempio n. 2
0
        public NPC(TmxObject obj, Tileset tileset, string mapName) : base(obj, tileset, mapName)
        {
            Sheet = new SpriteSheet(TextureId, tileset);
            DialogId = obj.Properties.ContainsKey("dialog") ? int.Parse(obj.Properties["dialog"]) : -1;

            if (TextureId == Sheet.GidUp)
                Direction = FacingDirection.Up;
            else if (TextureId == Sheet.GidLeft)
                Direction = FacingDirection.Left;
            else if (TextureId == Sheet.GidRight)
                Direction = FacingDirection.Right;
            else
                Direction = FacingDirection.Down;

            DefaultDirection = Direction;
        }
Esempio n. 3
0
        public MapObject(TmxObject obj, Tileset tileset, string mapName = "")
        {
            // Name
            Name = obj.Name != null ? obj.Name : "NoName";

            // Identifier used for ObjectInfo instance
            Identifier = String.Format("{0}_{1}_{2}", obj.Id, mapName, Name).Replace(" ", string.Empty);

            // ObjectInfo instance, holding information about the object in runtime
            SavedInformation = new ObjectInfo(Identifier);
            if (obj.Properties.ContainsKey("active"))
            {
                SavedInformation.IsActive = obj.Properties["active"] == "true" ? true : false;
            }

            // Gets the script id
            ScriptId = obj.Properties.ContainsKey("script") ? int.Parse(obj.Properties["script"]) : -1;

            // Gets the name color
            if (obj.Properties.ContainsKey("color"))
            {
                string[] rgba = obj.Properties["color"].Split(',');
                NameColor = rgba.Count() == 4 ? new Color(float.Parse(rgba[0]), float.Parse(rgba[1]), float.Parse(rgba[2]), float.Parse(rgba[3])) : Color.White;
            } else
            {
                NameColor = Color.White;
            }

            // Gets texture information
            Texture = tileset.Texture;
            TextureId = obj.Tile != null ? obj.Tile.Gid - tileset.FirstGid : -1;

            // Workaround for the Y axis when it's a tile object (instead of rectangle)
            int y = obj.ObjectType == TmxObjectType.Tile ? (int)obj.Y - 1 : (int)obj.Y;

            // Sets position
            MapPosition = new Vector2((int)obj.X / Global.TileSize, y / Global.TileSize);
            CurrentPosition = MapPosition * Global.TileSize;
            DestinationPosition = CurrentPosition;
            IsMoving = false;

            // Width and height for objects bigger than a tile
            Size = new Vector2((int)obj.Width / Global.TileSize, (int)obj.Height / Global.TileSize);
        }
Esempio n. 4
0
        public Teleport(TmxObject obj, Tileset tileset) : base(obj, tileset)
        {
            string[] property = obj.Properties["teleport"].Split(',');
            Map = property[0];
            TeleportPosition = new Vector2(int.Parse(property[1]), int.Parse(property[2]));

            switch (property[3])
            {
                case "up":
                    Direction = FacingDirection.Up;
                    break;
                case "down":
                    Direction = FacingDirection.Down;
                    break;
                case "left":
                    Direction = FacingDirection.Left;
                    break;
                case "right":
                    Direction = FacingDirection.Right;
                    break;
            }
        }
Esempio n. 5
0
 public Player(TmxObject obj, Tileset tileset) : base(obj, tileset, "")
 {
     Name = "Stryfe";
     Attributes = new AttributeSheet();
 }