private static void PlatformsCollision(Label ball) { foreach (Control platform in Platforms) { Bounds ballBounds = new Bounds { X = (int)b.X, Y = (int)b.Y, W = b.Width, H = b.Height }; Bounds platformBounds = new Bounds { X = platform.Location.X, Y = platform.Location.Y, W = platform.Width, H = platform.Height }; if (!InBounds(platform, ball)) { continue; } Direction dir = b.Dir; switch (WhereIsBallRespectPlatform(ballBounds, platformBounds, platform, ball)) { case Where.Far: case Where.Outside: case Where.Near: return; case Where.Top: DirectionMethods.Topimize(ref dir); platform.Visible = false; Score += 15; break; case Where.Bot: DirectionMethods.Bottomize(ref dir); platform.Visible = false; Score += 15; break; case Where.Left: DirectionMethods.Leftimize(ref dir); platform.Visible = false; Score += 15; break; case Where.Right: DirectionMethods.Rightimize(ref dir); platform.Visible = false; Score += 15; break; } b.Dir = dir; if (!platform.Visible) { Platforms.Remove(platform); return; } } }
private static Where WhereIsBallRespectPlatform(Bounds obj1, Bounds obj2, Control platform, Label ball) { if (!InBounds(platform, ball)) { return Where.Far & Where.Outside; } if (obj1.Y < obj2.Y && obj1.Y + obj1.H < obj2.Y + obj2.H) { return Where.Top; } if (obj1.Y > obj2.Y && obj1.Y + obj1.H > obj2.Y + obj2.H) { return Where.Bot; } if (obj1.X > obj2.X && obj1.X + obj1.W > obj2.X + obj2.W) { return Where.Right; } if (obj1.X < obj2.X && obj1.X + obj1.W < obj2.X + obj2.W) { return Where.Left; } return Where.Near; }
private static void PlatformCollide(Label platform, Label ball) { Bounds ballBounds = new Bounds { X = (int)b.X, Y = (int)b.Y, W = b.Width, H = b.Height }; Bounds platformBounds = new Bounds { X = platform.Location.X, Y = platform.Location.Y, W = platform.Width, H = platform.Height }; if (!InBounds(platform, ball)) { return; } Direction dir = b.Dir; switch(WhereIsBallRespectPlatform(ballBounds, platformBounds, platform, ball)) { case Where.Far: case Where.Outside: case Where.Near: return; case Where.Top: DirectionMethods.Topimize(ref dir); break; case Where.Bot: DirectionMethods.Bottomize(ref dir); break; case Where.Left: DirectionMethods.Leftimize(ref dir); break; case Where.Right: DirectionMethods.Rightimize(ref dir); break; } b.Dir = dir; }