Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            if (game.GetGameState() == Game1.GameState.HighScores)
            {
                keyboard = Keyboard.GetState();

                if (CheckKeyboard(Keys.Enter))
                {
                    game.SetGameState(Game1.GameState.MainMenu);
                }

                prevKeyboard = keyboard;
            }
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            int lifeSpacingX = screenWidth - 3 * (imagePlayer.Width + 5);

            if (game.GetGameState() == Game1.GameState.Playing)
            {
                spriteBatch.Begin();


                if (!gameOver)
                {
                    spriteBatch.DrawString(font, "SCORE: " + score, new Vector2(0, 0), Color.White);
                    spriteBatch.DrawString(font, "LIVES: ", new Vector2(screenWidth - 190, 0), Color.White);
                    spriteBatch.DrawString(font, "HIGH SCORE: " + highScore, new Vector2(310, 0), Color.White);
                    spriteBatch.DrawString(font, "LEVEL: " + alienSquad.getLevel(), new Vector2(0, 20), Color.White);

                    spriteBatch.Draw(imagePlayer, new Vector2(lifeSpacingX, 0), Color.White);

                    // If player has more than 3 lives the display changes to compress the display instead of having multiple little pictures
                    if (lives > 3)
                    {
                        spriteBatch.DrawString(font, " x " + lives, new Vector2(screenWidth - 85, 0), Color.White);
                    }
                    else
                    {
                        for (int i = 0; i < (lives - 1); i++)
                        {
                            spriteBatch.Draw(imagePlayer, new Vector2(lifeSpacingX + imagePlayer.Width + 5, 0), Color.White);
                            lifeSpacingX += imagePlayer.Width + 5;
                        }
                    }
                }
                else
                {
                    /*
                     * if (score > highScore)
                     * {
                     *  highScoreObject.WriteHighScore(score);
                     * }*/
                    //endOfGame = true;//So the Game Over Menu will show
                    game.SetGameState(Game1.GameState.GameOverMenu);
                }


                spriteBatch.End();
            }
            base.Draw(gameTime);
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            if (game.GetGameState() == Game1.GameState.MainMenu)
            {
                if (!songPlaying)
                {
                    titleSongInstance.Play();
                    songPlaying = true;
                }

                keyboard = Keyboard.GetState();

                //Checks for input from user that represent going up
                if (CheckKeyboard(Keys.Up) || CheckKeyboard(Keys.W))
                {
                    //Will not go up further than top list item, wraps to bottom item
                    if (selected > 0)
                    {
                        selected--;
                    }
                    else if (selected == 0)
                    {
                        selected = menuItems.Count - 1;
                    }
                }

                //Checks for input from user that represent going down
                if (CheckKeyboard(Keys.Down) || CheckKeyboard(Keys.S))
                {
                    //Will not go lower than bottom list item, wraps to top item
                    if (selected < menuItems.Count - 1)
                    {
                        selected++;
                    }
                    else if (selected == (menuItems.Count - 1))
                    {
                        selected = 0;
                    }
                }

                //Checks for input from user that represents 'enter'
                if (CheckKeyboard(Keys.Enter))
                {
                    switch (selected)
                    {
                    case 0:
                    {
                        titleSongInstance.Stop();
                        timer.Start();
                        break;
                    }

                    case 1:
                    {
                        game.SetGameState(Game1.GameState.HighScores);
                        break;
                    }

                    case 2:
                    {
                        game.SetGameState(Game1.GameState.Exit);
                        break;
                    }
                    }
                }

                prevKeyboard = keyboard;
            }

            base.Update(gameTime);
        }
Ejemplo n.º 4
0
        public override void Update(GameTime gameTime)
        {
            if (game.GetGameState() == Game1.GameState.GameOverMenu)
            {
                keyboard = Keyboard.GetState();

                //Makes sure user does not need to enter initial for highscore, if so controls are overriden
                if (!lockControls)
                {
                    //Checks for input from user that represent going up
                    if (CheckKeyboard(Keys.Up) || CheckKeyboard(Keys.W))
                    {
                        //Will not go up further than top list item, wraps to bottom item
                        if (selected > 0)
                        {
                            selected--;
                        }
                        else if (selected == 0)
                        {
                            selected = menuItems.Count - 1;
                        }
                    }

                    //Checks for input from user that represent going down
                    if (CheckKeyboard(Keys.Down) || CheckKeyboard(Keys.S))
                    {
                        //Will not go lower than bottom list item, wraps to top item
                        if (selected < menuItems.Count - 1)
                        {
                            selected++;
                        }
                        else if (selected == (menuItems.Count - 1))
                        {
                            selected = 0;
                        }
                    }

                    //Checks for input from user that represents 'enter'
                    if (CheckKeyboard(Keys.Enter))
                    {
                        switch (selected)
                        {
                        //Game restart case
                        case 0:
                        {
                            timer.Start();
                            initialCtr      = 0;
                            lockControls    = false;
                            releaseControls = false;
                            game.restartGame();
                            break;
                        }

                        //Main menu case
                        case 1:
                        {
                            //game.restartGame();
                            //game.SetGameState(Game1.GameState.MainMenu);
                            break;
                        }

                        //Exit case
                        case 2:
                        {
                            game.SetGameState(Game1.GameState.Exit);
                            break;
                        }
                        }
                    }
                }

                score     = game.GetGameScore();
                highScore = game.GetGameHighScore();


                //Will not accept key input if game controls are active
                if (lockControls)
                {
                    acceptHighScoreInitials();
                }

                prevKeyboard = keyboard;
            }



            base.Update(gameTime);
        }