Beispiel #1
0
 /// <summary>
 /// Resets the game if we start the game again.
 /// </summary>
 private static void ResetGame()
 {
     CameraManager.Reset();
     ItemManager.Reset();
     BackgroundManager.Reset();
     PlayerManager.Reset();
 }
Beispiel #2
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);

            //Load the personal scores and sound setting
            ScoresData = personalScoresSaver.LoadMyData("LocalScores");
            if (ScoresData == null)
            {
                ScoresData = new LocalScores();
            }
            SoundManager.PlaySounds = ScoresData.soundOn;

            //Create banner ad on the screen
            bannerAd = adManager.CreateAd("10016958", new Rectangle(160, 0, 480, 80), RotationMode.Manual, false);

            //Load all the graphics
            gameScreen     = Content.Load <Texture2D>(@"MenuScreens\gamestartscreen");
            howToScreen    = Content.Load <Texture2D>(@"MenuScreens\howtoscreen");
            highScores     = Content.Load <Texture2D>(@"MenuScreens\highscoresscreen");
            contactInfo    = Content.Load <Texture2D>(@"MenuScreens\contactscreen");
            myScoresScreen = Content.Load <Texture2D>(@"MenuScreens\myscoresscreen");
            spriteSheet    = Content.Load <Texture2D>("spritesheet");
            background1    = Content.Load <Texture2D>("background01");
            background2    = Content.Load <Texture2D>("background02");
            pausedScreen   = Content.Load <Texture2D>(@"MenuScreens\pausedscreen");
            submitScore    = Content.Load <Texture2D>(@"MenuScreens\enterhighscore");
            offonSprite    = Content.Load <Texture2D>(@"MenuScreens\offonsprite");

            //Load all the fonts
            highScoresFont  = Content.Load <SpriteFont>(@"Fonts\highscores");
            submitScoreFont = Content.Load <SpriteFont>(@"Fonts\submitscores");
            scoreFont       = Content.Load <SpriteFont>(@"Fonts\score");

            //Set the size of the WHOLE world and the viewable screen
            CameraManager.WorldRectangle = new Rectangle(0, 0, 1600, 1440);
            CameraManager.ViewPortWidth  = 800;
            CameraManager.ViewPortHeight = 480;

            //Initialize all the managers
            BackgroundManager.Initialize(background1, background2, new Rectangle(0, 0, 1600, 1440), 1);
            PlayerManager.Initialize(spriteSheet, new Rectangle(0, 0, 161, 86), new Vector2(65, 200), 2);
            ItemManager.Initialize(spriteSheet);
            SoundManager.Initialize(Content);
            HighScoreTable.Initialize();

            //Set the locations of the buttons for touching
            startGameButton   = new MenuItem(new Rectangle(40, 240, 250, 55));
            howToButton       = new MenuItem(new Rectangle(40, 325, 275, 55));
            myScoresButton    = new MenuItem(new Rectangle(40, 416, 235, 55));
            highScoresButton  = new MenuItem(new Rectangle(488, 240, 270, 55));
            contactInfoButton = new MenuItem(new Rectangle(465, 325, 305, 55));
            soundButton       = new MenuItem(new Rectangle(488, 416, 270, 55));

            yesScore = new MenuItem(new Rectangle(257, 282, 121, 51));
            noScore  = new MenuItem(new Rectangle(439, 282, 121, 51));
            yesExit  = new MenuItem(new Rectangle(257, 307, 121, 51));
            noExit   = new MenuItem(new Rectangle(439, 307, 121, 51));
        }
