示例#1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            soundCenter = new SoundCenter(this);
            font        = Content.Load <SpriteFont>("MyFont");

            Services.AddService(typeof(SpriteBatch), spriteBatch);
            Services.AddService(typeof(SoundCenter), soundCenter);
            Services.AddService(typeof(SpriteFont), font);

            score = new Score(this);
            Components.Add(score);

            gameOverScene = new GameOverScene(this, score);
            gameOverScene.Hide();

            level2 = new Level2(this, score, gameOverScene, null);
            level1 = new Level1(this, score, gameOverScene, level2);

            Components.Add(level1);
            Components.Add(level2);
            Components.Add(gameOverScene);

            level1.Show();
            level2.Hide();

            curScene = level2;
        }
示例#2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            KeyboardState keyState = Keyboard.GetState();

            if (keyState.IsKeyDown(Keys.R) || keyState.IsKeyDown(Keys.F1))
            {
                level1.ResetLevel();
                level1.Show();

                gameOverScene.Hide();
                level2.Hide();
            }

            if (keyState.IsKeyDown(Keys.F2))
            {
                level2.Show();
                level2.ResetLevel();

                level1.Hide();
                gameOverScene.Hide();
            }

            base.Update(gameTime);
        }