Exemplo n.º 1
0
    void EjectChildren(Transform parent)
    {
        List <Transform> toEject = new List <Transform>();

        foreach (Transform child in parent)
        {
            if (child.GetComponent <AttachedBall>())
            {
                toEject.Add(child);
            }
        }
        //have to do two passes because we need to set parent to null
        //and this modifies what we're enumerating through
        foreach (Transform child in toEject)
        {
            GameObject ejected = PoolManager.Instance.GetPoolByRepresentative(ejectedBallPrefab).GetPooled();
            Vector3    pos     = child.position;
            Quaternion rot     = child.rotation;
            ejected.transform.position = pos;
            ejected.transform.rotation = rot;
            ejected.GetComponent <SpriteRenderer>().sprite = child.GetComponent <SpriteRenderer>().sprite;
            foreach (Transform c in child)
            {
                c.parent = ejected.transform;
            }
            child.SendMessage("Destroy");

            AttachedBall.AddStatusAllAttachedBalls(ejected.transform, BallStatus.EJECTED, ejected.GetComponent <SpriteRenderer>().sharedMaterial);
            ejected.SetActive(true);
            ejected.GetComponent <Rigidbody2D>().velocity = (pos - parent.position).normalized * ejectionForce;
        }
    }
Exemplo n.º 2
0
    float ScoreChild(Transform child, int depth, ref int maxChain)
    {
        if (depth > maxChain)
        {
            maxChain = depth;
        }
        AttachedBall ab     = child.GetComponent <AttachedBall>();
        float        points = depth * ab.pointValue;

        foreach (Transform c in child)
        {
            if (c.GetComponent <AttachedBall>() != null)
            {
                //if a connecting ball is golden or the same colour then continue the chain
                if (ComboValid(child, c))
                {
                    points += ScoreChild(c, depth + 1, ref maxChain);
                }
                else
                {
                    points += ScoreChild(c, 1, ref maxChain);
                }
            }
        }
        //Debug.Log (child.name + child.GetInstanceID() + " scoring for " + points);
        return(points);
    }
Exemplo n.º 3
0
 public override void ApplyEffect(Transform target)
 {
     if (!(target.gameObject.layer == LayerMask.NameToLayer("Player")))
     {
         //Debug.Log ("Delinker Ball Applying Effect - Target: " + target.GetInstanceID());
         target.parent = transform;
         AttachedBall.AddStatusAllAttachedBalls(target, BallStatus.EJECTED, ejectedMat);
     }
 }
Exemplo n.º 4
0
 public void RemoveStatus(BallStatus newStatus, Material toRemove)
 {
     FlagsHelper.Unset <BallStatus>(ref status, newStatus);
     if (toRemove != null && matQueue.Remove(toRemove))
     {
         CheckStatus();
     }
     AttachedBall.RemoveStatusAllAttachedBalls(transform, newStatus, toRemove);
 }
Exemplo n.º 5
0
 public void GetShocked(float duration, Material shockedMat)
 {
     if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.SHOCKED))
     {
         GetComponent <Renderer>().sharedMaterial = shockedMat;
         AddStatus(BallStatus.SHOCKED, shockedMat);
         AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.SHOCKED, shockedMat);
         StartCoroutine(Timers.Countdown(duration, () => RemoveStatus(BallStatus.SHOCKED, shockedMat)));
     }
 }
Exemplo n.º 6
0
 public void GetFrozen(float duration, Material frozenMat)
 {
     if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.FROZEN))
     {
         GetComponent <Renderer>().sharedMaterial = frozenMat;
         AddStatus(BallStatus.FROZEN, frozenMat);
         GetComponent <Rigidbody2D>().velocity    = Vector2.zero;
         GetComponent <Rigidbody2D>().isKinematic = true;
         AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.FROZEN, frozenMat);
         StartCoroutine(Timers.Countdown(duration, () => {
             RemoveStatus(BallStatus.FROZEN, frozenMat);
             GetComponent <Rigidbody2D>().isKinematic = false;
         }));
     }
 }
