Esempio n. 1
0
    // IEnumerator for invoking a function with parameters
    IEnumerator EndParaylzeIE(Transform trans, float delay)
    {
        yield return(new WaitForSeconds(delay));

        // previous state has been memorized above
        virusState = previousState;
    }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (currentState == VirusState.JUMPING)
        {
            bool isWindow = collision.gameObject.tag == WindowTags.TAG1 ||
                            collision.gameObject.tag == WindowTags.TAG2;

            GameObject collParent = collision.transform.parent == null ? collision.gameObject : collision.transform.parent.gameObject;

            if (isWindow && (lastHeldWindow == null || !lastHeldWindow.Equals(collParent)))
            {
                currentState = VirusState.HOLDINGWINDOW;

                lastHeldWindow = collParent;

                collParent.GetComponent <Window>().AttributeActive = false;

                dir = Vector2.zero;
                transform.position = collision.gameObject.transform.position;
                transform.parent   = collParent.transform;

                holdingLegsObject = Instantiate(holdingLegsPrefab, collision.transform.position, Quaternion.identity);
                holdingLegsObject.transform.parent = collision.gameObject.transform;
            }
        }
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        ct = GetComponent <ChaseTarget> ();
        cs = GetComponent <ControlStatus> ();
        hd = GetComponent <HurtAndDamage> ();

        if (ct)
        {
            defaultRotSpeed  = ct.rotationSpeed;
            defaultMoveSpeed = ct.moveSpeed;
        }

        virusState    = VirusState.Idle;
        previousState = VirusState.Idle;

        ResetActions();
        if (OnIdleStart != null)
        {
            OnIdleStart(this.transform);
        }

        paralyzeTime = 5f;

        tp  = GetComponent <VirusTargetPicker> ();
        vpm = transform.parent.GetComponent <VirusPosManager> ();

        if (cs)
        {
            cs.OnCutByEnemy  += StopStateControl;
            cs.OnCutByPlayer += StopStateControl;

            cs.OnLinkedByEnemy  += StartStateControl;
            cs.OnLinkedByPlayer += StartStateControl;
        }
    }
Esempio n. 4
0
    new void Start()
    {
        base.Start();

        attackPower   = 20;
        movementSpeed = 10;

        landingShake = 0.5f;

        idleTime  = 3;
        arrowTime = 1;

        rigidbody.gravityScale = 0;

        GetComponent <BoxCollider2D>().isTrigger = true;

        // Scriptet sitter på censored enemy
        if (GetComponent <Animator>() == null)
        {
            arrowPrefab       = GetComponent <CensoredEnemy>().virusArrowPrefab;
            holdingLegsPrefab = GetComponent <CensoredEnemy>().virusHoldingLegsPrefab;
        }
        else
        {
            animator = GetComponent <Animator>();
        }

        currentState = VirusState.JUMPING;
        FindBestWindow();
    }
Esempio n. 5
0
        public VirusState DoBurst()
        {
            var        key   = CurrentNode.Now();
            VirusState state = VirusState.Clean;

            if (!Blocks.ContainsKey(key))
            {
                // no block node, so add it and infect it
                Blocks.Add(key, VirusState.Infected);
                CurrentNode.TurnLeft();
                CurrentNode.MoveForward();
                InfectionBursts++;
            }
            else
            {
                state = Blocks[key];
                if (state == VirusState.Infected)
                {
                    Blocks[key] = VirusState.Clean;
                    CurrentNode.TurnRight();
                    CurrentNode.MoveForward();
                }
                else
                {
                    Blocks[key] = VirusState.Infected;
                    CurrentNode.TurnLeft();
                    CurrentNode.MoveForward();
                    InfectionBursts++;
                }
            }
            return(state);
        }
Esempio n. 6
0
 public void StartParalyze(Transform virusTrans)
 {
     // first stop this object
     StopChase(this.transform);
     StopPosReceiver(this.transform);
     // memorize the previous state
     previousState = virusState;
     // then start this object after a given amont of time
     StartCoroutine(EndParaylzeIE(this.transform, paralyzeTime));
 }
Esempio n. 7
0
        public VirusState DoBurst2()
        {
            var        key   = CurrentNode.Now();
            VirusState state = VirusState.Clean;

            if (!Blocks.ContainsKey(key))
            {
                // no block node, so add it
                Blocks.Add(key, VirusState.Clean);
            }
            state = Blocks[key];
            switch (state)
            {
            case VirusState.Clean:
                Blocks[key] = VirusState.Weakened;
                CurrentNode.TurnLeft();
                break;

            case VirusState.Weakened:
                Blocks[key] = VirusState.Infected;
                // no turning
                InfectionBursts++;
                break;

            case VirusState.Infected:
                Blocks[key] = VirusState.Flagged;
                CurrentNode.TurnRight();
                break;

            case VirusState.Flagged:
                Blocks[key] = VirusState.Clean;
                CurrentNode.Reverse();
                break;

            default:
                break;
            }
            CurrentNode.MoveForward();
            return(state);
        }
Esempio n. 8
0
        public void ParseData(string path)
        {
            var rows = DataTools.ReadAllLines(path);

            DimY = rows.Length;
            DimX = rows[0].Length;

            for (int y = 0; y < DimY; y++)
            {
                var chars = rows[y].ToCharArray();
                for (int x = 0; x < DimX; x++)
                {
                    Tuple <int, int> key      = new Tuple <int, int>(x, y);
                    VirusState       infected = chars[x] == '#' ? VirusState.Infected : VirusState.Clean;
                    Blocks.Add(key, infected);
                }
            }
            CurrentNode           = new Position();
            CurrentNode.X         = DimX / 2;
            CurrentNode.Y         = DimY / 2;
            CurrentNode.Direction = Direction.Up;
            InfectionBursts       = 0;
        }
