Exemple #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;
            }
        }
Exemple #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;
 }
Exemple #4
0
 public bool HitMiddleLeftZone(Ball ball)
 {
     return ball.Position.X < (_ship.Left + _shipSection * 3);
 }
Exemple #5
0
 public bool HitMiddleRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Right - _shipSection * 3);
 }
Exemple #6
0
 public bool HitFarthestLeftZone(Ball ball)
 {
     return ball.Position.X < (_ship.Left + _shipSection);
 }
Exemple #7
0
 public bool HitFarthestRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Right - _shipSection);
 }
Exemple #8
0
 public bool HitCentreRightZone(Ball ball)
 {
     return ball.Position.X > (_ship.Center.X);
 }
Exemple #9
0
 private void Remove(Ball ball)
 {
     _balls.Remove(ball);
 }
Exemple #10
0
        private bool IsBallDead(Ball ball)
        {
            Rectangle viewport = _world.GetViewport();

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