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

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