コード例 #1
0
        public bool CanTransitionTo(Level level, Vector2 position)
        {
            LevelData transitionTarget = this.GetTransitionTarget(level, position);

            return(transitionTarget != null && !transitionTarget.Dummy);
        }
コード例 #2
0
        private void Load()
        {
            if (!File.Exists(this.Filepath))
            {
                return;
            }
            this.Strawberries = new List <EntityData>();
            BinaryPacker.Element element = BinaryPacker.FromBinary(this.Filepath);
            //string file = JsonConvert.SerializeObject(element);
            //File.WriteAllText("F:/test.json", file);
            if (!element.Package.Equals(this.ModeData.Path))
            {
                throw new Exception("Corrupted Level Data");
            }
            foreach (BinaryPacker.Element child1 in element.Children)
            {
                if (child1.Name == "levels")
                {
                    this.Levels = new List <LevelData>();
                    foreach (BinaryPacker.Element child2 in child1.Children)
                    {
                        LevelData levelData = new LevelData(child2);
                        this.DetectedStrawberries += levelData.Strawberries;
                        if (levelData.HasGem)
                        {
                            this.DetectedRemixNotes = true;
                        }
                        if (levelData.HasHeartGem)
                        {
                            this.DetectedHeartGem = true;
                        }
                        this.Levels.Add(levelData);
                    }
                }
                else if (child1.Name == "Filler")
                {
                    this.Filler = new List <Rectangle>();
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            this.Filler.Add(new Rectangle((int)child2.Attributes["x"], (int)child2.Attributes["y"], (int)child2.Attributes["w"], (int)child2.Attributes["h"]));
                        }
                    }
                }
                else if (child1.Name == "Style")
                {
                    if (child1.HasAttr("color"))
                    {
                        this.BackgroundColor = Util.HexToColor(child1.Attr("color", ""));
                    }
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            if (child2.Name == "Backgrounds")
                            {
                                this.Background = child2;
                            }
                            else if (child2.Name == "Foregrounds")
                            {
                                this.Foreground = child2;
                            }
                        }
                    }
                }
            }
            foreach (LevelData level in this.Levels)
            {
                foreach (EntityData entity in level.Entities)
                {
                    if (entity.Name == "strawberry")
                    {
                        this.Strawberries.Add(entity);
                    }
                    else if (entity.Name == "goldenBerry")
                    {
                        this.Goldenberries.Add(entity);
                    }
                }
            }
            int num1 = int.MaxValue;
            int num2 = int.MaxValue;
            int num3 = int.MinValue;
            int num4 = int.MinValue;

            foreach (LevelData level in this.Levels)
            {
                if (level.Bounds.xMin < num1)
                {
                    num1 = Mathf.RoundToInt(level.Bounds.xMin);
                }
                if (level.Bounds.top < num2)
                {
                    num2 = Mathf.RoundToInt(level.Bounds.top);
                }
                if (level.Bounds.xMax > num3)
                {
                    num3 = Mathf.RoundToInt(level.Bounds.xMax);
                }
                if (level.Bounds.bottom > num4)
                {
                    num4 = Mathf.RoundToInt(level.Bounds.bottom);
                }
            }
            foreach (Rectangle rectangle in this.Filler)
            {
                if (rectangle.Left < num1)
                {
                    num1 = rectangle.Left;
                }
                if (rectangle.Top < num2)
                {
                    num2 = rectangle.Top;
                }
                if (rectangle.Right > num3)
                {
                    num3 = rectangle.Right;
                }
                if (rectangle.Bottom > num4)
                {
                    num4 = rectangle.Bottom;
                }
            }
            int num5 = 64;

            this.Bounds = new Rectangle(num1 - num5, num2 - num5, num3 - num1 + num5 * 2, num4 - num2 + num5 * 2);
            this.ModeData.TotalStrawberries        = 0;
            this.ModeData.StartStrawberries        = 0;
            this.ModeData.StrawberriesByCheckpoint = new EntityData[10, 25];
            for (int index = 0; this.ModeData.Checkpoints != null && index < this.ModeData.Checkpoints.Length; ++index)
            {
                if (this.ModeData.Checkpoints[index] != null)
                {
                    this.ModeData.Checkpoints[index].Strawberries = 0;
                }
            }
            foreach (EntityData strawberry in this.Strawberries)
            {
                if (!strawberry.Bool("moon", false))
                {
                    int index1 = strawberry.Int("checkpointID", 0);
                    int index2 = strawberry.Int("order", 0);
                    if (this.ModeData.StrawberriesByCheckpoint[index1, index2] == null)
                    {
                        this.ModeData.StrawberriesByCheckpoint[index1, index2] = strawberry;
                    }
                    if (index1 == 0)
                    {
                        ++this.ModeData.StartStrawberries;
                    }
                    else if (this.ModeData.Checkpoints != null)
                    {
                        ++this.ModeData.Checkpoints[index1 - 1].Strawberries;
                    }
                    ++this.ModeData.TotalStrawberries;
                }
            }
        }