Exemplo n.º 1
0
    public void Init(LinkedListNode <GameObject> cube, scrNode parent, Vector3 position, DataState state)
    {
        transform.position = position;
        transform.rotation = Quaternion.identity;
        Parent             = parent;
        Cube = cube;

        StatePrev = state;
        State     = state;
        if (State == DataState.INFECTED)
        {
            infectionTransitionCompleted = true;
            renderer.material            = scrNodeMaster.Instance.MatCubeInfected;
        }
        else
        {
            infectionTransitionCompleted = false;
            infectionTransitionTimer     = 0.0f;

            if (State == DataState.BLOCKED)
            {
                renderer.material = scrNodeMaster.Instance.MatCubeBlocked;
            }
            else
            {
                renderer.material = scrNodeMaster.Instance.MatCubeUninfected;
            }
        }

        damageTimer = 0;
        Uploading   = false;
        pathfinder.Pause();
    }
Exemplo n.º 2
0
    // Update is called once per frame
    protected override void Update()
    {
        if (Expired)
        {
            // Destroy segments.
            if (ExplosionPrefab != null)
            {
                for (int i = 0; i < Segments.Length; ++i)
                {
                    GameObject explosion = (GameObject)Instantiate(ExplosionPrefab, Segments[i].transform.position, Quaternion.identity);
                    explosion.particleSystem.startColor = Color.Lerp(Segments[i].renderer.material.color, Color.white, 0.5f);
                    Destroy(Segments[i].gameObject);
                }
            }

            // NOW destroy self.
            Destroy(gameObject);
            return;
        }

        if (Vector2.Distance(transform.position, scrPlayer.Instance.transform.position) < 50 && !Physics.Linecast(transform.position, scrPlayer.Instance.transform.position, 1 << LayerMask.NameToLayer("Node")))
        {
            pathfinder.Pause();
            Vector3 direction = Vector3.Lerp((transform.position - (Vector3)prevPositions[0]).normalized, (scrPlayer.Instance.transform.position - transform.position).normalized, 0.3f).normalized *Time.deltaTime *Speed;
            transform.position += direction;

            fireTimer += Time.deltaTime * fireRate;
            if (fireTimer >= 1)
            {
                fireTimer = 0;

                scrEnemyMaster.BulletPool.Create(new BulletPowerup(scrNodeMaster.ColCoreInfected, 80, 1, 0, 0, 0, false, false), transform.position, direction.normalized, false, true);
                audio.PlayOneShot(FireSound);
            }
        }
        else
        {
            pathfinder.Resume();
        }

        // Shift segments scaled by the velocity, which is worked out by the translation of the head since the last update. Deltatime is not needed because the translation is already dependant on it..
        spacingTimer    += 0.05f * Vector2.Distance((Vector2)transform.position, prevHeadPosition);
        prevHeadPosition = transform.position;

        if (spacingTimer >= spacingDelay)
        {
            spacingTimer     = 0;
            prevPositions[0] = nextPositions[0];
            nextPositions[0] = transform.position;
            for (int i = 1; i < Segments.Length; ++i)
            {
                prevPositions[i] = nextPositions[i];
                nextPositions[i] = prevPositions[i - 1];
            }
        }

        bool allExpired = true;

        for (int i = 0; i < Segments.Length; ++i)
        {
            if (Segments[i] == null)
            {
                continue;
            }

            // If the segment has expired, disable its enemy script, hide its children and show its "dead" skeleton child.
            if (Segments[i].Expired)
            {
                if (Segments[i].enabled)
                {
                    Segments[i].renderer.material.color = Color.black;
                    Segments[i].transform.localScale   *= 0.5f;
                    Segments[i].collider2D.enabled      = false;
                    Segments[i].enabled = false;
                    Segments[i].GetComponentInChildren <TextMesh>().text = "";
                }
            }
            else
            {
                allExpired = false;
            }

            Vector2 direction = nextPositions[i] - prevPositions[i];
            Segments[i].transform.rotation = Quaternion.RotateTowards(Segments[i].transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime);
            Segments[i].transform.position = Vector2.Lerp(prevPositions[i], nextPositions[i], spacingTimer / spacingDelay);
        }

        // If all segments are gone, destroy self.
        if (allExpired)
        {
            damageTimer = DamageToDestroy;
        }

        base.Update();
    }
Exemplo n.º 3
0
    // Update is called once per frame
    protected override void Update()
    {
        if (transform.localScale.x == 0.0f)
        {
            return;
        }

        if (startAngle != 0.0f || Vector3.Distance(transform.position, pathfinder.Target.transform.position) <= 50.0f)
        {
            // Initialisation of orbit.
            if (startAngle == 0.0f)
            {
                Vector3 direction = pathfinder.Target.transform.position - transform.position;
                startAngle = Mathf.Atan2(-direction.y, direction.x) - Mathf.PI * 0.5f;
            }

            pathfinder.Pause();
            transform.position = pathfinder.Target.transform.position + new Vector3(50.0f * Mathf.Sin(startAngle + orbitTimer * Mathf.PI * 2), 50.0f * Mathf.Cos(startAngle + orbitTimer * Mathf.PI * 2), 0.0f);
            orbitTimer        += Time.deltaTime * rotateSpeed * 0.001f;


            if (ChildCore.transform.localScale.x > 0.0f)
            {
                ChildCore.transform.localScale = Vector3.one * (ChildCore.transform.localScale.x - Time.deltaTime / transform.localScale.x * 0.05f);
                scrAICore.Instance.Learn(true, Time.deltaTime / transform.localScale.x);

                if (ChildCore.transform.localScale.x <= 0.0f)
                {
                    ChildCore.transform.localScale = Vector3.zero;
                    link.SetVertexCount(0);
                }
                else
                {
                    // Create a curved link like the nodes.
                    float   curve   = 20.0f;
                    Vector3 control = Vector3.Lerp(transform.position, pathfinder.Target.transform.position, 0.5f) - curve * Vector3.back;
                    for (int i = 0; i < 5; ++i)
                    {
                        float t    = (float)i / (5 - 1);
                        float tInv = 1.0f - t;
                        link.SetPosition(i, tInv * tInv * transform.position + 2 * tInv * t * control + t * t * pathfinder.Target.transform.position);
                    }

                    link.SetColors(Color.Lerp(Color.clear, Color.red, Mathf.Abs(orbitTimer) / 0.05f), Color.Lerp(Color.clear, Color.red, Mathf.Abs(orbitTimer) / 0.2f));
                }
            }
        }
        else
        {
            pathfinder.Resume();
        }

        // Rotate the shell.
        ChildShell.transform.Rotate(0.0f, rotateSpeed * Time.deltaTime, 0.0f);

        if (Vector2.Distance(transform.position, scrPlayer.Instance.transform.position) < 70)
        {
            fireTimer += Time.deltaTime * fireRate;
            if (fireTimer > 1.0f)
            {
                fireTimer = 0.0f;
                Vector3 position = ChildShell.transform.TransformPoint(0.5f * new Vector3(Mathf.Sin(fireCannon / 8.0f * Mathf.PI * 2),
                                                                                          0.0f, Mathf.Cos(fireCannon / 8.0f * Mathf.PI * 2)));
                scrEnemyMaster.BulletPool.Create(new BulletPowerup(Color.red, 40.0f, 10.0f * transform.localScale.x, 0, 0, 0, false, true),
                                                 position, (position - transform.position).normalized, false, true);
                ++fireCannon;
                if (fireCannon == 8)
                {
                    fireCannon = 0;
                }
            }
        }

        base.Update();
    }