Exemple #1
0
        public bool PerformCollisionAgainst(AnimatedSpriteEntity entity)
        {
            bool didCollisionOccur = false;

            int leftIndex;
            int rightIndex;

            GetIndicesBetween(
                entity.BoundingBoxWorld.LowerLeft.X, entity.BoundingBoxWorld.UpperRight.X, out leftIndex, out rightIndex);

            var boundingBoxWorld = entity.BoundingBoxWorld;

            for (int i = leftIndex; i < rightIndex; i++)
            {
                var separatingVector = GetSeparatingVector(boundingBoxWorld, collisions [i]);

                if (separatingVector != CCVector2.Zero)
                {
                    entity.PositionX += separatingVector.X;
                    entity.PositionY += separatingVector.Y;
                    // refresh boundingBoxWorld:
                    boundingBoxWorld = entity.BoundingBoxWorld;

                    didCollisionOccur = true;
                }
            }

            return(didCollisionOccur);
        }
        public bool PerformCollisionAgainst(AnimatedSpriteEntity entity)
        {
            bool didCollisionOccur = false;

            int leftIndex;
            int rightIndex;

            //entity是player/enemy
            //boundiongBox是包裹entity的最小的矩形
            //lowerLeft是左下角,UpperRight是右上角
            //得到的leftIndex和rightIndex应该是和entity有接触的瓦片地图的实体瓦片的list
            //例如,如果entity在地面上,则这个list里面应该只有和entity接触的地面瓦片
            //然后进一步判断这个地面瓦片对于entity的作用(地面就是支持entity)
            GetIndicesBetween (entity.BoundingBoxWorld.LowerLeft.X, entity.BoundingBoxWorld.UpperRight.X, out leftIndex, out rightIndex);

            var boundingBoxWorld = entity.BoundingBoxWorld;

            //遍历所有和entity有接触的瓦片,来判断这些瓦片对于entity的物理作用
            for (int i = leftIndex; i < rightIndex; i++)
            {
                //计算得到这个瓦片和entity接触后对entity的作用力产生的运动vector
                var separatingVector = GetSeparatingVector (boundingBoxWorld, collisions [i]);

                //如果player和瓦片地图中的不可进入的瓦片相碰
                if (separatingVector != CCVector2.Zero)
                {
                    //更新entity的位置
                    entity.PositionX += separatingVector.X;
                    entity.PositionY += separatingVector.Y;
                    // refresh boundingBoxWorld:
                    boundingBoxWorld = entity.BoundingBoxWorld;

                    didCollisionOccur = true;
                }
            }

            //相碰
            return didCollisionOccur;
        }
		public bool PerformCollisionAgainst(AnimatedSpriteEntity entity)
		{
			bool didCollisionOccur = false;

			int leftIndex;
			int rightIndex;

			GetIndicesBetween (
				entity.BoundingBoxWorld.LowerLeft.X, entity.BoundingBoxWorld.UpperRight.X, out leftIndex, out rightIndex);

			var boundingBoxWorld = entity.BoundingBoxWorld;

			for (int i = leftIndex; i < rightIndex; i++)
			{
				var separatingVector = GetSeparatingVector (boundingBoxWorld, collisions [i]);

				if (separatingVector != CCVector2.Zero)
				{
					entity.PositionX += separatingVector.X;
					entity.PositionY += separatingVector.Y;
					// refresh boundingBoxWorld:
					boundingBoxWorld = entity.BoundingBoxWorld;

					didCollisionOccur = true;
				}
			}

			return didCollisionOccur;
		}
 public bool Intersects(AnimatedSpriteEntity other)
 {
     //返回是否两个entity的rect有重叠
     return this.sprite.BoundingBoxTransformedToWorld.IntersectsRect (other.sprite.BoundingBoxTransformedToWorld);
 }
Exemple #5
0
 public bool Intersects(AnimatedSpriteEntity other)
 {
     return(this.sprite.BoundingBoxTransformedToWorld.IntersectsRect(other.sprite.BoundingBoxTransformedToWorld));
 }