Exemple #1
0
    protected void CreateIce(IceScript iceScript)
    {
        bool isMelange = iceScript.Get_attribute().isMelange;

        iceScript.Get_attribute().Combine(attribute);
        iceScript.Get_attribute().isMelange    = isMelange;
        iceScript.Get_attribute().life         = 1;
        iceScript.Get_attribute().life_current = 1;

        iceScript.ResetAttributes();
        iceScript.resetUpdateLife = true;
        iceScript.Get_rb().velocity        = Vector2.zero;
        iceScript.Get_transform().position = transform.position;
    }
Exemple #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        int _layer = other.gameObject.layer;

        if (_layer == 9)//Player
        {
            //Springe in die Luft:
            Rigidbody2D rb_other = other.GetComponent <Rigidbody2D>();
            rb_other.velocity = new Vector2(rb_other.velocity.x, Mathf.Clamp(other.GetComponent <PlayerScript>().attribute.jumpPower, 15, 20));
            cScript.DoShake();

            //Verliere den Eisturm:
            if (cone == null)
            {
                return;
            }
            IceScript iceScript;
            for (int i = cone.iceTower.Count - 1; i > 0; i--)
            {
                iceScript = cone.iceTower[i].Get_transform().GetComponent <IceScript>();
                cone.RemoveIce(iceScript.id);
                iceScript.RemoveFromCone();
                iceScript.Get_rb().velocity = rb_other.velocity + Random.insideUnitCircle * new Vector2(10, 2);
            }
        }
        if (_layer == 8)//Eis
        {
            IceScript iceScript = other.GetComponent <IceScript>();
            if (iceScript.id < 0)
            {
                iceScript.Get_attribute().life_current -= 2;
            }
        }
    }
Exemple #3
0
    IEnumerator EatIce(IceScript iceScript)
    {
        if (iceScript != null)
        {
            if (iceScript.id > 0)
            {
                iceScript.Get_rb().constraints = RigidbodyConstraints2D.FreezeAll;
                iceScript.gameObject.GetComponent <Collider2D>().enabled = false;
                cone.RemoveIce(iceScript.id);
                iceScript.RemoveFromCone();

                yield return(new WaitForSeconds(.2f));
            }

            progressDisplay.UpdateProgressDisplay(iceScript.Get_attribute());
            anim.SetTrigger("squeesh");
        }
        if (iceScript != null)
        {
            Destroy(iceScript.gameObject);
        }
        yield break;
    }
Exemple #4
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Rigidbody2D rb_other = other.GetComponent <Rigidbody2D>();

        if (exclusions.Contains(other.gameObject) || rb_other == null)
        {
            return;
        }

        Vector2 diff       = other.transform.position - transform.position;
        float   distFactor = transform.localScale.x / (2 + diff.sqrMagnitude);

        if (other.GetComponent <IHitable>() != null)
        {
            other.GetComponent <IHitable>().StartPlayHit(other.gameObject); return;
        }

        if (other.gameObject.layer == 8)
        {
            IceScript iceScript = other.GetComponent <IceScript>();
            if (iceScript.id < 0)
            {
                iceScript.Get_attribute().life_current -= distFactor;
            }
            else
            {
                cone.RemoveIce(iceScript.id);
                iceScript.RemoveFromCone();
            }
        }
        else
        {
            distFactor *= rb_other.gravityScale / 2;
        }
        rb_other.velocity += diff * power * distFactor;
    }
