本文整理汇总了C#中Character.isJumping方法的典型用法代码示例。如果您正苦于以下问题:C# Character.isJumping方法的具体用法?C# Character.isJumping怎么用?C# Character.isJumping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character
的用法示例。
在下文中一共展示了Character.isJumping方法的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);
}
}
}
示例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();
}
示例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();
}
}
}
}
}
示例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();
}
}