public TouchScreenInput(CCLayer Owner,PhysicsEntity controledEntity)
        {
            this.owner = Owner;
            mControledEntity = controledEntity;

            touchListener = new CCEventListenerTouchAllAtOnce ();
            touchListener.OnTouchesMoved = HandleTouchesMoved;
            touchListener.OnTouchesEnded = OnTouchesEnded;
            owner.AddEventListener (touchListener);
        }
예제 #2
0
        public void PerformCollisionAgainst(PhysicsEntity entity, out CCTileMapCoordinates tileAtXy, out bool didCollisionOccur)
        {
            didCollisionOccur = false;
            tileAtXy = CCTileMapCoordinates.Zero;

            int leftIndex;
            int rightIndex;

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

            var boundingBoxWorld = entity.BoundingBoxTransformedToWorld;

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

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

                        didCollisionOccur = true;

                        tileAtXy = collisions [i].tiledMapCoordinate;
                    }
                }

            }
        }
예제 #3
0
 public bool Intersects(PhysicsEntity other)
 {
     return this.sprite.BoundingBoxTransformedToWorld.IntersectsRect (other.sprite.BoundingBoxTransformedToWorld);
 }