Пример #1
0
        public override void Initialize()
        {
            childComponents = new List<GameObject>();
            ioManager = new IOManager();
            font = gameRef.Content.Load<SpriteFont>("SpriteFont1");

            platform = new Platform(new Rectangle(18, 40, 445, 650), gameRef.Content);
            guage = new Guage(new Rectangle(platform.Position.X + platform.Position.Width + 2, 40, 100, 650), gameRef.Content);
            Vector2 startingPos = platform.getMidPoint();
            player = new Munchlit(new Rectangle((int)startingPos.X, (int)startingPos.Y, 20, 20), gameRef.Content);

            childComponents.Add(platform);
            childComponents.Add(guage);
            childComponents.Add(player);

            for (int i = platform.Position.X + 12; i <= platform.Position.X + platform.Position.Width - 24; i += 30)
            {

                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 45, 30, 30), gameRef.Content, 0));
                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 75, 30, 30), gameRef.Content, 0));
                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 105, 30, 30), gameRef.Content, 0));
            }

            guiManager.AddLabel("HighScore", font, "Highscore: " + 0);
            guiManager["HighScore"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 40.0f);
            guiManager["HighScore"].Size = new Vector2(200.0f, 75.0f);
            guiManager["HighScore"].Color = Color.Black;

            guiManager.AddLabel("level", font, "Level: " + level);
            guiManager["level"].Position = new Vector2(platform.Position.X + platform.Position.Width / 3 + 20, 10.0f);
            guiManager["level"].Size = new Vector2(150, 20.0f);
            guiManager["level"].Color = Color.Black;

            guiManager.AddLabel("time", font, "Timer: " + timer);
            guiManager["time"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 70.0f);
            guiManager["time"].Size = new Vector2(200.0f, 75.0f);
            guiManager["time"].Color = Color.Black;

            guiManager.AddLabel("lives", font, "Lives: " + player.Lives);
            guiManager["lives"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 100.0f);
            guiManager["lives"].Size = new Vector2(150.0f, 20.0f);
            guiManager["lives"].Color = Color.Black;

            guiManager.AddLabel("points", font, "Points: " + player.Point);
            guiManager["points"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 130.0f);
            guiManager["points"].Size = new Vector2(150.0f, 20.0f);
            guiManager["points"].Color = Color.Black;

            guiManager.AddPicture("tmp", gameRef.Content.Load<Texture2D>("Freezling"));
            guiManager["tmp"].Position = new Vector2(guage.Position.X + guage.Position.Width + 30, 200.0f);
            guiManager["tmp"].Size = new Vector2(200.0f, 200.0f);

            guiManager.AddButton("pause", "PAUSE", guage.Position.X + guage.Position.Width + 10, 400, 200.0f, 75.0f);

            guiManager.AddButton("btnMainMenu", "Menu", guage.Position.X + guage.Position.Width + 10, 500, 200.0f, 75.0f);

            guiManager.AddButton("btnExit", "Exit", guage.Position.X + guage.Position.Width + 10, 600, 200.0f, 75.0f);

            btnMainMenu = guiManager["btnMainMenu"] as Button;
            btnMainMenu.Click += (control, button) =>
            {
                GameState MainMenu = this.parent[GameStateType.Playing];
                if (MainMenu != null)
                {
                    this.parent.PushState(MainMenu);

                    MainMenu MainMenuState = new MainMenu(this.gameRef, this.renderer, this.parent);
                    MainMenu.Initialize();
                    this.parent.PushState(MainMenuState);

                }
            };

            btnExit = guiManager["btnExit"] as Button;
            btnExit.Click += (control, button) =>
            {
                gameRef.Exit();
            };

            try
            {
                highScore = ioManager.LoadHighScore();
            }
            catch (Exception)
            {
                ioManager.SaveHighScore(0);
                highScore = 0;
            }
        }