Exemplo n.º 1
0
 public Vector2 CheckCollision(World world, GeometryType ignore)
 {
     float xMove = 0;
     GeometryBox collisionBox = new GeometryBox();
     collisionBox.rect = _bbox;
     if (world.Collides(_bbox, ignore, collisionBox, out collisionBox)) {
         xMove = 5 * Math.Sign(_bbox.X - collisionBox.rect.X);
     }
     _position += new Vector2(xMove, 0);
     _bbox.X += (int)xMove;
     return new Vector2(xMove, 0);
 }
Exemplo n.º 2
0
        public Vector2 MoveTo(Vector2 position, World world, out int hcol, out int vcol, GeometryType ignore)
        {
            Vector2 delta = position - _position;
            hcol = 0;
            vcol = 0;

            while (delta.LengthSquared() > 0.1f) {
                float dX = Math.Sign(delta.X);
                if (Math.Abs(delta.X) < 1) dX = delta.X;
                delta.X -= dX;

                float dY = Math.Sign(delta.Y);
                if (Math.Abs(delta.Y) < 1) dY = delta.Y;
                delta.Y -= dY;

                _bbox.X += (int)Math.Round(dX);
                if (world.Collides(_bbox, ignore)) {
                    _bbox.X -= (int)Math.Round(dX);
                    hcol = Math.Sign(dX);
                    delta.X = 0;
                    dX = 0;
                }

                _position.X += dX;

                _bbox.Y += (int)Math.Round(dY);

                if (world.Collides(_bbox, ignore)) {
                    _bbox.Y -= (int)Math.Round(dY);
                    vcol = Math.Sign(dY);
                    delta.Y = 0;
                    dY = 0;
                }

                _position.Y += dY;
            }

            return _position;
        }