当前位置: 首页>>代码示例>>C#>>正文


C# Edge.isVertical方法代码示例

本文整理汇总了C#中System.Edge.isVertical方法的典型用法代码示例。如果您正苦于以下问题:C# Edge.isVertical方法的具体用法?C# Edge.isVertical怎么用?C# Edge.isVertical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Edge的用法示例。


在下文中一共展示了Edge.isVertical方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testTileCollision

		/// <summary>
		/// Tests the tile for a collision. Returns via out the position in world space where the collision occured.
		/// </summary>
		/// <returns>The tile collision.</returns>
		/// <param name="tile">Tile.</param>
		/// <param name="edgeToTest">the opposite side of movement, the side the leading edge will collide with</param>
		/// <param name="perpindicularPosition">Perpindicular position.</param>
		/// <param name="leadingPosition">Leading position.</param>
		/// <param name="shouldTestSlopes">Should test slopes.</param>
		/// <param name="collisionResponse">Collision response.</param>
		bool testTileCollision( TiledTile tile, Edge edgeToTest, int perpindicularPosition, int leadingPosition, bool shouldTestSlopes, out int collisionResponse )
		{
			collisionResponse = leadingPosition;

			// one way platforms are only collideable from the top when the player is already above them
			if( tile.isOneWayPlatform() )
			{
				// only the top edge of one way platforms are checked for collisions
				if( edgeToTest != Edge.Top )
					return false;

				// our response should be the top of the platform
				collisionResponse = tiledMap.tileToWorldPositionX( tile.y );
				return _boxColliderBounds.Bottom <= collisionResponse;
			}

			var forceSlopedTileCheckAsWall = false;

			// when moving horizontally the only time a slope is considered for collision testing is when its closest side is the tallest side
			// and we were not intesecting the tile before moving.
			// this prevents clipping through a tile when hitting its edge: -> |\
			if( edgeToTest.isHorizontal() && tile.isSlope() && tile.getNearestEdge( leadingPosition ) == tile.getHighestSlopeEdge() )
			{
				var moveDir = edgeToTest.oppositeEdge();
				var leadingPositionPreMovement = _boxColliderBounds.getSide( moveDir );

				// we need the tile x position that is on the opposite side of our move direction. Moving right we want the left edge
				var tileX = moveDir == Edge.Right ? tiledMap.tileToWorldPositionX( tile.x ) : tiledMap.tileToWorldPositionX( tile.x + 1 );

				// using the edge before movement, we see if we were colliding before moving.
				var wasCollidingBeforeMove = moveDir == Edge.Right ? leadingPositionPreMovement > tileX : leadingPositionPreMovement < tileX;

				// if we were not colliding before moving we need to consider this tile for a collision check as if it were a wall tile
				forceSlopedTileCheckAsWall = !wasCollidingBeforeMove;
			}


			if( forceSlopedTileCheckAsWall || !tile.isSlope() )
			{				
				switch( edgeToTest )
				{
					case Edge.Top:
						collisionResponse = tiledMap.tileToWorldPositionY( tile.y );
						break;
					case Edge.Bottom:
						collisionResponse = tiledMap.tileToWorldPositionY( tile.y + 1 );
						break;
					case Edge.Left:
						collisionResponse = tiledMap.tileToWorldPositionX( tile.x );
						break;
					case Edge.Right:
						collisionResponse = tiledMap.tileToWorldPositionX( tile.x + 1 );
						break;
				}

				return true;
			}

			if( shouldTestSlopes )
			{
				var tileWorldX = tiledMap.tileToWorldPositionX( tile.x );
				var tileWorldY = tiledMap.tileToWorldPositionX( tile.y );
				var slope = tile.getSlope();
				var offset = tile.getSlopeOffset();

				// calculate the point on the slope at perpindicularPosition
				collisionResponse = (int)( edgeToTest.isVertical() ? slope * ( perpindicularPosition - tileWorldX ) + offset + tileWorldY : ( perpindicularPosition - tileWorldY - offset ) / slope + tileWorldX );
				var isColliding = edgeToTest.isMax() ? leadingPosition <= collisionResponse : leadingPosition >= collisionResponse;

				// this code ensures that we dont consider collisions on a slope while jumping up that dont intersect our collider.
				// It also makes sure when testing the bottom edge that the leadingPosition is actually above the collisionResponse.
				// HACK: It isn't totally perfect but it does the job
				if( isColliding && edgeToTest == Edge.Bottom && leadingPosition <= collisionResponse )
					isColliding = false;
				
				return isColliding;
			}

			return false;
		}
开发者ID:prime31,项目名称:Nez,代码行数:90,代码来源:TiledMapMover.cs

示例2: collisionRectForSide

		/// <summary>
		/// gets a collision rect for the given side expanded to take into account motion
		/// </summary>
		/// <returns>The rect for side.</returns>
		/// <param name="side">Side.</param>
		/// <param name="motion">Motion.</param>
		Rectangle collisionRectForSide( Edge side, int motion )
		{
			Rectangle bounds;

			// for horizontal collision checks we use just a sliver for our bounds. Vertical gets the half rect so that it can properly push
			// up when intersecting a slope which is ignored when moving horizontally.
			if( side.isHorizontal() )
				bounds = _boxColliderBounds.getRectEdgePortion( side );
			else
				bounds = _boxColliderBounds.getHalfRect( side );

			// we contract horizontally for vertical movement and vertically for horizontal movement
			if( side.isVertical() )
				RectangleExt.contract( ref bounds, colliderHorizontalInset, 0 );
			else
				RectangleExt.contract( ref bounds, 0, colliderVerticalInset );

			// finally expand the side in the direction of movement
			RectangleExt.expandSide( ref bounds, side, motion );

			return bounds;
		}
开发者ID:prime31,项目名称:Nez,代码行数:28,代码来源:TiledMapMover.cs

示例3: collisionRectForSide

        /// <summary>
        /// gets a collision rect for the given side expanded to take into account motion
        /// </summary>
        /// <returns>The rect for side.</returns>
        /// <param name="side">Side.</param>
        /// <param name="motion">Motion.</param>
        Rectangle collisionRectForSide( Edge side, int motion )
        {
            var bounds = (Rectangle)_collider.bounds;
            bounds = bounds.getHalfRect( side );

            // we contract horizontally for vertical movement and vertically for horizontal movement
            if( side.isVertical() )
                RectangleExt.contract( ref bounds, colliderHorizontalInset, 0 );
            else
                RectangleExt.contract( ref bounds, 0, colliderVerticalInset );

            // finally expand the side in the direction of movement
            RectangleExt.expandSide( ref bounds, side, motion );

            return bounds;
        }
开发者ID:RastaCow,项目名称:Nez,代码行数:22,代码来源:TiledMapMover.cs


注:本文中的System.Edge.isVertical方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。