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; } }
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; }
public bool HitMiddleLeftZone(Ball ball) { return ball.Position.X < (_ship.Left + _shipSection * 3); }
public bool HitMiddleRightZone(Ball ball) { return ball.Position.X > (_ship.Right - _shipSection * 3); }
public bool HitFarthestLeftZone(Ball ball) { return ball.Position.X < (_ship.Left + _shipSection); }
public bool HitFarthestRightZone(Ball ball) { return ball.Position.X > (_ship.Right - _shipSection); }
public bool HitCentreRightZone(Ball ball) { return ball.Position.X > (_ship.Center.X); }
private void Remove(Ball ball) { _balls.Remove(ball); }
private bool IsBallDead(Ball ball) { Rectangle viewport = _world.GetViewport(); return !viewport.Contains(new Point( (int)ball.Position.X, (int)ball.Position.Y)); }
private void HandleBallDeath(Ball ball) { Remove(ball); if (_balls.Count == 0) _world.HandleLostLife(); }
public void Add(Ball ball) { _balls.Add(ball); }