Ejemplo n.º 1
0
 public void OnTouch(Physics.Response response)
 {
     if (response.Contact.Normal.Y < 0)
     {
         this.Velocity *= Vector2.UnitX;
         this.onGround  = true;
         this.Animation = Math.Abs(this.Velocity.X) > Physics.Epsilon ? Atlas.Player.Run : Atlas.Player.Idle;
     }
 }
Ejemplo n.º 2
0
        public RectangleF Move(RectangleF origin, RectangleF destination, Action <Physics.Response> onTouch)
        {
            //destination.X = MathHelper.Clamp(destination.X, 0, this.Width - 1 * Atlas.GridSize - destination.Width);
            //destination.Y = MathHelper.Clamp(destination.Y, 0, this.Height * Atlas.GridSize - destination.Height);

            Physics.Response nearest = null;

            for (int x = 0; x < this.Width; x++)
            {
                for (int y = 0; y < this.Height; y++)
                {
                    var tile = tiles[x, y];
                    if (tile != null)
                    {
                        var tileBox  = new RectangleF(x * Atlas.GridSize, y * Atlas.GridSize, Atlas.GridSize, Atlas.GridSize);
                        var movement = Physics.Slide(origin, destination, tileBox);

                        if (movement.Contact.HasTouched && (nearest == null || nearest.Contact.Amount > movement.Contact.Amount))
                        {
                            nearest = movement;
                        }
                    }
                }
            }

            if (nearest != null)
            {
                onTouch(nearest);
                return(Move(origin, nearest.Destination, onTouch));
            }

            return(destination);

            /*
             *
             *
             * var sx = Math.Min(origin.Left, destination.Left) / Atlas.GridSize;
             * var sy = Math.Min(origin.Top, destination.Top) / Atlas.GridSize;
             * var ex = 1 + Math.Max(origin.Left, destination.Left) / Atlas.GridSize;
             * var ey = 1 + Math.Max(origin.Top, destination.Top) / Atlas.GridSize;
             * for (int x = sx; x < ex; x++)
             * {
             *      for (int y = sy; y < ey; y++)
             *      {
             *              var tile = tiles[x, y];
             *              if (tile != null)
             *              {
             *                      var tileBox = new Rectangle(x * Atlas.GridSize, y * Atlas.GridSize, Atlas.GridSize, Atlas.GridSize);
             *                      var movement = Physics.Slide(origin, destination, tileBox);
             *                      destination = movement.Destination;
             *              }
             *      }
             * }*/
        }