public bool HasHitSideWalls() { if (BoxRestrictions.SideWallsCollisions(this.breakout.restrictions, this.restrictions)) { this.velocity.RotateVertically(); this.BallMovement(); return(true); } return(false); }
public bool HasHitTopWall() { if (BoxRestrictions.TopWallCollisions(this.breakout.restrictions, this.restrictions, this.breakout.StripSize)) { this.velocity.RotateHorizontally(); this.BallMovement(); return(true); } return(false); }
public static double IntersectionAreaPercentage(BoxRestrictions primary, BoxRestrictions secondary) { BoxRestrictions intersection = Intersection(primary, secondary); if (intersection != null) { return(intersection.RectangleArea / primary.RectangleArea); } return(0.0); }
public Paddle(Breakout breakout, int x, int y, int paddleWidth, int paddleHeight) { this.breakout = breakout; this.paddle = new PictureBox(); this.paddle.Parent = this.breakout; this.paddle.Location = new Point(x, y); this.paddle.Height = paddleHeight; this.paddle.Width = paddleWidth; this.paddle.BackColor = this.paddleColor; this.restrictions = new BoxRestrictions(this.paddle.Left, this.paddle.Top, this.paddle.Width, this.paddle.Height); }
public Brick(Breakout breakout, int x, int y, int brickWidth, int brickHeight, Color brickColor, int colorValue) { this.breakout = breakout; this.brick = new PictureBox(); this.brick.Parent = this.breakout; this.brick.Location = new Point(x, y); this.brick.Height = brickHeight; this.brick.Width = brickWidth; this.brick.BackColor = brickColor; this.colorValue = colorValue; this.restrictions = new BoxRestrictions(this.brick.Left, this.brick.Top, this.brick.Width, this.brick.Height); }
public Ball(Breakout breakout, int x, int y, int ballWidth, int ballHeight) { this.breakout = breakout; this.ball = new PictureBox(); this.ball.Parent = this.breakout; this.ball.Left = x; this.ball.Top = y; this.ball.Height = ballHeight; this.ball.Width = ballWidth; this.ballImage = new Bitmap(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "blue.png")), this.ball.Height, this.ball.Width); this.ball.Image = this.ballImage; this.velocity = new XY(3.0, -4.0); this.restrictions = new BoxRestrictions(this.ball.Left, this.ball.Top, this.ball.Width, this.ball.Height); }
public bool HasHitPaddle(Paddle paddle) { if (BoxRestrictions.HasCollided(paddle.restrictions, this.restrictions)) { double xDeviation = (this.restrictions.XCenter - paddle.restrictions.XCenter) / ((paddle.restrictions.Width + this.restrictions.Width) / 2.0); this.velocity.Y *= -1.0; this.velocity.X += xDeviation * 0.70 * (Math.Abs(this.velocity.X) + (9 / (3 + Math.Abs(this.velocity.X)))); this.velocity.X = Math.Max(-15, Math.Min(15, this.velocity.X)); this.BallMovement(); return(true); } return(false); }
private static BoxRestrictions Intersection(BoxRestrictions box1, BoxRestrictions box2) { if (!HasCollided(box1, box2)) { return(null); } // Collisions double[] xCoordinates = new double[] { box1.Left, box1.Right, box2.Left, box2.Right }; double[] yCoordinates = new double[] { box1.Top, box1.Bottom, box2.Top, box2.Bottom }; Array.Sort(xCoordinates); Array.Sort(yCoordinates); return(new BoxRestrictions(xCoordinates[1], yCoordinates[1], xCoordinates[2] - xCoordinates[1], yCoordinates[2] - yCoordinates[1])); }
private void PlayGame(object sender, EventArgs e) { this.ClearWindow(); this.CreateBricks(); this.CreatePaddle(); this.CreateBall(); this.keyboardManager = new KeyboardManager(this); this.keyboardManager.Focus(); this.restrictions = new BoxRestrictions(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); this.timer = new Timer(); this.timer.Interval = this.tickPeriod; this.timer.Tick += this.Tick; this.timer.Enabled = true; this.stopwatch = new Stopwatch(); this.stopwatch.Start(); }
public Brick HasHitBricks(List <Brick> gameBricks) { foreach (Brick brick in gameBricks) { switch (BoxRestrictions.GetCollisionLocation(brick.restrictions, this.restrictions)) { case BoxRestrictions.CollisionLocation.Right: case BoxRestrictions.CollisionLocation.Left: this.velocity.RotateVertically(); this.BallMovement(); return(brick); case BoxRestrictions.CollisionLocation.Top: case BoxRestrictions.CollisionLocation.Bottom: this.velocity.RotateHorizontally(); this.BallMovement(); return(brick); } } return(null); }
public bool HasHitBottomWall(Paddle paddle) { if (BoxRestrictions.BottomWallCollisions(this.breakout.restrictions, this.restrictions, this.breakout.StripSize, (int)paddle.restrictions.Height)) { if (this.breakout.NumberOfLives > 1) { this.breakout.NumberOfLives -= 1; this.ball.Dispose(); this.breakout.CreateBall(); return(false); } else { this.Velocity.X = 0.0; this.Velocity.Y = 0.0; this.breakout.GameOver(); return(true); } } return(false); }
public static CollisionLocation GetCollisionLocation(BoxRestrictions primary, BoxRestrictions secondary) { if (!HasCollided(primary, secondary)) { return(CollisionLocation.NoCollision); } double intersectionRightPrimary = IntersectionAreaPercentage(primary.BoxBoundaries(BoxParts.Right), secondary); double intersectionLeftPrimary = IntersectionAreaPercentage(primary.BoxBoundaries(BoxParts.Left), secondary); double intersectionTopPrimary = IntersectionAreaPercentage(primary.BoxBoundaries(BoxParts.Upper), secondary); double intersectionBottomPrimary = IntersectionAreaPercentage(primary.BoxBoundaries(BoxParts.Lower), secondary); double intersectionRightSecondary = IntersectionAreaPercentage(secondary.BoxBoundaries(BoxParts.Right), primary); double intersectionLeftSecondary = IntersectionAreaPercentage(secondary.BoxBoundaries(BoxParts.Left), primary); double intersectionTopSecondary = IntersectionAreaPercentage(secondary.BoxBoundaries(BoxParts.Upper), primary); double intersectionBottomSecondary = IntersectionAreaPercentage(secondary.BoxBoundaries(BoxParts.Lower), primary); double intersectionRight = intersectionRightPrimary + intersectionLeftSecondary; double intersectionLeft = intersectionLeftPrimary + intersectionRightSecondary; double intersectionTop = intersectionTopPrimary + intersectionBottomSecondary; double intersectionBottom = intersectionBottomPrimary + intersectionTopSecondary; if (intersectionRight >= intersectionLeft && intersectionRight >= intersectionTop && intersectionRight >= intersectionBottom) { return(CollisionLocation.Right); } if (intersectionLeft >= intersectionRight && intersectionLeft >= intersectionTop && intersectionLeft >= intersectionBottom) { return(CollisionLocation.Left); } if (intersectionTop >= intersectionRight && intersectionTop >= intersectionLeft && intersectionTop >= intersectionBottom) { return(CollisionLocation.Top); } return(CollisionLocation.Bottom); }
public static bool HasCollided(BoxRestrictions box1, BoxRestrictions box2) { // No collisions if (box1.Left < box2.Left) { if (box1.Right <= box2.Left) { return(false); } } else { if (box2.Right <= box1.Left) { return(false); } } if (box1.Top < box2.Top) { if (box1.Bottom <= box2.Top) { return(false); } } else { if (box2.Bottom <= box1.Top) { return(false); } } // Some collision return(true); }
public static bool BottomWallCollisions(BoxRestrictions mainWindow, BoxRestrictions ball, int StripSize, int paddleWidth) { return((ball.Top + ball.Height) >= (mainWindow.Height - StripSize + paddleWidth)); }
public static bool TopWallCollisions(BoxRestrictions mainWindow, BoxRestrictions ball, int StripSize) { return(mainWindow.Top + StripSize >= ball.Top); }
public static bool SideWallsCollisions(BoxRestrictions mainWindow, BoxRestrictions ball) { return((ball.Left <= 0) || ((ball.Left + ball.Width) >= mainWindow.Width)); }