Exemple #5
0
    private IEnumerator JumpToPoint(GameObject jumper, GameObject ice)
    {
        goalerList.Remove(jumper);
        jumper.GetComponent <GoalerScript>().block = true;

        Rigidbody2D rb_ice    = ice.GetComponent <Rigidbody2D>();
        Vector3     ice_vel   = Vector3.zero;
        IceScript   iceScript = ice.GetComponent <IceScript>();
        Vector2     endPoint  = ice.transform.position;

        if (iceScript.id < 0)
        {
            iceScript.Get_attribute().runSim = false;

            ice_vel              = rb_ice.velocity;
            rb_ice.bodyType      = RigidbodyType2D.Kinematic;
            rb_ice.constraints   = RigidbodyConstraints2D.FreezeAll;
            ice.gameObject.layer = 0;
        }
        else
        {
            ice = null;
        }
        endPoint += (Vector2)ice_vel * jumpTime * .5f;
        ice_vel  *= Time.fixedDeltaTime;


        Vector2 startPos = jumper.transform.position;
        Vector2 diff     = endPoint - (Vector2)jumper.transform.position + Vector2.down;

        Animator anim = jumper.transform.GetChild(0).GetComponent <Animator>();

        anim.Play("Jump", 0);
        jumper.transform.localScale = Mathf.Abs(jumper.transform.localScale.x) * new Vector3(Mathf.Sign(diff.x), 1, 1);

        //Fliege zum Punkt:
        for (float count = 0; count < 1; count += timeStep)
        {
            if (ice != null)
            {
                ice.transform.position += ice_vel * (1 - count);
            }
            jumper.transform.position = startPos + new Vector2(diff.x * count, (1 - (1 - count) * (1 - count)) * diff.y);
            yield return(new WaitForFixedUpdate());
        }
        //Eis solltee jetzt durch GoalerScript zerstört sein!
        yield return(new WaitForSeconds(.5f));

        Vector2 tmpPos = jumper.transform.position;

        diff *= new Vector2(.5f, -1);
        //Falle auf y-start zurück
        float fallStep = timeStep * 2;

        for (float count = 0; count < 1; count += fallStep)
        {
            jumper.transform.position = tmpPos + new Vector2(diff.x * count, (1 - (1 - count) * (1 - count)) * diff.y);
            yield return(new WaitForFixedUpdate());
        }

        //Laufe zum Start zurück:
        anim.SetBool("moving", true);
        jumper.transform.localScale = new Vector3(-jumper.transform.localScale.x, jumper.transform.localScale.y, 1); //transform.localScale.x * Vector3.one * Mathf.Sign(diff.x);
        tmpPos = jumper.transform.position;
        diff  *= new Vector2(3 * timeStep, 0);
        for (float count = 0; count < 1; count += timeStep)
        {
            jumper.transform.position -= (Vector3)diff;
            yield return(new WaitForFixedUpdate());
        }

        jumper.transform.position = startPos;
        goalerList.Add(jumper);
        anim.SetBool("moving", false);
        jumper.GetComponent <GoalerScript>().block = false;
        yield break;
    }
