public void Update(float seconds, Ball ball)
 {
     if (!_ready)
     Init();
       _motion.Update(ball.Position[0], ball.Position[1]);
       _trail.Rebuild(_motion.Points());
 }
Example #2
0
        public void Update(Ball b, Paddle p)
        {
            float target = 0f;
              if (b.Velocity [1] > 0)
            target = b.Position [0];

              float distance_to_target = Math.Abs(target - p.Position [0]);
              if (distance_to_target < p.Speed) {
            distance_to_target = distance_to_target / 10f;
            if (distance_to_target < 1f)
              distance_to_target = 0f;
              }

              if (target > p.Position[0])
            p.MoveRight(distance_to_target);
              if (target < p.Position[0])
            p.MoveLeft(distance_to_target);
        }
Example #3
0
        public void Update(Ball b, Paddle p)
        {
            var target = b.Position [0];

              float distance_to_target = Math.Abs(target - p.Position [0]);
              if (distance_to_target < 1f)
            return;

              /* Don't jerk */
              if ((distance_to_target > 2f) && (distance_to_target < 2.5f)) {
            distance_to_target = 0.3f;
              }

              if (target > p.Position[0])
            p.MoveRight(distance_to_target);

              if (target < p.Position[0])
            p.MoveLeft(distance_to_target);
        }
Example #4
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;
        }
Example #5
0
        /** Reset the ball position and start again */
        public void NewGame()
        {
            PlayerPaddle = new Paddle(this);
              AiPaddle = new Paddle(this);
              Ball = new Ball(this);
              Field =  new Field(this, Camera());
              Sparkle = new Sparkle(this);
              RainbowTrail = new RainbowTrail(this);
              Flare = new Ps.Model.Object.Flare(this);
              Collectables = new Collectables(this);

              /* actions */
              SetupActions();
              _input = new GameInput(this);
              Game.SoundReset(); // reload

              /* Set initial paddle positions */
              PlayerPaddle.Position[0] = 0f;
              PlayerPaddle.Position[1] = Field.Bounds[1] + nLayout.DistanceInWorld(14f, nAxis.Y, _camera);;
              AiPaddle.Position[0] = 0f;
              AiPaddle.Position[1] = Field.Bounds[3] - AiPaddle.Size[1] - nLayout.DistanceInWorld(7f, nAxis.Y, _camera);

              var direction = new nGLine() {
            P1 = new float[2] { 0, 0 },
            P2 = new float[2] { nRand.Float(0f, 1f), nRand.Float(1f, 0.3f) }
              };
              var unit = direction.Unit;
              Ball.Position[0] = 0;
              Ball.Position[1] = 0;
              Ball.Velocity[0] = unit[0] * 35f;
              Ball.Velocity[1] = unit[1] * 35f;

              /* reset paddles */
              AiPaddle.Ai = new EasyAiProfile();
              AiPaddle.Speed = AiPaddle.Ai.Speed;
              PlayerPaddle.Speed = Config.PlayerSpeed;
              AiPaddle.Position[0] = 0;
              PlayerPaddle.Position[0] = 0;

              /* ai */
              Activated = false;
              Camera().Pipe.Drawables.Clear();
              Camera().Pipe.Render();
        }
Example #6
0
 public void Update(Ball b, Paddle p)
 {
     p.Position[0] = b.Position[0];
 }
Example #7
0
 /** Check if the ball collides with any twinkles and convert into a score */
 public void CheckBallCollisions(Ball b)
 {
     if (b != null) {
     var qb = new nGQuad(5f).Offset(b.Position);
     foreach (var t in Twinkles) {
       var qc = new nGQuad(t.Size).Offset(t.Position);
       if (qc.Intersects(qb)) {
     t.Die();
     CreateScore(t);
       }
     }
       }
 }