예제 #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)
        {
            if (!(preloadedAssets && preloadedJSon))
            {
                GraphicsDevice.Clear(Color.Black);

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

                for (int i = 0; i < starCount; i++)
                {
                    if (stars[i].X - shipPosition.X < -425 || stars[i].X - shipPosition.X > 425 || stars[i].Y - shipPosition.Y < -150 || stars[i].Y - shipPosition.Y > 150)
                    {
                        continue;
                    }

                    spriteBatch.Draw(asteroidsSpriteSheet, new Rectangle((GlobalGameConstants.GameResolutionWidth / 2 - 425) + 425 + (int)(stars[i].X - shipPosition.X), (GlobalGameConstants.GameResolutionHeight / 3 - 100) + 150 + (int)(stars[i].Y - shipPosition.Y), 20, 16), new Rectangle(555, 172, 30, 28), Color.White, starRotation[i], new Vector2(15, 14), SpriteEffects.None, 0.0f);
                }

                spriteBatch.Draw(asteroidsSpriteSheet, new Rectangle((GlobalGameConstants.GameResolutionWidth / 2 - 425) + 425, (GlobalGameConstants.GameResolutionHeight / 3 - 100) + 150, 30, 30), new Rectangle(0, 172, 120, 120), Color.White, shipRotation + (float)(Math.PI / 2), new Vector2(60), SpriteEffects.None, 0.0f);
                drawBox(spriteBatch, new Rectangle(GlobalGameConstants.GameResolutionWidth / 2 - 425, GlobalGameConstants.GameResolutionHeight / 3 - 100, 850, 300), Color.White, 2.0f);

                spriteBatch.Draw(pleaseWaitDialog, (new Vector2(GlobalGameConstants.GameResolutionWidth / 2, GlobalGameConstants.GameResolutionHeight * 0.75f) - new Vector2(pleaseWaitDialog.Width / 2, pleaseWaitDialog.Height / 2)), Color.White);

                spriteBatch.End();

                return;
            }

            currentGameScreen.render(spriteBatch);

            if (SaveGameModule.TouchingStorageDevice)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(saveIcon, new Rectangle(1100, 588, 54, 59), new Rectangle(3, 28, 54, 59), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.5f);
                spriteBatch.End();
            }

#if CONTROLLER_DATA
            spriteBatch.Begin();

            try
            {
                spriteBatch.DrawString(Game1.tenbyFive14, "Player1: " + InputDevice2.GetPlayerGamePadIndex(InputDevice2.PPG_Player.Player_1).ToString(), new Vector2(32), Color.White);
            }
            catch (Exception)
            {
                spriteBatch.DrawString(Game1.tenbyFive14, "Player1: none", new Vector2(32), Color.White);
            }

            try
            {
                spriteBatch.DrawString(Game1.tenbyFive14, "Player2: " + InputDevice2.GetPlayerGamePadIndex(InputDevice2.PPG_Player.Player_2).ToString(), new Vector2(32, 64), Color.White);
            }
            catch (Exception)
            {
                spriteBatch.DrawString(Game1.tenbyFive14, "Player2: none", new Vector2(32, 64), Color.White);
            }

            spriteBatch.End();
#endif

#if PROFILE
            frameCounter++;

            string fps = string.Format("fps: {0}", frameRate);

            spriteBatch.Begin();

            spriteBatch.DrawString(font, fps, new Vector2(33, 33), Color.Black);
            spriteBatch.DrawString(font, fps, new Vector2(32, 32), Color.White);

            spriteBatch.End();
#endif
        }
예제 #2
0
        /// <summary>
        /// Creates a new high scores screen state.
        /// </summary>
        /// <param name="inGame">If the player has died or completed the game, set this to true. If simply checking the scores from the menu, set this to false</param>
        public HighScoresState(bool inGame, bool gameComplete)
        {
            InitalizeHighScores();

            HighScoreValue newScore = new HighScoreValue(GameCampaign.PlayerName, GameCampaign.Player_Coin_Amount, GameCampaign.ElapsedCampaignTime, GameCampaign.PlayerLevelProgress, GameCampaign.PlayerFloorHeight);

            this.inGame       = inGame;
            this.gameComplete = gameComplete;

            try
            {
                SignedInGamer gamer = Gamer.SignedInGamers[InputDevice2.GetPlayerGamePadIndex(InputDevice2.PPG_Player.Player_1)];
                isSignedIn = (gamer != null);
            }
            catch (Exception)
            {
                isSignedIn = false;
            }

            if (inGame)
            {
                highScores.Add(newScore);

                // if there are 11 high scores now, remove the lowest score
                if (highScores.Count > 10)
                {
                    HighScoreValue    lowestScore = highScores[0];
                    CompareHighScores comparer    = new CompareHighScores();

                    for (int i = 1; i < highScores.Count; i++)
                    {
                        if (comparer.Compare(highScores[i], lowestScore) < 0)
                        {
                            lowestScore = highScores[i];
                        }
                    }

                    highScores.Remove(lowestScore);
                }

                highScores.Sort(new CompareHighScores());
                highScores.Reverse();

                for (int i = 0; i < highScores.Count; i++)
                {
                    if (highScores[i].playerName == newScore.playerName && highScores[i].secondsElapsed == newScore.secondsElapsed && highScores[i].floorDiedOn == newScore.floorDiedOn)
                    {
                        newlyAddedScoreIndex = i;
                    }
                }

                SaveGameModule.saveGame();
            }
            else
            {
                highScores.Sort(new CompareHighScores());
                highScores.Reverse();
            }

            stateTimer = 0;

            if (isSignedIn)
            {
                SaveGameModule.loadGame();
            }
        }