當前位置: 首頁>>代碼示例>>C#>>正文


C# Character.fall方法代碼示例

本文整理匯總了C#中Character.fall方法的典型用法代碼示例。如果您正苦於以下問題:C# Character.fall方法的具體用法?C# Character.fall怎麽用?C# Character.fall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Character的用法示例。


在下文中一共展示了Character.fall方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: checkTileCollision

        /// <summary>
        /// Will check if the given character has collided with a tile
        /// in the level and then handle the position correction.
        /// ENSURE:   the given character will not be colliding with any tiles.
        /// </summary>
        private void checkTileCollision(Character.Character character)
        {
            //for every tile in the level
              foreach (Tile tile in this.level_tiles)
              {
            //save the character's bounding box
            Rectangle character_bounds = character.BoundingBox();

            //now get the character's current velocity
            Vector2 character_velocity = character.currentSpeed();
            //compute the future position of the character
            Rectangle future_bounds = new Rectangle(
              character_bounds.X + (int)character_velocity.X,
              character_bounds.Y + (int)character_velocity.Y,
              character_bounds.Width, character_bounds.Height);

            //check if the character WILL collide with this tile
            if (tile.collidesWith(future_bounds)){
              //find how much overlap is occuring
              Rectangle intersection = Rectangle.Intersect(tile.destinationRectangle, future_bounds);

              //alter the characters velocity to take the collision into account
              Vector2 offset = new Vector2();
              //if the character has horizontal velocity
              //and isn't jumping or falling
              if ((character.isJumping() == false && character.isFalling() == false)
            && character_velocity.X != 0)
              {
            //compute the horizontal offset
            offset.X = (character_velocity.X > 0) ?
              (intersection.X - intersection.Right) : //negative offset if positive velocity
              (intersection.Right - intersection.X); //positive offset if negative velocity

            //add the offset to the velocity value
            //character_velocity.X = character_velocity.X + offset.X;
              }
              //if the character has vertical velocity
              if (character_velocity.Y != 0)
              {
            //they are jumping or falling into this object

            //first fix their vertical forces
            //if the character has a positive vertical velocity
            if (character_velocity.Y > 0)
            {
              //then the offset needs to be negative
              offset.Y = (intersection.Y - intersection.Bottom) -1;
              //this also means the character has hit ground
              //character.ground();
            }
            //otherwise, the velocity is negative
            else
            {
              //so the offset needs to be positive
              offset.Y = (intersection.Bottom - intersection.Y);
              //the character hit the bottom of something, fall
              character.fall();
            }

            //now they might have horizontal forces,
            //before we fix them, see if the character is no longer colliding
            //compute the future position of the character
            Rectangle new_future_bounds = new Rectangle(
              future_bounds.X + (int)offset.X,
              future_bounds.Y + (int)offset.Y,
              future_bounds.Width, future_bounds.Height);
            if (tile.collidesWith(new_future_bounds))
            {
              //then fix the horizontal forces
              Rectangle new_intersection = Rectangle.Intersect(tile.destinationRectangle, new_future_bounds);

              //compute the horizontal offset
              offset.X = (character_velocity.X > 0) ?
                (intersection.X - intersection.Right) : //negative offset if positive velocity
                (intersection.Right - intersection.X); //positive offset if negative velocity
            }
              }
              character_velocity.X = character_velocity.X + offset.X;
              character_velocity.Y = character_velocity.Y + offset.Y;
              //give the player it's new position
              character.setVelocity(character_velocity);
            }
              }
        }
開發者ID:kWhittington,項目名稱:CSCI3097_HW3,代碼行數:89,代碼來源:Level.cs

示例2: updateEnemy

        /// <summary>
        /// Will update the given enemy character.
        /// </summary>
        private void updateEnemy(Character.Enemy enemy)
        {
            //if the character is jumping right
              if (enemy.isJumpingRight())
              {
            enemy.setRightMove();
              }
              //or if the character is jumping left
              else if (enemy.isJumpingLeft())
              {
            enemy.setLeftMove();
              }
              //if the player is jumping
              if (enemy.isJumping() == true)
              {
            //if the player has reached the max jumping height
            if (enemy.jumpHeightReached())
            {
              //then begin their decent
              enemy.fall();
            }
            //otherwise, the player is still jumping
            else
            {
              enemy.jump();
            }
              }
              //or if the player is falling
              else if (enemy.isFalling() == true)
              {
            //make them fall
            enemy.fall();
              }

              //for character alive right now
              foreach (Character.Character character in this.aliveCharacters())
              {
            //if they are within view distance of this enemy
            if (character.Equals(enemy) == false && enemy.canSee(character) == true)
            {
              //then update this enemy accordingly
              enemy.react(character);
            }
              }
              enemy.Personality().update();
        }
開發者ID:kWhittington,項目名稱:CSCI3097_HW3,代碼行數:49,代碼來源:CharacterManager.cs

示例3: checkForSolidGround

 /// <summary>
 /// Will check if the given character is standing on solid ground.
 /// If not, they will fall.
 /// </summary>
 private void checkForSolidGround(Character.Character character)
 {
     //this only matters if the character is grounded
       if (character.isJumping() == false)
       {
     //for every tile in the level
     foreach (Tile tile in this.level_tiles)
     {
       //if they will collide with character and is below the character
       //and is not solid
       if (tile.isUnder(character))
       {
     //if the tile is not solid
     if (tile.collisionType.Equals(TileCollision.NO_COLLISION))
     {
       //make the character fall
       character.fall();
     }
     //otherwise, ground the character
     else
     {
       character.ground();
     }
       }
     }
       }
 }
開發者ID:kWhittington,項目名稱:CSCI3097_HW3,代碼行數:31,代碼來源:Level.cs

示例4: updateCharacter

 /// <summary>
 /// Will update the given character.
 /// </summary>
 private void updateCharacter(Character.Character character)
 {
     //if the player is jumping
       if (character.isJumping() == true)
       {
     //if the player has reached the max jumping height
     if (character.jumpHeightReached())
     {
       //then begin their decent
       character.fall();
     }
     //otherwise, the player is still jumping
     else
     {
       character.jump();
     }
       }
       //or if the player is falling
       else if (character.isFalling() == true)
       {
     //make them fall
     character.fall();
       }
 }
開發者ID:kWhittington,項目名稱:CSCI3097_HW3,代碼行數:27,代碼來源:CharacterManager.cs


注:本文中的Character.fall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。