Ejemplo n.º 1
0
        public void ProcessGamePad(ScreenPad screenPad, PhysicalObject gameMap)
        {
            //var candidatePos = this.Position;
            //var candidateXPos = this.Position;
            //var candidateYPos = this.Position;

            //if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            //{
            //    screenPad.LeftStick.Normalize();
            //    candidatePos = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * .5f;
            //    candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * .5f;
            //    candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * .5f;
            //}

            //var collisionResult = gameMap.TestCollision(this, candidatePos);
            //var collisionXResult = gameMap.TestCollision(this, candidateXPos);
            //var collisionYResult = gameMap.TestCollision(this, candidateYPos);
            //if (collisionResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidatePos;
            //}
            //else if (collisionXResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateXPos;
            //}
            //else if (collisionYResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateYPos;
            //}
        }
Ejemplo n.º 2
0
        public void ProcessGamePad(ScreenPad screenPad, PhysicalObject gameMap, float scrollRows)
        {
            var candidatePos  = this.Position;
            var candidateXPos = this.Position;
            var candidateYPos = this.Position;

            if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            {
                screenPad.LeftStick.Normalize();
                candidatePos  = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * .25f;
                candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * .25f;
                candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * .25f;
            }

            var collisionResult  = gameMap.TestCollision(this, candidatePos, scrollRows);
            var collisionXResult = gameMap.TestCollision(this, candidateXPos, scrollRows);
            var collisionYResult = gameMap.TestCollision(this, candidateYPos, scrollRows);

            if (collisionResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePos;
            }
            else if (collisionXResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateXPos;
            }
            else if (collisionYResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateYPos;
            }
        }
Ejemplo n.º 3
0
        public virtual CollisionResult TestCollision(PhysicalObject that, Vector2 thatNewPosition, float scrollRows)
        {
            var collisionResult = new CollisionResult();

            var thisScreenRectangle =
                new Rectangle((int)Position.X
                              , (int)Position.Y
                              , (int)this.Size.X
                              , (int)this.Size.Y);

            var thatScreenRectangle =
                new Rectangle((int)thatNewPosition.X
                              , (int)(thatNewPosition.Y)
                              , (int)that.Size.X
                              , (int)that.Size.Y);

            Rectangle intersectArea = Rectangle.Intersect(thisScreenRectangle, thatScreenRectangle);

            if (intersectArea.X * intersectArea.Y != 0)
            {
                collisionResult.CollisionType = CollisionType.Blocked;
            }

            return(collisionResult);
        }
Ejemplo n.º 4
0
        public override CollisionResult TestCollision(PhysicalObject that, Vector2 thatNewPosition, float scrollRows)
        {
            var collisionResult = new CollisionResult();

            if (thatNewPosition.X < 0 ||
                thatNewPosition.X + that.Size.X > windowTilesSize.X ||
                thatNewPosition.Y < 0 ||
                thatNewPosition.Y + that.Size.Y > windowTilesSize.Y)
            {
                collisionResult.CollisionType = CollisionType.OffRoad;
                var x = Math.Min(thatNewPosition.X, windowTilesSize.X - that.Size.X);
                x = Math.Max(x, 0);
                var y = Math.Min(thatNewPosition.Y, windowTilesSize.Y - that.Size.Y);
                y = Math.Max(y, 0);
            }
            else
            {
                for (var deltaX = 0; deltaX < that.Size.X; deltaX++)
                {
                    for (var deltaY = 0; deltaY < that.Size.Y; deltaY++)
                    {
                        var x = (int)((thatNewPosition.X) / that.Size.X + deltaX);
                        var y = (int)((scrollRows / 2 + thatNewPosition.Y / that.Size.Y) + deltaY);

                        if ((x < 0 ||
                             x >= (windowTilesSize.X / 2)) ||
                            y < 0 ||
                            y >= (mapLines.Count() * 2))
                        {
                            collisionResult.CollisionType = CollisionType.OffRoad;
                            break;
                        }
                        else
                        {
                            var mapChar = mapLines[y][x];

                            if ("XD".Contains(mapChar))
                            {
                                collisionResult.CollisionType = CollisionType.Blocked;
                                break;
                            }
                        }
                    }
                }

                //var colorArray = new Color[(int)(that.Size.X * that.Size.Y)];
                //var extractRegion = new Rectangle(
                //    (int)Math.Round(thatNewPosition.X),
                //    (int)Math.Round(scrollRows + thatNewPosition.Y),
                //    (int)that.Size.X,
                //    (int)that.Size.Y);
                //path01.GetData<Color>(0, extractRegion, colorArray, 0, (int)(that.Size.X * that.Size.Y));
                //foreach (var color in colorArray)
                //{
                //    if (color != Color.White)
                //    {
                //        collisionResult.CollisionType = CollisionType.Blocked;
                //        break;
                //    }
                //}
            }

            return(collisionResult);
        }
Ejemplo n.º 5
0
 public override CollisionResult TestCollision(PhysicalObject that, Vector2 thatNewPosition, float scrollRows)
 {
     return(base.TestCollision(that, thatNewPosition, scrollRows));
 }