Exemple #6
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        int _layer = other.gameObject.layer;

        if (isGettingDestroyed || _layer == 19 /*iceOnly*/)
        {
            return;
        }

        if (id > 0)//Eis ist auf der Waffel
        {
            if (other.tag == "Col" || _layer == 8 || (_layer > 11 && _layer < 20))
            {
                return;                                                                   //Falls von einem anderen Eis/Waffel getroffen, dann ignoriere es: Eingehendes Eis handelt sich selbst
            }
            //Eis wird runtergeschubst:
            //Debug.Log(name + " leaving: posInCone: " + posInCone);
            if (_attribute.explosionRange > 0)
            {
                GameObject explsn = Instantiate(iceManager.explosionPrefab, transform.position, Quaternion.identity);
                explsn.transform.localScale = Vector3.one * _attribute.explosionRange * transform.localScale.x * .5f;
                explsn.GetComponent <ExplosionScript>().exclusions.Add(gameObject);
            }

            cone.blockCone();
            cone.RemoveIce(id);
            RemoveFromCone();
            StartCoroutine(PushIceOut());
            cScript.DoShake(2000);
            return;
        }
        else//Eis fliegt durch die Gegend
        {
            if (block_ice_enter || _layer == 13 || _layer == 14)
            {
                return;                                                  //ist in der nicht-berühr-Phase oder von einem Effekt betroffen
            }
            //Weder Eis noch Cone getroffen:
            if (_layer != 8 && _layer != 12)
            {
                //Hier den Code einfügen, der beschreibt, was passiert, wenn fliegendes Eis in Kontakt mit der Umgebung kommt:

                if (_attribute.reactOnImpact)
                {
                    if (_attribute.life_current > 1)
                    {
                        //Growth
                        if (_attribute.growing != 0 && Mathf.Sign(_attribute.growing) == Mathf.Sign(_attribute.endScale - transform.localScale.x))
                        {
                            _attribute.scale    += _attribute.growing * 50;
                            transform.localScale = Vector3.one * _attribute.scale;
                        }
                        //Explosion:
                        GameObject explsn = null;
                        if (_attribute.explosionRange > 0)
                        {
                            explsn = Instantiate(iceManager.explosionPrefab, transform.position, Quaternion.identity);
                            explsn.transform.localScale = Vector3.one * _attribute.explosionRange * transform.localScale.x * .5f;
                            explsn.GetComponent <ExplosionScript>().exclusions.Add(gameObject);
                        }
                        //Split:
                        if (_attribute.splitCount > 0)
                        {
                            IceScript splitIce = Instantiate(gameObject).GetComponent <IceScript>();
                            splitIce.Set_Attribute(_attribute);
                            splitIce.Get_attribute().ResetIce();
                            splitIce.Get_attribute().life_current = _attribute.life_current;
                            rb.velocity = -prevVel;

                            _attribute.life_current  = _attribute.life;
                            _attribute.reactOnImpact = false;
                            _attribute.splitCount--;
                            _attribute.scale     *= .75f;
                            _attribute.mass      *= .75f;
                            transform.localScale *= .75f;
                            rb.mass = _attribute.mass;

                            if (explsn != null)
                            {
                                explsn.GetComponent <ExplosionScript>().exclusions.Add(splitIce.gameObject);
                            }

                            Rigidbody2D split_rb = splitIce.GetComponent <Rigidbody2D>();
                            split_rb.constraints = RigidbodyConstraints2D.FreezeRotation;
                            split_rb.velocity    = prevVel;
                            iceManager.SplitIgnore(splitIce.gameObject, transform.GetChild(0).gameObject);
                        }
                    }
                }

                //Sticking on ground:
                ICone iceOrigin = GetHighestIce(this);
                if (_attribute.sticky && !_attribute.onGround)
                {
                    _attribute.onGround = true;
                    rb.constraints      = RigidbodyConstraints2D.FreezeAll;
                    OrderStickyIce(other.transform, iceOrigin);

                    /*
                     * Debug.Log(name + " hits ground");
                     * Debug.Log("pos: " + transform.position + ", calcPos: " + (other.transform.position + (Vector3)posInCone));
                     * Debug.Log("posInCone: " + posInCone);
                     * Debug.Break();
                     * //*/
                    return;
                }
                //Ground- Bounce einer Gruppe:
                if (!(_attribute.stickyParent == null || iceOrigin.Get_attribute().reflecting))
                {
                    StartCoroutine(iceOrigin.Get_attribute().SetReflectBlock());
                    iceOrigin.Get_rb().velocity *= -1;//simple reflection (pls dont kill me XP)
                }

                _attribute.life_current--;
                return;
            }

            ICone other_Ice = other.GetComponent <ICone>();
            //falls das getroffene Eis nicht auf der waffel ist:
            if (other_Ice.GetID() < 0)
            {
                //sticky:
                if (((_attribute.sticky)) &&                                             //!_attribute.onGround)) &&// || (other_Ice.Get_attribute().sticky && !other_Ice.Get_attribute().onGround)) && //Falls sticky und nicht auf Boden berührt Eis und
                    ((_attribute.stickyParent == null) ||
                     (_attribute.stickyParent != other_Ice.Get_attribute().stickyParent) //Origin ungleich other.Origin (gegen doppelkontakt)
                    ))
                {
                    //Ermittle höchstes Eis:
                    Transform myStickyParent  = transform;
                    ICone     iceOrigin       = GetHighestIce(this);
                    ICone     iceOrigin_other = GetHighestIce(other_Ice);
                    if (iceOrigin == iceOrigin_other)
                    {
                        return;                             //haben schon die gleiche Quelle
                    }
                    if (iceOrigin.Get_attribute().onGround) //Wenn die ein am Boden klebendes Eis ist, dann wird das andere eis diesem zugeordnet
                    {
                        iceOrigin_other.Get_rb().constraints = RigidbodyConstraints2D.FreezeAll;
                        OrderStickyIce(transform, iceOrigin_other);
                        StartCoroutine(Set_sticky(iceOrigin_other.Get_attribute()));
                        return;
                    }
                    //Debug.Log("origin: " + iceOrigin.Get_transform() + "\nother: " + other.transform);

                    /*
                     * //Debug.Log("sticky pre-parent: " + _attribute.stickyParent);
                     * if (_attribute.stickyParent != null)
                     * {
                     *  Debug.Log("parent: " + _attribute.stickyParent + ", parent-origin: " + _attribute.stickyParent.GetComponent<ICone>().Get_attribute().stickyParent
                     + "\nother: " + other.transform);
                     +  Debug.Log("connect: " + ((_attribute.stickyParent != other.transform) && (_attribute.stickyParent.GetComponent<ICone>().Get_attribute().stickyParent != other.transform)));
                     + }
                     + //*/
                    iceOrigin.Get_rb().constraints = RigidbodyConstraints2D.FreezeAll;
                    OrderStickyIce(other.transform, iceOrigin);

                    /*
                     * Debug.Log(name + " hits " + other.name);
                     * //Debug.Log("other: " + other.transform.position + ", self: " + transform.position + "\ndiff: " + (transform.position - _attribute.stickyParent.position) + "posInCone: " + posInCone);
                     * Debug.Log("runSim of parent: " + _attribute.stickyParent.GetComponent<ICone>().Get_attribute().runSim);
                     * Debug.Log("sticky parent " + _attribute.stickyParent + " follows " + _attribute.stickyParent.GetComponent<ICone>().Get_attribute().stickyParent);
                     * //Debug.Log("is already paired to it: " + (_attribute.stickyParent == other.transform));
                     * Debug.Break();
                     * //*/
                    StartCoroutine(Set_sticky(_attribute));
                    return;
                }
                //*
                //Bounce
                else if (!_attribute.sticky && !other_Ice.Get_attribute().sticky&& other_Ice.Get_attribute().stickyParent != null && _attribute.stickyParent == null)
                {
                    ICone iceOrigin = GetHighestIce(other_Ice);
                    if (iceOrigin.Get_attribute().onGround)
                    {
                        Vector2 diff = ((Vector2)(transform.position - other.transform.position)).normalized;
                        rb.velocity = rb.velocity.magnitude * diff;
                    }
                    else
                    {
                        Debug.Log(name + " bounced " + other.name);
                        Vector2 vel = iceOrigin.Get_rb().velocity;
                        iceOrigin.Get_rb().velocity += rb.velocity;// / iceOrigin.Get_attribute().stickyCount;
                        rb.velocity = vel;
                        //rb.velocity = (vel * iceOrigin.Get_attribute().stickyCount + rb.velocity) / (iceOrigin.Get_attribute().stickyCount + 1);
                    }
                }
                //*/
                return;
            }

            //Eis wird in den Turm integriert:
            //Update den Turm:
            rb.constraints   = RigidbodyConstraints2D.FreezeRotation;
            transform.parent = cone.transform;
            //id = other_Ice.GetID()+1;
            SetID(other_Ice.GetID() + 1);
            _attribute.ResetIce();
            _attribute.AddToCone();
            cScript.offset = new Vector2(0, ++coneIceCount * .3f);
            Camera.main.orthographicSize = cone.camSize + .3f * coneIceCount;
            cone.iceTower.Insert(id, this);
            cone.UpdateConeTower(id);
            StartCoroutine(TriggerBlink());//Damit Gruppen aufgelöst werden können
        }
    }
