示例#1
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
            bool coveredByOtherScreen)
        {
            //BEGIN NEW XBOX LIVE GamerPicture code etc
            //You just need to get the GamerCard info if you don't have it already
            if (gamer == null && SignedInGamer.SignedInGamers.Count > 0)
            {
                //Get info for the 1st player
                gamer = SignedInGamer.SignedInGamers[0];
                profile = gamer.GetProfile();
                //place to draw the gamer picture (in the middle of the screen)
                GamerPictureRectangle = new Rectangle(
                                30,
                                150,
                                64,
                                64
                              );
                //place to write some info
                gamerTagVector = new Vector2(GamerPictureRectangle.X, 0);
            }
            //END NEW XBOX LIVE GamerPicture code etc
            //Get the current state of the keyboard (what keys are and are not being pressed)
            KeyboardState aKeyboard = Keyboard.GetState();
            if (aKeyboard.IsKeyDown(Keys.P))
            {
                //pause the game
                paused = !paused;

            }

            if (paused)
            {

            }
            else
            {
                CheckForRumble(gameTime);

                // TODO: Add your update logic here
                //The time since Update was called last
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

                //Update the game objects

                //Lets rotate both ways
                //Only Math.PI / 2( one quarter turn)
                const float quarterturn = (float)Math.PI / 2;

                if (rotation < quarterturn)
                {
                    // The grid is currently rotateing
                    // Just Draw
                }
                else
                    if (rotation > Math.PI / 2 && rotation_direction != 0)
                    {//Rotation completed
                        if (rotation_direction > 0) mPlayfield.Rotate_Grid();
                        else mPlayfield.Rotate_Grid_Clockwise();
                        rotation_direction = 0;
                        rotation = 3.14f;
                    }
                    else
                        if (mPlayfield.CheckCollision(mCurrentShape) == true && mCurrentShape.PositionY < 4)
                        {
                        gameover = true;
                        SaveHighScore();
                        }
                        else
                            UpdateGameObjects(elapsed, aKeyboard);

                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                if (IsActive)
                {

                }
            }
        }
