示例#1
0
 private void OnBallCollision(BallCollisionEventArgs e)
 {
     if (e.IncomingBall.IsProjectile)
     {
         var magnitude    = e.BallInGrid.Magnitude;
         var gridPosition = _gridPositionCalculator.FindGridPosition(e.BallInGrid, magnitude, e.AngleOfImpact);
         _ballGrid.Append(e.IncomingBall, gridPosition);
     }
 }
示例#2
0
        public void TestBallCollision(float angleOfImpact, int expectedX, int expectedY)
        {
            var incomingBall = CreateSubstitueBall(BallType.Blue, int.MaxValue, int.MaxValue);
            var ballInGrid   = CreateSubstitueBall(BallType.Blue, 5, 5);

            incomingBall.IsProjectile.Returns(true);

            var ballCollisionEventArgs = new BallCollisionEventArgs(incomingBall, ballInGrid, angleOfImpact);

            _ballGridController.CallPrivateMethod("OnBallCollision", ballCollisionEventArgs);

            _mockBallGrid.Received().Append(incomingBall, new GridPosition(expectedX, expectedY));
        }
示例#3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == Tags.Balls)
     {
         var otherObject = collision.gameObject.GetComponent <IBallController>();
         if (IsProjectile && otherObject != null)
         {
             var projectilePosition = transform.position;
             var gridBallPosition   = collision.transform.position;
             var angle = angleOfImpactCalculator.Calculate(projectilePosition, gridBallPosition);
             var ballCollisionEventArgs = new BallCollisionEventArgs(this, otherObject, angle);
             GameManager.Instance.EventBus.Broadcast(ballCollisionEventArgs);
         }
     }
 }