コード例 #1
0
ファイル: Play.cs プロジェクト: jl4312/Meteor-Freeze
        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;
            }
        }
コード例 #2
0
ファイル: Copy of Game1.cs プロジェクト: jl4312/Meteor-Freeze
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            childComponent = new List<GameObject>();

            platform = new Platform(new Rectangle(GraphicsDevice.Viewport.Width / 5 + 28, 10, 445, 650), this.Content);

            guage = new Guage(new Rectangle(platform.Position.X + platform.Position.Width + 2, 10, 100, 650), this.Content);
            Vector2 startingPos = platform.getMidPoint();
            player = new Munchlit(new Rectangle((int)startingPos.X, (int)startingPos.Y, 30, 30), this.Content);

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

            for (int i = platform.Position.X + 12; i <= platform.Position.X + platform.Position.Width - 24; i += 30)
            {
                Console.WriteLine(i);
                childComponent.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 45, 30, 30), this.Content, 0));
            }

            // TODO: use this.Content to load your game content here
        }