コード例 #1
0
        public override void ProcessCollision(Collision collision)
        {
            base.ProcessCollision(collision);
            BallData ball = null;

            if (collision.pair.first is BallData)
            {
                ball = collision.pair.first as BallData;
            }
            else if (collision.pair.second is BallData)
            {
                ball = collision.pair.second as BallData;
            }

            if (ball != null)
            {
                ball.Kill();
            }
        }
コード例 #2
0
        public BallData[] Update(float deltaTime)
        {
            time += deltaTime;
            var result = new List <BallData>();

            while (time > delay)
            {
                time -= delay;
                if (numBalls > 0)
                {
                    var newBall = new BallData(radius);
                    newBall.SetPositionX(position.x);
                    newBall.SetPositionY(position.y);
                    newBall.SetSpeed(startSpeedDirection * startSpeed);
                    newBall.UpdatePosition(time);
                    result.Add(newBall);
                }

                numBalls--;
            }
            return(result.ToArray());
        }
コード例 #3
0
        protected Collision TryGetCollisionWithCircle(BallData circle, float deltaTime, bool ignoreRadius = false)
        {
            //check speed direction
            if (Vector2.Dot(circle.GetSpeed(), Normal) > 0)
            {
                return(null);
            }

            var trajectoryStart  = circle.GetPosition();
            var trajectoryFinish = trajectoryStart + circle.GetSpeed() * deltaTime;

            //move line towards circle
            var lineStart  = start;
            var lineFinish = finish;

            if (!ignoreRadius)
            {
                var offset = Normal * circle.GetRadius();
                lineStart  += offset;
                lineFinish += offset;
            }

            Debug.DrawLine(lineStart, lineFinish, Color.yellow);

            var intersection = new Vector2();

            if (MathOperations.LineSegementsIntersect(trajectoryStart, trajectoryFinish,
                                                      lineStart, lineFinish, out intersection, true))
            {
                var toIntersection  = intersection - trajectoryStart;
                var circleSpeed     = circle.GetSpeed();
                var speedX          = circleSpeed.x < 0 ? -circleSpeed.x : circleSpeed.x;
                var speedY          = circleSpeed.y < 0 ? -circleSpeed.y : circleSpeed.y;
                var timeToCollision = speedX > speedY ? toIntersection.x / circleSpeed.x :
                                      toIntersection.y / circleSpeed.y;
                return(new Collision(this, circle, timeToCollision));
            }
            return(null);
        }
コード例 #4
0
        private ICollider[] ProcessCollision(Collision collision, float timeLeft, HashSet <ICollider> ignoreArray)
        {
            collision.Process();
            ICollider ignoringCollider = null;
            BallData  collider         = null;

            if (collision.pair.first is BallData)
            {
                collider         = collision.pair.first as BallData;
                ignoringCollider = collision.pair.second.GetUsedCollider();
            }
            if (collision.pair.second is BallData)
            {
                collider         = collision.pair.second as BallData;
                ignoringCollider = collision.pair.first.GetUsedCollider();
            }
            if (collider != null && !collider.IsAlive)
            {
                if (circles.Contains(collider))
                {
                    circles.Remove(collider);
                    KillObjectCallback?.Invoke(collider);
                }
            }
            if (ignoringCollider != null)
            {
                if (ignoreArray == null)
                {
                    ignoreArray = new HashSet <ICollider>();
                }
                ignoreArray.Add(ignoringCollider);
                if (ignoringCollider is BonusData)
                {
                    KillObjectCallback?.Invoke(ignoringCollider as BonusData);
                }
            }
            return(CheckCollisions(new ICollider[] { collider }, timeLeft, ignoreArray));
        }