Beispiel #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            switch (GameState)
            {
            case GameStates.InGame:
                InGame.Draw(spriteBatch);
                break;

            case GameStates.MainMenu:
                Main.Draw(spriteBatch);
                break;

            case GameStates.HighScore:
                HighScore.Draw(spriteBatch);
                break;

            case GameStates.Credits:
                Credits.Draw(spriteBatch);
                break;

            case GameStates.Exit:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            base.Draw(gameTime);
        }
Beispiel #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 || Keyboard.GetState().IsKeyDown(Keys.End))
            {
                this.Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges();
            }

            switch (GameState)
            {
            case GameStates.InGame:
                if (IsMouseVisible)
                {
                    IsMouseVisible = !IsMouseVisible;                    // set mouse not visible
                }
                InGame.Update(gameTime);
                break;

            case GameStates.MainMenu:
                if (!IsMouseVisible)
                {
                    IsMouseVisible = !IsMouseVisible;                      // set mouse visible
                }
                Main.Update();
                break;

            case GameStates.HighScore:
                if (!IsMouseVisible)
                {
                    IsMouseVisible = !IsMouseVisible;                      // set mouse visible
                }
                HighScore.Update();
                break;

            case GameStates.Credits:
                if (!IsMouseVisible)
                {
                    IsMouseVisible = !IsMouseVisible;                      // set mouse visible
                }
                Credits.Update(gameTime);
                break;

            case GameStates.Exit:
                this.Exit();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            InGame.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #3
0
        /// <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);

#if DEBUG
            DebugFont = Content.Load <SpriteFont>(@"Fonts/Debug");
#endif
            Main.LoadContent(Content, GraphicsDevice.Viewport);
            InGame.LoadContent(Content, GraphicsDevice.Viewport);
            HighScore.LoadContent(Content, GraphicsDevice.Viewport);
            Credits.LoadContent(Content, GraphicsDevice.Viewport);
        }
        public static void LoadContent(ContentManager content, Viewport viewport)
        {
            _menu = new Menu(content.Load <Texture2D>(@"Textures/Menu/MainMenuBackground"),
                             new Button[]
            {
                new Button(new Point(0, 0),
                           new Rectangle(100, 200, 200, 50),
                           content.Load <Texture2D>(@"Textures/Menu/playButton"),
                           content.Load <Texture2D>(@"Textures/Menu/playButtonPressed"),
                           () =>
                {
                    Game1.GameState = Game1.GameStates.InGame;
                    InGame.StartLevel(0);
                }),

                new Button(new Point(1, 0),
                           new Rectangle(400, 200, 200, 50),
                           content.Load <Texture2D>(@"Textures/Menu/highscoresButton"),
                           content.Load <Texture2D>(@"Textures/Menu/highscoresButtonPressed"),
                           () => Game1.GameState = Game1.GameStates.HighScore),

                new Button(new Point(2, 0),
                           new Rectangle(700, 200, 200, 50),
                           content.Load <Texture2D>(@"Textures/Menu/creditsButton"),
                           content.Load <Texture2D>(@"Textures/Menu/creditsButtonPressed"),
                           () => Game1.GameState = Game1.GameStates.Credits),

                new Button(new Point(3, 0),
                           new Rectangle(1000, 200, 200, 50),
                           content.Load <Texture2D>(@"Textures/Menu/exitButton"),
                           content.Load <Texture2D>(@"Textures/Menu/exitButtonPressed"),
                           () => Game1.GameState = Game1.GameStates.Exit),
            },
                             new MenuControlScheme(Keys.W, Keys.S, Keys.A, Keys.D, Keys.Enter),
                             viewport);
        }