示例#2
0
        public PlayerHUD( Player player, SignedInGamer gamer )
        {
            GameplayScreen screen = player.Screen;

              if ( gamer != null )
              {
            profile = gamer.GetProfile();
            Name = gamer.Gamertag;
              }
              else Name = "CPU";

              Player = player;
              Score = 0;
              Boost = 1f;

              Rectangle safeRect = ScreenRects.SafeRegion;

              screenScale = GameCore.Instance.GraphicsDevice.Viewport.Height / 1080f;
              float ss = screenScale;

              // base hud object
              hudCageTexture = screen.Content.Load<Texture2D>( "Textures/playerHUDCage" );
              hudTexture = screen.Content.Load<Texture2D>( "Textures/playerHUD" );
              int hudWidth  = (int)( hudTexture.Width * screenScale );
              int hudHeight = (int)( hudTexture.Height * screenScale );

              int x0 = xPadding + safeRect.X + Player.PlayerNumber * ( safeRect.Width - hudWidth - 2 * xPadding ) / 3;
              int y0 = -(int)( yPadding * screenScale + .5f ) + safeRect.Y + safeRect.Height - hudHeight;

              hudRect = new Rectangle( x0, y0, hudWidth, hudHeight );

              // profile picture
              profileRect = new Rectangle( x0 + (int)( 88 * ss + .5f ),
                                   y0 + (int)( 26 * ss + .5f ),
                                   (int)( 60 * ss + .5f ),
                                   (int)( 60 * ss + .5f ) );

              // boost meter
              boostRect = new Rectangle( x0 + (int)(  90 * ss + .5f ),
                                 y0 + (int)( 111 * ss + .5f ),
                                 (int)( 142 * ss + .5f ),
                                 (int)( 18 * ss + .5f ) );

              boostEffect = screen.Content.Load<Effect>( "Effects/meterEffect" );
              boostEffect.CurrentTechnique = boostEffect.Techniques[0];
              boostEffectParamBoost = boostEffect.Parameters["Boost"];
              boostEffectParamBoosting = boostEffect.Parameters["Boosting"];
              boostEffectParamTime = boostEffect.Parameters["Time"];
              boostTexture = new Texture2D( screen.ScreenManager.GraphicsDevice, boostRect.Width, boostRect.Height );

              // name
              namePos = new Vector2( x0 + 162 * ss, y0 + 12 * ss );
              nameFont = screen.Content.Load<SpriteFont>( "Fonts/HUDNameFont" );
              nameOrigin = nameFont.MeasureString( Name ) / 2;
              float nameLength = nameOrigin.X * 2;
              nameScale = ss * Math.Min( 150f / nameLength, 1f );

              // score
              scorePos = new Vector2( x0 + 230 * ss, y0 + 100 * ss );
              scoreFont = screen.Content.Load<SpriteFont>( "Fonts/HUDScoreFont" );
              scoreSpring = new SpringInterpolater( 1, 700f, .25f * SpringInterpolater.GetCriticalDamping( 700f ) );
              scoreSpring.SetSource( 1f );
              scoreSpring.SetDest( 1f );
              scoreSpring.Active = true;
              scoreString = new StringBuilder( 1 );

              //// score popup
              //scorePopup = new PopupText( ss, scorePos + new Vector2( -25f, -120f ) * screenScale,
              //                            scorePos + new Vector2( -15f, -15f ) * screenScale, 1f );
              // score popup
              //float yMax = GameCore.Instance.DisplayGamertags ? -50f : -10f;
              //float yMin = GameCore.Instance.DisplayGamertags ? 0f : 40f;
              float yMax = -50f;
              float yMin = 0f;
              scorePopup = new PopupText( ss, new Vector2( 0f, yMax ) * screenScale,
                                  new Vector2( 0, yMin ) * screenScale, 1f );

              // place
              placePos = new Vector2( x0 + 36 * ss, y0 + 91 * ss );
              placeFont = screen.Content.Load<SpriteFont>( "Fonts/HUDPlaceFont" );
              placeSmallFont = screen.Content.Load<SpriteFont>( "Fonts/HUDPlaceTagFont" );
              placeNumber = new StringBuilder( "0" );
              placeSpring = new SpringInterpolater( 1, 700f, .25f * SpringInterpolater.GetCriticalDamping( 700f ) );
              placeSpring.SetSource( 1f );
              placeSpring.SetDest( 1f );
              placeSpring.Active = true;
              Place = 1;
        }
示例#3
0
文件: User.cs 项目: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Checks for user details if not done so already. If no user is signed in 
        /// (always the case on windows) then the user will be asked for his/her name.
        /// </summary>
        //=========================================================================================
        public static void CheckUserDetails()
        {
            // See if we queried for a user profile:

            if ( s_queried_user_profile == false )
            {
                // Ok: look for a user profile

                try
                {
                    // Do the query:

                    if ( Gamer.SignedInGamers.Count > 0 && Gamer.SignedInGamers[PlayerIndex.One] != null )
                    {
                        // Try and get the signed in player for player one:

                        SignedInGamer signed_in_player = Gamer.SignedInGamers[PlayerIndex.One];

                        // See if there:

                        if ( signed_in_player != null )
                        {
                            // Grab the user profile:

                            s_user_profile = signed_in_player.GetProfile();

                            // Try and get the user name:

                            s_user_name = signed_in_player.Gamertag;

                            // Make sure no leading or trailing white space:

                            s_user_name = s_user_name.Trim();

                            // If no user name given then use a dash:

                            if ( s_user_name == null || s_user_name.Length <= 0 ) s_user_name = "-";

                            // Make sure it is within the max size:

                            if ( s_user_name.Length >= MAX_USER_NAME_LENGTH )
                            {
                                s_user_name = s_user_name.Substring(0,MAX_USER_NAME_LENGTH);
                            }
                        }
                    }
                }

                // Show exceptions on windows debug

                #if WINDOWS_DEBUG

                    catch ( Exception e ){ DebugConsole.PrintException(e); }

                #else

                    catch ( Exception ){}

                #endif

                // Now queried for a user profile:

                s_queried_user_profile = true;
            }
            else if ( s_user_profile == null && s_asked_for_user_name == false )
            {
                // If we haven't got a profile then try and ask the user for his/her name:

                if ( Guide.IsVisible == false )
                {
                    // This might fail:

                    try
                    {
                        // Only do if guide is not showing already

                        Guide.BeginShowKeyboardInput
                        (
                            PlayerIndex.One                                             ,
                            StringDatabase.GetString("user_enter_name_title")           ,
                            StringDatabase.GetString("user_enter_name_description")     ,
                            ""                                                          ,
                            new AsyncCallback(OnNameEntered)                            ,
                            null
                        );
                    }

                    // Show exceptions on windows debug

                    #if WINDOWS_DEBUG

                        catch ( Exception e ){ DebugConsole.PrintException(e); }

                    #else

                        catch ( Exception ){}

                    #endif

                    // Asked the user for his/her name

                    s_asked_for_user_name = true;
                }
            }
        }
