예제 #1
0
    // Update is called once per frame
    void Update()
    {
        //Spieler-Input:
        if (block)
        {
            return;
        }

        //Reset Level:
        if (Input.GetKey(KeyCode.R))
        {
            RestartLevel();
        }
        //Reset Checkpoint:
        if ((Input.GetKey(KeyCode.C) && CheckpointScript.current) || Math.Abs(transform.position.x) > 40 || Mathf.Abs(transform.position.y) > 27)
        {
            CheckpointScript.current.ReloadCheckpoint();
        }
        //Schummeln:
        if (Input.GetKey(KeyCode.P) && CheckpointScript.current)
        {
            CheckpointScript.current.StartSchummeln(transform.position);
        }
        //Arbeit frühzeitig abgeben:
        if (Input.GetKey(KeyCode.B))
        {
            cScript.EndTheGame();
        }

        gScript.ExecuteInput(Input.GetKey(KeyCode.A), Input.GetKey(KeyCode.D), Input.GetKey(KeyCode.W), gScript.properties);
    }
예제 #2
0
    IEnumerator RunSchummelScript(int ptr)
    {
        Debug.Log("Starte SchummelScript");
        int        steps = 30;
        Color      stepColor;
        GameObject obj;

        SchummelScript.SchummelEvent sEvent;
        GroupScript gScript = allies[0].GetComponent <GroupScript>();

        while (ptr < sEvents.Count)
        {
            sEvent = sEvents[ptr];

            gScript.rb.bodyType = RigidbodyType2D.Static;
            if (ptr > 0)
            {
                if (sScript.events[ptr].eventType != SchummelScript.EventType.add &&
                    sScript.events[ptr].eventType != SchummelScript.EventType.move)
                {
                    gScript.rb.velocity = Vector2.zero;
                }
            }

            //Warte auf Trigger:
            switch (sEvent.trigger)
            {
            case SchummelScript.TriggerType.none:

                break;

            case SchummelScript.TriggerType.time:
                if (sEvent.triggerTime > 0)
                {
                    yield return(new WaitForSeconds(sEvent.triggerTime));
                }
                break;
            }
            if (stop)
            {
                yield break;
            }


            //Ausführung der Aktion:
            MovementScript mScript;
            bool           goRight, changeObj;
            int            arrayPos;
            Debug.Log("active Event: " + sEvent.title);
            switch (sEvent.eventType)
            {
            case SchummelScript.EventType.spawn:
                //spawne ein SpielObjekt in der Geisterwelt:
                Debug.Log("Spawn Object");
                obj       = Resources.Load <GameObject>("Prefabs/Objects/" + sEvent.focus[0]);
                obj       = Instantiate(obj, sEvent.endPosition, Quaternion.identity);
                obj.layer = 19;    //Geisterobjekt
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0);
                activeObjects.Add(obj);
                Debug.Log(obj);

                StartCoroutine(FadeIn(obj));
                yield return(new WaitForSeconds(3));

                break;



            case SchummelScript.EventType.despawn:
                //despawne ein Objekt in der Geisterwelt
                if (!int.TryParse(sEvent.focus[0], out arrayPos))
                {
                    break;
                }
                obj = activeObjects[arrayPos];

                steps     = 30;
                stepColor = new Color(0, 0, 0, -0.01f);
                for (int i = 0; i < steps; i++)
                {
                    obj.GetComponent <SpriteRenderer>().color += stepColor;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }
                activeObjects.RemoveAt(arrayPos);
                Destroy(obj);
                break;



            case SchummelScript.EventType.wait:
                //Warte auf Event (noch nicht implementiert)

                break;



            case SchummelScript.EventType.add:
                //füge Einheit zur Gruppe hinzu, wie move, bloß mit gespawnter Einheit

                //spawne Einheit:
                obj = Resources.Load <GameObject>("Units/" + sEvent.focus[0]);
                obj = Instantiate(obj, sEvent.endPosition, Quaternion.identity);
                obj.transform.GetChild(2).gameObject.layer = 17;    //Ghost-Layer für Trigger
                allies.Add(obj);
                alliesNames.Add(obj.GetComponent <SpriteRenderer>().sprite.name);
                obj.tag   = "Ghost";
                obj.layer = 18;                                                    //mainGhost, bleibt auf Boden stehen
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); //unsichtbar
                StartCoroutine(FadeIn(obj));

                //move zur Einheit:
                gScript.rb.bodyType = RigidbodyType2D.Dynamic;
                goRight             = (sEvent.endPosition - (Vector2)gScript.transform.position).x > 0;
                while (((sEvent.endPosition - (Vector2)gScript.transform.position).x > 0) == goRight)
                {
                    gScript.ExecuteInput(!goRight, goRight, false, gScript.properties);
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Einheit hinzufügen:
                obj.GetComponent <GroupScript>().charToFollow = allies[allies.Count - 2];
                obj.GetComponent <GroupScript>().inGroup      = true;
                obj.layer = 17;    //Ghost
                break;



            case SchummelScript.EventType.combine:
                //vereinige Einheiten zu einer neuen Einheit

                //Einheiten die vereinigt werden sollen springen hoch, treffen sich in der Luft und werden gelöscht:
                int   count  = 0;
                float number = sEvent.focus.Length;
                foreach (string unitName in sEvent.focus)
                {
                    if (count++ == 0)
                    {
                        continue;
                    }

                    StartCoroutine(Merge(alliesNames.IndexOf(unitName), sEvent.endPosition, (count / number - 0.5f) * 3));
                }
                yield return(new WaitForSeconds(2f));

                if (stop)
                {
                    yield break;
                }

                //spawne Einheit:
                obj = Resources.Load <GameObject>("Units/" + sEvent.focus[0]);
                obj = Instantiate(obj, sEvent.endPosition + Vector2.up, Quaternion.identity);
                obj.transform.GetChild(2).gameObject.layer = 17;    //Ghost-Layer für Trigger
                allies.Add(obj);
                alliesNames.Add(obj.GetComponent <SpriteRenderer>().sprite.name);
                obj.tag   = "Ghost";
                obj.layer = 17;                                                    //Ghost
                obj.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); //unsichtbar
                obj.GetComponent <GroupScript>().enabled  = false;

                //Erscheinen:
                steps     = 30;
                stepColor = new Color(0, 0, 0, 0.01f);
                for (int i = 0; i < steps; i++)
                {
                    obj.GetComponent <SpriteRenderer>().color += stepColor;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Auf Boden Gleiten
                steps = 30;
                Vector3 stepPos = ((Vector3)sEvent.endPosition - obj.transform.position) / steps;
                for (int i = 0; i < steps; i++)
                {
                    obj.transform.position += stepPos;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Einheit hinzufügen:
                obj.GetComponent <GroupScript>().enabled      = true;
                obj.GetComponent <GroupScript>().charToFollow = allies[allies.Count - 2];
                obj.GetComponent <GroupScript>().inGroup      = true;
                break;



            case SchummelScript.EventType.move:
                //bewege Einheiten (ohne zu springen)
                gScript.rb.bodyType = RigidbodyType2D.Dynamic;
                goRight             = (sEvent.endPosition - (Vector2)allies[0].transform.position).x > 0;
                while (((sEvent.endPosition - (Vector2)allies[0].transform.position).x > 0) == goRight)
                {
                    Debug.Log("moving");
                    gScript.ExecuteInput(!goRight, goRight, false, gScript.properties);
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }
                break;



            case SchummelScript.EventType.jump:
                //bewege Einheiten mit Springanimation über eine Dauer von ValueSet

                if (!gScript)
                {
                    yield break;
                }
                gScript.enabled = false;    //gScript updates squish (scale) -> deactivation

                steps = 30;
                Vector3 realPos   = gScript.transform.position;
                Vector3 realScale = Vector2.one * gScript.properties.size;
                Vector3 posStep   = (sEvent.endPosition - (Vector2)gScript.transform.position) / sEvent.valueSet;
                Vector3 angleStep = -gScript.transform.eulerAngles / steps;

                float b = -steps / 2f;
                float a = -8f / (steps * steps);
                float factor;

                for (int i = 0; i <= steps; i++)
                {
                    realPos += posStep;

                    factor = a * (i + b) * (i + b) + 2;
                    gScript.transform.position     = realPos + Vector3.up * factor;
                    gScript.transform.localScale   = realScale + (Vector3) new Vector2(-0.1f, 0.05f) * factor;
                    gScript.transform.eulerAngles += angleStep;

                    gScript.UpdatePastPos();
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                gScript.enabled = true;
                break;



            case SchummelScript.EventType.set_Mass:
                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                mScript.rb.mass = sEvent.valueSet;
                break;



            case SchummelScript.EventType.set_Size:

                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                float diff = sEvent.valueSet - obj.transform.localScale.x;
                obj.transform.localScale = Vector2.one * sEvent.valueSet;
                mScript.properties.size  = obj.transform.localScale.x;

                obj.transform.position += Vector3.up * diff / 2;
                break;



            case SchummelScript.EventType.change_mass:

                break;



            case SchummelScript.EventType.change_size:

                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                bool add = sEvent.valueSet > gScript.properties.size;
                while (Mathf.Abs(sEvent.valueSet - mScript.properties.size) > 0.15f)
                {
                    //Debug.Log(Mathf.Abs(sEvent.valueSet - gScript.properties.size));
                    yield return(new WaitForSeconds(0.5f));

                    if (stop)
                    {
                        yield break;
                    }

                    obj = activeObjects[arrayPos];
                    obj.transform.localScale += (Vector3)Vector2.one * (add ? 0.1f : -0.1f);
                    obj.GetComponent <ObjectScript>().properties.size = obj.transform.localScale.x;

                    obj.transform.position += Vector3.up * (add ? 0.05f : -0.05f);
                }
                yield return(new WaitForSeconds(0.5f));

                break;


            case SchummelScript.EventType.change_vel:

                break;


            case SchummelScript.EventType.change_puls:

                break;


            case SchummelScript.EventType.change_force:

                break;


            case SchummelScript.EventType.change_energy:

                break;
            }

            ptr++;
        }

        //despawne Einheiten
        steps     = 100;
        stepColor = new Color(0, 0, 0, -0.01f);
        for (int i = 0; i < steps; i++)
        {
            foreach (GameObject unit in allies)
            {
                unit.GetComponent <SpriteRenderer>().color += stepColor;
            }
            yield return(new WaitForEndOfFrame());

            if (stop)
            {
                yield break;
            }
        }
        foreach (GameObject unit in allies)
        {
            Destroy(unit);
        }
        foreach (GameObject active_obj in activeObjects)
        {
            Destroy(active_obj);
        }
        stop = true;
        GetComponent <CoreScript>().SetPeeking(false);
        yield break;
    }