Beispiel #3
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.CornflowerBlue);

            spriteBatch.Begin();

            switch (gameState)
            {
            case GameStates.TitleScreen:
                spriteBatch.Draw(gameScreen, Vector2.Zero, Color.White); //draw the title screen
                if (SoundManager.PlaySounds)                             //check if the sound is on and draw the appropriate switch on/off
                {
                    spriteBatch.Draw(offonSprite, new Vector2(659, 413), new Rectangle(101, 0, 92, 50), Color.White);
                }
                else
                {
                    spriteBatch.Draw(offonSprite, new Vector2(659, 413), new Rectangle(0, 0, 100, 50), Color.White);
                }
                break;

            case GameStates.ContactInfo:
                spriteBatch.Draw(contactInfo, Vector2.Zero, Color.White);      //draw the contact info screen
                break;

            case GameStates.HowTo:
                spriteBatch.Draw(howToScreen, Vector2.Zero, Color.White);      //draw the how to screen
                break;

            case GameStates.HighScores:
                spriteBatch.Draw(highScores, Vector2.Zero, Color.White); //draw the high score screen
                getHighScores();                                         //call to get high scores online
                break;

            case GameStates.MyScores:
                spriteBatch.Draw(myScoresScreen, Vector2.Zero, Color.White); //draw the my scores screen
                getLocalScores();                                            //call to get the scores and draw them
                break;

            case GameStates.Paused:      //game objects will still be draw in these states, but no longer updated
            case GameStates.GameOver:
            case GameStates.Playing:
                BackgroundManager.DrawFirst(spriteBatch); //draw the background clouds
                ItemManager.Draw(spriteBatch);            //draw the items
                PlayerManager.Draw(spriteBatch);          //draw the player
                BackgroundManager.DrawLast(spriteBatch);  //draw the foreground clouds
                DrawFuelTanks();
                DrawScore();
                DrawThrustButtons();
                if (gameState == GameStates.GameOver)                                                                                  //if we are in the game over state
                {
                    textSize = submitScoreFont.MeasureString(PlayerManager.Score.ToString());                                          //figure out the center of the score
                    spriteBatch.Draw(submitScore, new Vector2(215, 60), Color.White);                                                  //draw the game over screen
                    spriteBatch.DrawString(submitScoreFont, PlayerManager.Score.ToString(), textCenter - (textSize / 2), Color.White); //draw the score on the screen
                }
                if (gameState == GameStates.Paused)                                                                                    //if we have paused the game, draw paused text
                {
                    spriteBatch.Draw(pausedScreen, new Vector2(215, 90), Color.White);

                    /*spriteBatch.DrawString(submitScoreFont, "P A U S E D", new Vector2(282, 202), Color.Black);
                     * spriteBatch.DrawString(submitScoreFont, "P A U S E D", new Vector2(280, 200), Color.Gainsboro);
                     * spriteBatch.DrawString(highScoresFont, "Touch the screen to resume play", new Vector2(182, 277), Color.Black);
                     * spriteBatch.DrawString(highScoresFont, "Touch the screen to resume play", new Vector2(180, 275), Color.Gainsboro);
                     * spriteBatch.DrawString(highScoresFont, "Press the Back button to return to title screen", new Vector2(77, 307), Color.Black);
                     * spriteBatch.DrawString(highScoresFont, "Press the Back button to return to title screen", new Vector2(75, 305), Color.Gainsboro);*/
                }
                break;
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #4
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)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (gameState)
            {
            case GameStates.TitleScreen:
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();      //exit the game if the back button is pressed from the titlescreen
                }
                if (isTapped(startGameButton))
                {
                    gameState = GameStates.Playing; //switch to the playing state if the start game button is tapped
                    ResetGame();                    //reset all game values to their starting values
                }
                else if (isTapped(howToButton))
                {
                    gameState = GameStates.HowTo;      //switch to the how to screen if the how to button is tapped
                }
                else if (isTapped(highScoresButton))
                {
                    gameState = GameStates.HighScores;      //switch to the high scores state if the high scores button is tapped
                }
                else if (isTapped(contactInfoButton))
                {
                    gameState = GameStates.ContactInfo;      //switch to the contact info state if the contact info button is tapped
                }
                else if (isTapped(myScoresButton))
                {
                    gameState = GameStates.MyScores;      //switch to the personal scores state if the my scores button is tapped
                }
                else if (isTapped(soundButton))
                {
                    if (SoundManager.PlaySounds)
                    {
                        SoundManager.PlaySounds = false;
                    }
                    else
                    {
                        SoundManager.PlaySounds = true;
                    }
                    ScoresData.soundOn = SoundManager.PlaySounds;
                    personalScoresSaver.SaveMyData(ScoresData, "LocalScores");
                }
                tapLocation = Vector2.Zero;      //reset the tap location before switching states!
                break;

            case GameStates.MyScores:
            case GameStates.ContactInfo:
            case GameStates.HowTo:
            case GameStates.HighScores:
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    gameState = GameStates.TitleScreen;      //go back to the title screen state if back is pressed on the above 4 cases
                }
                break;

            case GameStates.Paused:
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    gameState = GameStates.Playing;      //close the paused menu and go back into the game
                }
                else if (isTapped(noExit))
                {
                    gameState = GameStates.Playing;      //go back to the game
                }
                else if (isTapped(yesExit))
                {
                    gameState = GameStates.TitleScreen;      //go back to the title screen
                }
                tapLocation      = Vector2.Zero;
                bannerAd.Visible = true;
                break;

            case GameStates.GameOver:
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || isTapped(noScore))
                {
                    gameState        = GameStates.TitleScreen; //go back to the title screen if we press back or select not to submit score when the game is over
                    bannerAd.Visible = true;
                    ScoresData.AddScore(PlayerManager.Score);
                    personalScoresSaver.SaveMyData(ScoresData, "LocalScores");
                }
                else if (isTapped(yesScore))
                {
                    ScoresData.AddScore(PlayerManager.Score);
                    personalScoresSaver.SaveMyData(ScoresData, "LocalScores");
                    ShowKeyboard();         //show the keyboard if score is to be submitted
                }
                tapLocation = Vector2.Zero; //reset the tap location before switching states!
                break;

            case GameStates.Playing:
                //Update the player, items, and background while the game is playing
                bannerAd.Visible = false;      //turn off the ads while the game is playing
                PlayerManager.Update(gameTime);
                ItemManager.Update(gameTime);
                BackgroundManager.Update(gameTime);

                if (PlayerManager.PlayerDestroyed)
                {
                    gameState = GameStates.GameOver;      //if the player has fallen too far below the grass, switch to the game over state
                }
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    gameState = GameStates.Paused;      //open the paused menu if the back button is pressed during the game
                }
                break;
            }

            //Update ad banner every 30 secs and only if it's visible
            adDuration += elapsed;
            if (adDuration > 30 && bannerAd.Visible == true)
            {
                bannerAd.RequestNextAd();
                adDuration = 0;
            }

            base.Update(gameTime);
        }