Example #1
0
        public void SetBallVelocityAfterCollision(Ball ball)
        {
            ChangeVelocityToUp(ball);
            _zones = new ShipZones(_ship);

            if(_zones.HitFarthestLeftZone(ball))
            {
                ball.Velocity.X = -3.5f;
            }
            else if(_zones.HitFarthestRightZone(ball))
            {
                ball.Velocity.X = 3.5f;
            }
            else if (_zones.HitFarLeftZone(ball))
            {
                ball.Velocity.X = -2.0f;
            }
            else if (_zones.HitFarRightZone(ball))
            {
                ball.Velocity.X = 2.0f;
            }
            else if (_zones.HitMiddleLeftZone(ball))
            {
                ball.Velocity.X = -1.0f;
            }
            else if (_zones.HitMiddleRightZone(ball))
            {
                ball.Velocity.X = 1.0f;
            }
            else if(_zones.HitCentreRightZone(ball))
            {
                ball.Velocity.X = 0.5f;
            }
        }
Example #2
0
 private static void ChangeVelocityToUp(Ball ball)
 {
     if (Math.Sign(ball.Velocity.Y) >= 0)
         ball.Velocity.Y = -(ball.Velocity.Y);
 }
 public BallAndBrickCollisionHandler(Ball ball)
 {
     _ball = ball;
 }
Example #4
0
 public bool HitMiddleLeftZone(Ball ball)
 {
     return ball.Position.X < (_ship.Left + _shipSection * 3);
 }
Example #5
0
 public bool HitMiddleRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Right - _shipSection * 3);
 }
Example #6
0
 public bool HitFarthestLeftZone(Ball ball)
 {
     return ball.Position.X < (_ship.Left + _shipSection);
 }
Example #7
0
 public bool HitFarthestRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Right - _shipSection);
 }
Example #8
0
 public bool HitCentreRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Center.X);
 }
Example #9
0
 private void Remove(Ball ball)
 {
     _balls.Remove(ball);
 }
Example #10
0
        private bool IsBallDead(Ball ball)
        {
            Rectangle viewport = _world.GetViewport();

            return !viewport.Contains(new Point(
                            (int)ball.Position.X,
                            (int)ball.Position.Y));
        }
Example #11
0
 private void HandleBallDeath(Ball ball)
 {
     Remove(ball);
     if (_balls.Count == 0)
         _world.HandleLostLife();
 }
Example #12
0
 public void Add(Ball ball)
 {
     _balls.Add(ball);
 }