protected void OnBallMoved(object sender, BallMovedEventArgs e) { if (!ballPopManager.TryPopLines()) { ballSpawnManager.TrySpawnFewBalls(); } }
public void OnBallMoved(Ball source, BallMovedEventArgs args) { var ballPosition = args.Position; var ballPrevPosition = new double[] { ballPosition[0] - source.Direction.XComponent, ballPosition[1] + source.Direction.YComponent }; if (InXBounds(ballPosition)) // If in the x-boundaries { if (InYBounds(ballPosition)) // If in the y-boundaries { if (InXBounds(ballPrevPosition)) { if (_canBeHit) { source.Direction = new Vector(source.Direction.XComponent, -source.Direction.YComponent); Hit(); } } else { if (_canBeHit) { source.Direction = new Vector(-source.Direction.XComponent, source.Direction.YComponent); Hit(); } } } } }
public void OnBallMoved(BallMovedEventArgs args) { if (BallMoved != null) { BallMoved(this, args); } }
public override void Move(double[] newPosition) { base.Move(newPosition); if (_position[0] >= Console.WindowWidth) { _position = new double[] { Console.WindowWidth - 1, _position[1] }; Direction = new Vector(-Direction.XComponent, Direction.YComponent); } if (_position[0] < 0) { _position = new double[] { 0, _position[1] }; Direction = new Vector(-Direction.XComponent, Direction.YComponent); } var args = new BallMovedEventArgs() { Position = _position }; OnBallMoved(args); }
// Called when the ball moves public void OnBallMoved(Ball source, BallMovedEventArgs args) { var ballPosition = args.Position; if (ballPosition[1] <= _topWall.StartingLocation()[1]) { ResourceManager.GameWon = true; // Game won _manager.SwitchCurrentPortrait((int)PageHandles.EndGame); // Switch to the endgane } else if (ballPosition[1] >= _bottomWall.StartingLocation()[1]) { _manager.SwitchCurrentPortrait((int)PageHandles.EndGame); // Switch to the endgame } }
/// <summary> /// Calls when the ball moves. /// </summary> /// <param name="source">The source of the event</param> /// <param name="args">The arguments passed through</param> public void OnBallMoved(Ball source, BallMovedEventArgs args) { var ballPosition = args.Position; if (_canColide) { if (ballPosition[0] >= _position[0] && ballPosition[0] <= (_position[0] + 6)) { if (ballPosition[1] >= _position[1] - 1.0 && ballPosition[1] <= _position[1] + 1.0) { _changed = true; var changeMap = new double[] { -0.4, -0.2, 0, 0, 0.2, 0.4 }; // How much the balls vector changes var mapIndex = (int)Math.Floor(ballPosition[0] - _position[0]); try { source.Direction = new Vector(source.Direction.XComponent + changeMap[mapIndex], -source.Direction.YComponent); } catch (IndexOutOfRangeException) { source.Direction = new Vector(source.Direction.XComponent, -source.Direction.YComponent); Debug.Print("Caught Exception : IndexOutOfRange in Paddle Collision"); // Log the error } _canColide = false; // Cannot collide // Set a timer for the collision to reactivate after 0.2 seconds var collideTimer = new System.Timers.Timer(200) { Enabled = true }; collideTimer.Elapsed += OnTimedEvent; collideTimer.Start(); } } } }