Exemplo n.º 1
0
        /** Update the ball state */
        public void Update(float seconds)
        {
            if (_bounce != null) {
            _bounce.Update(seconds);
            Position[1] = _bounce.Value;
            if (_bounce.Finished)
              _bounce = null;
              }

              if (Ai != null)
            Ai.Update(_parent.Ball, this);

              if (_display != null)
            _display.Data.Position.Set(Position);
        }
Exemplo n.º 2
0
        /** If the ball intersects this paddle */
        public bool Intersects(Ball b)
        {
            var rectA = new Rect(b.Position [0], b.Position [1], b.Width, b.Height / 3);
              var rectB = new Rect(Position [0], Position [1], Size [0], Size [1]);

              // For rotated test, see:
              // http://stackoverflow.com/questions/115426/algorithm-to-detect-intersection-of-two-rectangles
              if ((Math.Abs(rectA.x - rectB.x) < (Math.Abs(rectA.width + rectB.width) / 2)) &&
            (Math.Abs(rectA.y - rectB.y) < (Math.Abs(rectA.height + rectB.height) / 2))) {

            // Also add some bounce, because its shiny
            if (_bounce == null) {
              _bounce = new nAnim(_display.Data) {
            Duration = 0.3f,
            Magnitude = Math.Sign(_parent.Ball.Velocity[1]) * 1.5f
              };
            }

            return true;
              }
              return false;
        }