示例#4
0
 // once we have the gamer's profile, set the local profile.
 public static void endGetProfile(IAsyncResult result)
 {
     gamerProfile = (result.AsyncState as Gamer).EndGetProfile(result);
 }
示例#5
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
            bool coveredByOtherScreen)
        {
            //BEGIN NEW CODE
            //You just need to get the GamerCard info if you don't have it already
            if (gamer == null && SignedInGamer.SignedInGamers.Count > 0)
            {
                //Get info for the 1st player
                gamer = SignedInGamer.SignedInGamers[0];
                profile = gamer.GetProfile();
                //place to draw the gamer picture (in the middle of the screen)
                GamerPictureRectangle = new Rectangle(
                                30,
                                150,
                                64,
                                64
                              );
                //place to write some info
                gamerTagVector = new Vector2(GamerPictureRectangle.X, 0);
            }
            //END NEW CODE

            Players[1].Update(gameTime);
            Players[0].Update(gameTime);
            Players[2].Update(gameTime);
            Players[3].Update(gameTime);

            //=======OLD CODE HERE===============
               // CheckForRumble(gameTime);

            // TODO: Add your update logic here
            //The time since Update was called last
             elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

              //  //Get the current state of the keyboard (what keys are and are not being pressed)
              //  KeyboardState aKeyboard = Keyboard.GetState();

            /*
                    if (mPlayfield.CheckCollision(mCurrentShape) == true && mCurrentShape.PositionY < 4)
                    {//gameover}}
                        gameover = true;
                    }
                    else
                        UpdateGameObjects(elapsed);
            */
            //==========OLD CODE END HERE===================

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
示例#6
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
            bool coveredByOtherScreen)
        {
            //BEGIN NEW XBOX LIVE GamerPicture code etc
            //You just need to get the GamerCard info if you don't have it already
            if (gamer == null && SignedInGamer.SignedInGamers.Count > 0)
            {
                //Get info for the 1st player
                gamer = SignedInGamer.SignedInGamers[0];
                profile = gamer.GetProfile();
                //place to draw the gamer picture (in the middle of the screen)
                GamerPictureRectangle = new Rectangle(
                                30,
                                150,
                                64,
                                64
                              );
                //place to write some info
                gamerTagVector = new Vector2(GamerPictureRectangle.X, 0);
            }
            //END NEW XBOX LIVE GamerPicture code etc

            CheckForRumble(gameTime);

            // TODO: Add your update logic here
            //The time since Update was called last
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Get the current state of the keyboard (what keys are and are not being pressed)
            KeyboardState aKeyboard = Keyboard.GetState();

            //Update the game objects
            if (rotation < Math.PI / 2)
            {
                //rotateing
            }
            else
                if (rotation > Math.PI / 2 && rotation != 3.14f)
                {
                    mPlayfield.Rotate_Grid();
                    rotation = 3.14f;
                }
                else
                    if (mPlayfield.CheckCollision(mCurrentShape) == true && mCurrentShape.PositionY < 4)
                    {gameover = true;}
                    else
                        UpdateGameObjects(elapsed, aKeyboard);

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (IsActive)
            {
                // Apply some random jitter to make the enemy move around.
                const float randomization = 10;

                enemyPosition.X += (float)(random.NextDouble() - 0.5) * randomization;
                enemyPosition.Y += (float)(random.NextDouble() - 0.5) * randomization;

                // Apply a stabilizing force to stop the enemy moving off the screen.
                Vector2 targetPosition = new Vector2(200, 200);

                enemyPosition = Vector2.Lerp(enemyPosition, targetPosition, 0.05f);

                // TODO: this game isn't very fun! You could probably improve
                // it by inserting something more interesting in this space :-)
            }
        }