private void CorrectBallPosition(IPad pad, IBall ball) { Vector2 previous = ball.Boundary.Min; while (collisionManagerForMoveReversion.Detect(pad, ball)) { if (!ball.MoveBall(true)) { ball.Boundary.Min = previous; padManager.RestartBallYPosition(pad, ball); return; } previous = ball.Boundary.Min; ball.SavePosition(); foreach (IBorder border in borderManager) { if (collisionManagerForMoveReversion.Detect(border, ball)) { padManager.SetBallStartPosition(pad, ball); break; } } if (screenCollisionManager.DetectAndVerify(ball)) { padManager.SetBallStartPosition(pad, ball); break; } } ball.Boundary.Min = previous; }
private void CorrectBallPosition(IPad pad, IBall ball) { while (collisionManagerForMoveReversion.Detect(pad, ball)) { if (!ball.MoveBall(true)) { game.RestartBallYPosition(pad, ball); return; } ball.SavePosition(); foreach (IBorder border in borderManager) { if (collisionManagerForMoveReversion.Detect(border, ball)) { game.SetBallStartPosition(pad, ball); break; } } if (screenCollisionManager.DetectAndVerify(ball)) { game.SetBallStartPosition(pad, ball); break; } } }
protected void DetectPadCollision(IBall ball) { IPad pad = null; bool collisionDetected = false; foreach (var value in padManager) { pad = value.Item3; if (collisionManager.Detect(pad, ball)) { collisionDetected = true; CorrectBallPosition(pad, ball); if (pad.Speed > padSpeedToGoBallFaster) { ball.SetFasterSpeed(); } break; } } if (collisionDetected) { collisionState.SetPadCollistionState(true, true, pad); } }
protected bool HandlePadCollision(IBall ball) { foreach (IPad pad in padManager) { if (collisionManager.Detect(pad, ball)) { pad.LogData(); CorrectBallPosition(pad, ball); collisionManager.Bounce(ball); ball.LogData(); return(true); } } return(false); }
private bool DetectAndVerify(IBorder border, IPad pad) { if (collisionManager.Detect(border, pad)) { if (border.Type == Edge.Left) { pad.Boundary.Min = new Vector2(border.Boundary.Max.X, pad.Boundary.Min.Y); return(true); } if (border.Type == Edge.Right) { pad.Boundary.Min = new Vector2(border.Boundary.Min.X - pad.Boundary.Size.X, pad.Boundary.Min.Y); return(true); } } return(false); }
public bool DetectAndVerify(IPad pad) { if (collisionManager.Detect(border, pad)) { IElement borderElement = border as IElement; IElement padElement = pad as IElement; if (border.Type == Edge.Left) { padElement.PosX = borderElement.PosX + borderElement.Width; return(true); } if (border.Type == Edge.Right) { padElement.PosX = borderElement.PosX - padElement.Width; return(true); } } return(false); }
public static IEnumerable <int> DetectCollision(this IEnumerable <IBrick> bricks, IBall ball, ICollisionManager collisionManager) { var brickHitList = new List <int>(); int i = 0; foreach (var brick in bricks) { if (!brick.IsHit && brick.IsVisible) { if (collisionManager.Detect(brick, ball)) { brickHitList.Add(i); } } ++i; } return(brickHitList); }