private void ShootTimerTickEventHandler(object sender, EventArgs e) { isRunning = true; restOfBalls--; UcBall ball = new UcBall(); //Canvas.SetTop(ball, 0); // Canvas.SetLeft(ball, 0); TranslateTransform transform = ball.RenderTransform as TranslateTransform; transform.X = canvasWidth / 2; transform.Y = 10; ball.Vx = initialVelocity * Math.Cos(currentAngle); ball.Vy = initialVelocity * Math.Sin(currentAngle); if (transform.Y != 0) { } cvs.Children.Add(ball); balls.Add(ball); if (restOfBalls <= 0) { timer.Stop(); // return; } }
private Turn CheckCollision(UcBall ball) { Turn result = new Turn(1, 1); var tempResult = CheckCollisionWithLine(ball, 1, 0, -canvasWidth); if (tempResult != null) { result.Add(tempResult); } tempResult = CheckCollisionWithLine(ball, 1, 0, 0); if (tempResult != null) { result.Add(tempResult); } foreach (var block in blocks.ToArray()) { if (block.Count == 0) { blocks.Remove(block); cvs.Children.Remove(block as UIElement); } tempResult = block.CheckCollision(ball); if (tempResult != null) { result.Add(tempResult); } } return(result); }
private bool CheckDie(UcBall ball) { if (Mode == GameMode.UpToDownWithGravity) { if (ball.Y + R > canvasHeight) { ball.Visibility = Visibility.Collapsed; cvs.Children.Remove(ball); balls.Remove(ball); } } return(false); }
private Turn CheckCollisionWithLine(UcBall ball, double a, double b, double c) { if (!(a == 0 || b == 0)) { throw new Exception("a和b必须有一个为0"); } double distance = Math.Abs(a * ball.X + b * ball.Y + c) / Math.Sqrt(a * a + b * b); if (distance > R) { return(null); } if (b == 0) { return(new Turn(-1, 1)); } else { return(new Turn(1, -1)); } }
public void TurnBall(UcBall ball) { ball.Vx *= Vx; ball.Vy *= Vy; }