public void move(List <Hole> holes) { int XVelocity = (int)(Velocity * Math.Cos(Angle)); int YVelocity = (int)(Velocity * Math.Sin(Angle)); XCoord += XVelocity; YCoord += YVelocity; if (collisionWithHole(holes)) { visible = false; } if (XCoord - Radius <= Bounds.Left || XCoord + Radius >= Bounds.Right) { XCoord -= XVelocity; Angle = HoleGenerator.getRandomAngle(Angle); } if (YCoord - Radius <= Bounds.Top || ((YCoord + Radius) >= Bounds.Bottom)) { YCoord -= YVelocity; Angle = HoleGenerator.getRandomAngle(Angle); } }
private void mainScreen_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point clickPoint = e.Location; if (clickPoint.X - 25 >= 0 && clickPoint.X + 25 <= mainScreen.Width && clickPoint.Y - 25 >= 0 && clickPoint.Y + 25 <= mainScreen.Height) { int randomAngle = HoleGenerator.getRandomAngle(-1); Ball newBall = new Ball(clickPoint.X, clickPoint.Y, 25, color, mainScreen.ClientRectangle, randomAngle); listOfBalls.addBall(newBall); toolStripLabel.Text = "# Balls : " + listOfBalls.size().ToString(); mainScreen.Invalidate(); } } }