Beispiel #1
0
        /// <summary> Loads the current level </summary>
        public void LoadLevel()
        {
            DisposeElements();
            String[] data = LevelController.Instance.CurrentLevel.Data;

            Vector2 playerStart = Vector2.Zero;

            foreach (String element in data)
            {
                if (String.IsNullOrEmpty(element) || element.Equals("\r"))
                {
                    continue;
                }
                String[] elementData = element.Split(',');
                switch (elementData[0])
                {
                case "Sprite":
                    _LevelDrawables.Add(new Sprite(ZippyGame.MainCanvas, elementData));
                    break;

                case "TextDisplay":
                    _LevelDrawables.Add(new TextDisplay(ZippyGame.MainCanvas, elementData));
                    break;

                case "AnimatedSprite":
                    _LevelDrawables.Add(new AnimatedSprite(ZippyGame.MainCanvas, elementData));
                    break;

                case "PlayerStart":
                    String[] position = elementData[1].Split('|');
                    XVector2 pos      = new XVector2(Single.Parse(position[0], CultureInfo.InvariantCulture), Single.Parse(position[1], CultureInfo.InvariantCulture));
                    _Zippy.SetStartPosition(pos);
                    break;

                case "CameraLimits":
                    ZippyGame.Camera.SetLimits(elementData);
                    _LeftCollider.Position  = ConvertUnits.ToSimUnits(new XVector2(ZippyGame.Camera.TopLeft.X - (Renderer.Instance.TargetDimensions.X / 2 - 10), ZippyGame.Camera.TopLeft.Y));
                    _RightCollider.Position = ConvertUnits.ToSimUnits(new XVector2(ZippyGame.Camera.BottomRight.X + (Renderer.Instance.TargetDimensions.X / 2 + 10), ZippyGame.Camera.BottomRight.Y));
                    break;

                default:
                    if (!SceneTypeMap.TypeExists(elementData[0]))
                    {
                        throw new KeyNotFoundException($"The given type {elementData[0]} is not in the type map");
                    }
                    Object obj = Activator.CreateInstance(SceneTypeMap.GetType(elementData[0]), new Object[] { elementData });
                    if (obj is Enemy)
                    {
                        _Enemies.Add((Enemy)obj);
                    }
                    else if (obj is Collectible)
                    {
                        _Collectibles.Add((Collectible)obj);
                    }
                    else if (obj is Platform)
                    {
                        _Platforms.Add((Platform)obj);
                    }
                    break;
                }
            }
        }