private void DrawBall(MovableBall ball, Graphics graphics) { RectangleF rect = new RectangleF(ball.GetXCoordinate(), ball.GetYCoordinate(), ball.GetRadius(), ball.GetRadius()); graphics.DrawEllipse(blackPen, rect); ball.Move(); }
public static void CheckAndFixCollisionWithBoarders(MovableBall ball, int height, int width) { if (ball.GetXCoordinate() < 0 || ball.GetXCoordinate() > width) { ball.SetXSpeed(ball.GetXSpeed() * -1); } if (ball.GetYCoordinate() < 0 || ball.GetYCoordinate() > height) { ball.SetYSpeed(ball.GetYSpeed() * -1); } }
private static int SetCoordinates(MovableBall ball1, MovableBall ball2) { // меняем скорость по x Console.WriteLine("start to calculate"); int speed = ball1.GetXSpeed(); ball1.SetXSpeed(((ball1.GetWeight() - ball2.GetWeight()) * ball1.GetXSpeed() + 2 * ball2.GetWeight() * ball2.GetXSpeed()) / (ball1.GetWeight() + ball2.GetWeight())); ball2.SetXSpeed(((ball2.GetWeight() - ball1.GetWeight()) * ball2.GetXSpeed() + 2 * ball1.GetWeight() * speed) / (ball1.GetWeight() + ball2.GetWeight())); // меняем скорость по y speed = ball1.GetYSpeed(); ball1.SetYSpeed(((ball1.GetWeight() - ball2.GetWeight()) * ball1.GetYSpeed() + 2 * ball2.GetWeight() * ball2.GetYSpeed()) / (ball1.GetWeight() + ball2.GetWeight())); ball2.SetYSpeed(((ball2.GetWeight() - ball1.GetWeight()) * ball2.GetYSpeed() + 2 * ball1.GetWeight() * speed) / (ball1.GetWeight() + ball2.GetWeight())); return(speed); }
private void CreateNewBall() { balls[lastPoint++] = new MovableBall(Convert.ToInt32(weight.Text), Convert.ToInt32(radius.Text), Convert.ToInt32(n_speed.Text), Convert.ToInt32(t_speed.Text), 0, 0); Console.WriteLine("creating new Ball"); }