Esempio n. 9
0
 public void StartStateControl(Transform virusTrans)
 {
     this.enabled = true;
     // default behaviour is to set status as return
     virusState = VirusState.Return;
 }
Esempio n. 10
0
    // logic for switching states
    void Update()
    {
        //ObjectIdentity oi = transform.parent.GetComponent<ObjectIdentity> ();


        //if (oi == null)
        //return;
        switch (cs.controller)
        {
        case Controller.Boss:
            // state switch logic for Boss
            vpm = transform.parent.GetComponent <VirusPosManager> ();
            switch (virusState)
            {
            case VirusState.Idle:
            {
                Transform newTarget = tp.PickTarget();
                if (newTarget != null)
                {
                    // we found a new target here, set the target to the new target
                    // and change the state
                    //					Debug.Log ("leaving idle, entering chase");
                    tp.SetNewTarget(newTarget);
                    // entering the chase state
                    virusState = VirusState.Chase;
                }
                break;
            }

            case VirusState.Chase:
            {
                Transform newTarget = tp.PickTarget();
                float     dist      =
                    Vector3.Distance(transform.position, transform.parent.position);

                //if (dist > maxControlDistance) {
                if (newTarget == null || dist > maxControlDistance)
                {
                    // lost the target OR reaching the distance boundary
                    if (dist <= vpm.spreadRadius * 1.2f)
                    {
                        virusState = VirusState.Idle;
                    }
                    else
                    {
                        virusState = VirusState.Return;
                    }
                }
                else
                {
                    // update target
                    tp.SetNewTarget(newTarget);
                }
                break;
            }

            case VirusState.Return:
            {
                Transform newTarget = tp.PickTarget();
                if (newTarget != null)
                {
//						Debug.Log ("leaving return, entering chase");
                    // found new target
                    tp.SetNewTarget(newTarget);
                    // entering the chase state
                    virusState = VirusState.Chase;
                }
                else
                {
                    // set chase target to parent
                    tp.SetParentAsTarget();
                    float dist =
                        Vector3.Distance(transform.position, transform.parent.position);
                    if (dist <= vpm.spreadRadius)
                    {
                        // reached parent object, switch to idle
                        virusState = VirusState.Idle;
                    }
                }
                break;
            }

            default:
                break;
            }
            break;



        case Controller.Hacker:
            // state switch logic for hacker
            switch (virusState)
            {
            case VirusState.Return:
            {
                StopPosReceiver(this.transform);
                tp.SetParentAsTarget();
                float dist =
                    Vector3.Distance(transform.position, transform.parent.position);
                if (dist <= vpm.spreadRadius)
                {
                    // reached parent object, switch to idle
                    virusState = VirusState.Idle;
                }
                break;
            }

            case VirusState.Idle:
            {
                // if the player presses the buttom, release this virus
                // state switch from Idle to Chase is managed in Hacker's script

                break;
            }

            case VirusState.Chase:
            {
                Transform newTarget = tp.PickTarget();
                float     dist      =
                    Vector3.Distance(transform.position, releasePos);
                tp.SetNewTarget(newTarget);
                if (dist > maxControlDistance)
                {
                    HealthSystem hs = GetComponent <HealthSystem> ();
                    if (hs)
                    {
                        hs.InstantDead();
                    }
                }

                break;
            }
            }
            break;

        case Controller.None: {
            StopChase(this.transform);
            break;
        }

        default:
            Debug.LogError("parent obj type must be hacker of boss");
            break;
        }
    }
Esempio n. 11
0
    new void Update()
    {
        // Direction vector
        InsideScreen();
        dir.x = direction * Mathf.Abs(dir.x);

        // Animation
        if (animator != null)
        {
            animator.SetBool("isJumping", currentState == VirusState.JUMPING);
        }

        // Timer
        if (currentState != VirusState.JUMPING)
        {
            stateTimer += Time.deltaTime;
        }

        switch (currentState)
        {
        case VirusState.JUMPING:

            rigidbody.MovePosition(transform.position + (Vector3)dir * movementSpeed * Time.deltaTime);

            break;

        case VirusState.HOLDINGWINDOW:

            if (stateTimer >= idleTime && CanFindNewWindow())
            {
                stateTimer = 0;

                currentState = VirusState.SHOWINGDIRECTION;

                FindBestWindow();

                arrowObject = Instantiate(arrowPrefab, gameObject.transform.position, Quaternion.identity);
                arrowObject.transform.parent      = gameObject.transform;
                arrowObject.transform.eulerAngles = new Vector3(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
            }

            break;

        case VirusState.SHOWINGDIRECTION:

            if (stateTimer >= arrowTime)
            {
                stateTimer = 0;

                currentState = VirusState.JUMPING;

                transform.parent.GetComponent <Window>().AttributeActive = true;

                transform.parent = null;

                Destroy(arrowObject);
                Destroy(holdingLegsObject);
            }

            break;
        }
    }
Esempio n. 12
0
 public void Init()
 {
     state = new VirusStateBirth(this, new Vector3(0,0,0));
 }
Esempio n. 13
0
 public void SetState(VirusState state)
 {
     this.state = state;
 }