Exemple #7
0
    IEnumerator UpdateLife()
    {
        float timeCount;
        float timeGoal;

        while (_attribute.life_current > 0)
        {
            yield return(new WaitUntil(() => id < 0));

            while (id < 0 && _attribute.life_current > 0)
            {
                mat.SetInt("_Blink", 0);
                transform.GetChild(2).gameObject.SetActive(true);

                timeCount = 0;
                timeGoal  = _attribute.life_current * .2f;
                while (_attribute.life_current > 0 && id < 0 && (timeCount < timeGoal || _attribute.life_current > 10) && !resetUpdateLife)
                {
                    if (pauseGame)
                    {
                        yield return(new WaitWhile(() => pauseGame));
                    }

                    timeCount += Time.fixedDeltaTime;
                    _attribute.life_current -= Time.fixedDeltaTime;
                    yield return(new WaitForFixedUpdate());
                }

                mat.SetInt("_Blink", 1);
                transform.GetChild(2).gameObject.SetActive(false);

                timeCount = 0;
                timeGoal  = _attribute.life_current * .025f;
                while (_attribute.life_current > 0 && id < 0 && timeCount < timeGoal && !resetUpdateLife)
                {
                    timeCount += Time.fixedDeltaTime;
                    _attribute.life_current -= Time.fixedDeltaTime;
                    yield return(new WaitForFixedUpdate());
                }

                if (resetUpdateLife)
                {
                    resetUpdateLife = false; yield return(new WaitForSeconds(.25f)); continue;
                }

                //Reagiere nur bei Lebensabzug:
                GetComponent <Collider2D>().GetContacts(new List <Collider2D>());
                if (_attribute.reactOnImpact && _attribute.life_current > 0 && _attribute.life_current < 1 && !touchingGround)
                {
                    _attribute.life_current = .5f;
                }
                touchingGround = false;
            }

            mat.SetInt("_Blink", 0);
            transform.GetChild(1).gameObject.SetActive(true);
        }

        //Explosion:
        GameObject explsn = null;

        if (_attribute.explosionRange > 0)
        {
            explsn = Instantiate(iceManager.explosionPrefab, transform.position, Quaternion.identity);
            explsn.transform.localScale = Vector3.one * _attribute.explosionRange * transform.localScale.x;
            explsn.GetComponent <ExplosionScript>().exclusions.Add(gameObject);
        }

        //Split:
        if (_attribute.splitCount > 0)
        {
            _attribute.life_current = _attribute.life;
            _attribute.splitCount--;
            _attribute.scale     *= .75f;
            _attribute.mass      *= .75f;
            transform.localScale *= .75f;
            rb.mass = _attribute.mass;

            IceScript splitIce = Instantiate(gameObject).GetComponent <IceScript>();
            splitIce.Set_Attribute(_attribute);
            splitIce.Get_attribute().ResetIce();
            rb.velocity = -prevVel;

            if (explsn != null)
            {
                explsn.GetComponent <ExplosionScript>().exclusions.Add(splitIce.gameObject);
            }

            Rigidbody2D split_rb = splitIce.GetComponent <Rigidbody2D>();
            split_rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            split_rb.velocity    = prevVel;
            iceManager.SplitIgnore(splitIce.gameObject, transform.GetChild(0).gameObject);

            StartCoroutine(UpdateLife());
            yield break;
        }

        //Instantiiere Effekt:
        GameObject obj = Instantiate(DestroyEffect, transform.position, Quaternion.identity);

        ParticleSystem.MainModule main = obj.GetComponent <ParticleSystem>().main;
        main.startColor = _attribute.color;

        Destroy(gameObject);
        yield break;
    }