Exemplo n.º 7
0
    public static bool ComboValid(Transform parent, Transform child)
    {
        AttachedBall childBall  = child.GetComponent <AttachedBall>();
        AttachedBall parentBall = parent.GetComponent <AttachedBall>();

        if (childBall != null && parentBall != null)
        {
            return(!FlagsHelper.IsSet(childBall.status, BallStatus.INFECTED) && !FlagsHelper.IsSet(parentBall.status, BallStatus.INFECTED) &&
                   (childBall.type == AttachedBall.BallTypeNames.BonusBall || parentBall.type == AttachedBall.BallTypeNames.BonusBall ||
                    childBall.type == parentBall.type));
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 8
0
    public void GetGlooped(float duration, Material gloopMat)
    {
        if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.GLOOPED))
        {
            GetComponent <Renderer>().sharedMaterial = gloopMat;
            AddStatus(BallStatus.GLOOPED, gloopMat);
            //we make copies so the delegate we create keeps its own state

            /*
             * Material oldMat = GetComponent<SpriteRenderer>().sharedMaterial;
             * Transform trans = transform;
             * GetComponent<SpriteRenderer>().sharedMaterial = gloopMaterial;
             * StartCoroutine(Timers.Countdown(duration,() => {
             *      Debug.Log ("Resetting mat to " + oldMat.name + " " + oldMat.GetInstanceID());
             *      trans.GetComponent<SpriteRenderer>().sharedMaterial = oldMat;
             * }));
             */
            AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.GLOOPED, gloopMat);
            StartCoroutine(Timers.Countdown(duration, () => RemoveStatus(BallStatus.GLOOPED, gloopMat)));
        }
    }
Exemplo n.º 9
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.GLOOPED))
        {
            ContactPoint2D[] cps           = col.contacts;
            Transform        parent        = GetCorrectParent(cps);
            GameObject       playerPart    = parent.gameObject;
            GameObject       collidingBall = col.gameObject;
            if (BallCollect != null)
            {
                BallCollect(this.gameObject, playerPart, collidingBall);
            }
            if (col.gameObject.layer == LayerMask.NameToLayer("GoodBall"))
            {
                PointBall pb;
                if (pb = col.gameObject.GetComponent <PointBall>())
                {
                    if (pb.HasSound)
                    {
                        SoundEffectManager.PlayClipOnce(pb.CollectSound, Vector3.zero, 1);
                    }
                    Vector3    pos    = pb.transform.position;
                    Quaternion rot    = pb.transform.rotation;
                    Vector3    scale  = pb.transform.localScale;
                    Material   mat    = pb.GetComponent <SpriteRenderer>().sharedMaterial;
                    Sprite     sprite = pb.GetComponent <SpriteRenderer>().sprite;
                    pb.Destroy();
                    AttachedBall ball = ballPool.GetPooled().GetComponent <AttachedBall>();

                    ball.transform.position = pos;
                    ball.transform.rotation = rot;
                    ball.GetComponent <SpriteRenderer>().sprite = sprite;
                    //ball.transform.localScale = scale;
                    ball.GetComponent <SpriteRenderer>().sharedMaterial = mat;
                    ball.gameObject.SetActive(true);

                    ball.transform.parent = parent;
                    if (parent == null)
                    {
                        Debug.LogError("No correct parent could be found");
                    }
                    ball.SetPointValue(pb.pointValue);
                    ball.SetType(pb.gameObject.name);

                    //if we current have any number of statuses, apply them to the new ball
                    if (status != BallStatus.NONE)
                    {
                        //apply all current status to new ball
                        ball.status = status;
                        //include all materials (except the original material)
                        for (int i = 1; i < matQueue.Count; i++)
                        {
                            ball.matQueue.Add(matQueue[i]);
                        }
                        ball.CheckStatus();
                    }
                    //Debug.Log ("Creating Attached Ball at " + pos + " parent: " + ball.transform.parent.GetInstanceID());

                    ScoreCalculator.Instance.ComboUp();
                    //recalculate score
                    ScoreCalculator.Instance.SetScorePrediction();
                }
            }
            else if (col.gameObject.layer == LayerMask.NameToLayer("BadBall"))
            {
                //Debug.Log ("BadBall Collision");
                BadBall bb = col.gameObject.GetComponent <BadBall>();
                bb.ApplyEffect(cps[0].otherCollider.transform);
                if (bb.HasSound)
                {
                    SoundEffectManager.PlayClipOnce(bb.HitSound, Vector3.zero, 1);
                }

                //recalculate score
                ScoreCalculator.Instance.SetScorePrediction();
            }
        }
    }