Ejemplo n.º 1
0
        public static Level ParseLevel(string path, ResourcePool res)
        {
            var levelTemplate = JsonConvert.DeserializeObject <LevelJ>(File.ReadAllText(path));

            float translateX = 1 / (100f / Globals.SCREEN_WIDTH);
            float translateY = 1 / (100f / Globals.SCREEN_HEIGHT);

            // Add all enemies to the list
            var enemies = new List <Enemy>();

            if (levelTemplate.Enemies != null)
            {
                levelTemplate.Enemies.ForEach(enemyT => {
                    var func = GetLambda(enemyT.Path.Func);
                    enemies.Add(new Enemy(
                                    sprite: new Sprite(res.GetTexture(enemyT.Texture),
                                                       X: enemyT.Rectangle.X * translateX - enemyT.Rectangle.X / 2,
                                                       Y: enemyT.Rectangle.Y * translateY - enemyT.Rectangle.Y / 2,
                                                       W: enemyT.Rectangle.W,
                                                       H: enemyT.Rectangle.H,
                                                       color: new Color(enemyT.Color.R / 255f, enemyT.Color.G / 255f, enemyT.Color.B / 255f)),
                                    healthBarTexture: res.GetTexture("pixel"),
                                    health: enemyT.Health,
                                    value: enemyT.Value,
                                    path: new Path(enemyT.Path.Speed, enemyT.Path.Angle, func),
                                    delay: enemyT.Delay));
                });
            }

            if (levelTemplate.Templates != null)
            {
                levelTemplate.Templates.ForEach(enemyT => {
                    var tmp = ParseEnemyTemplate(res, enemyT);
                    tmp.X  *= translateX;
                    enemies.Add(tmp);
                });
            }

            // create player
            var player = new Player(
                res,
                levelTemplate.Player.Rectangle.X * translateX - levelTemplate.Player.Rectangle.W / 2,
                levelTemplate.Player.Rectangle.Y * translateY - levelTemplate.Player.Rectangle.H / 2,
                levelTemplate.Player.Rectangle.W,
                levelTemplate.Player.Rectangle.H,
                new Color(levelTemplate.Player.Color.R / 255f, levelTemplate.Player.Color.G / 255f, levelTemplate.Player.Color.B / 255f)
                );

            return(new Level(enemies, player, res.GetFont(levelTemplate.UiFont), res));
        }
Ejemplo n.º 2
0
        protected void LateInit()
        {
            levelSelect = new Menu();
            res.AddView("levelSelect", levelSelect);
            mainMenu = new Menu();
            res.AddView("mainMenu", mainMenu);

            var tempPos = new Vector2(Globals.SCREEN_WIDTH / 6, 280);

            Directory.EnumerateFiles("Levels").ToList().ForEach(element =>
            {
                res.AddView(element, Parser.ParseLevel(element, res));
                levelSelect.AddInteractive(new Button(
                                               System.IO.Path.GetFileNameWithoutExtension(element),
                                               res.GetFont("Forced"),
                                               tempPos,
                                               Color.White,
                                               Color.Yellow,
                                               ViewEvent.ChangeView(res.GetView(element))));
                if (tempPos.Y < Globals.SCREEN_HEIGHT - 100)
                {
                    tempPos.Y += 100;
                }
                else
                {
                    tempPos.Y += 280; tempPos.X += Globals.SCREEN_WIDTH / 6;
                }
            });


            levelSelect.AddStatic(new Text("Select Level", res.GetFont("Earth Orbiter"), new Vector2(Globals.SCREEN_WIDTH / 2, 100), Color.Yellow, Align.Center));
            levelSelect.BackEvent = ViewEvent.ChangeView(res.GetView("mainMenu"));

            mainMenu.AddStatic(new Text(
                                   "Void Warrior",
                                   res.GetFont("Earth Orbiter"),
                                   new Vector2(Globals.SCREEN_WIDTH / 2, 100),
                                   Color.Yellow,
                                   Align.Center));
            mainMenu.AddInteractive(new Button(
                                        "Start",
                                        res.GetFont("Guardians"),
                                        new Vector2(Globals.SCREEN_WIDTH / 2, 400),
                                        Color.White, Color.Yellow,
                                        ViewEvent.ChangeView(levelSelect),
                                        Align.Center));
            mainMenu.AddInteractive(new Button(
                                        "Quit",
                                        res.GetFont("Guardians"),
                                        new Vector2(Globals.SCREEN_WIDTH / 2, 500),
                                        Color.White, Color.Yellow,
                                        ViewEvent.Back,
                                        Align.Center));

            currentView = mainMenu;



            //controllerStatus = new Text(Input.GamepadConnected.ToString(), res.GetFont("Guardians"), 0, 0, Color.White);
            parallax = new Parallax(res.GetTexture("BackgroundBack"), res.GetTexture("BackgroundFront"));
        }