Inheritance: AbstractEntity
Esempio n. 1
0
    // Called when the Spider collides with another 2D GameObject (with a trigger)
    void OnTriggerEnter2D(Collider2D coll)
    {
        // Switch on the tag of the game object hit
        switch (coll.gameObject.tag)
        {
        case "GameplayGround":
            // Change state of this Spider to Ascending so it will
            // move back up the web
            state = SpiderState.Ascending;
            break;

        case "GameplayCeiling":
            // Change state of this Spider to Stationary so it
            // may be used again by the player
            state = SpiderState.Stationary;
            break;

        case "GoodBug":
            // Change state of this Spider to Ascending
            state = SpiderState.Ascending;

            // Handle health and score updates in the GameManager
            GameManager.instance.handleGoodBugInteraction(this.gameObject, coll.gameObject);
            break;

        case "BadBug":
            // Handle consequences in the GameManager
            GameManager.instance.handleBadBugInteraction();
            break;

        default:
            break;
        }
    }
    public override void Hit(int dmg, Vector3 hitPos, Vector3 direction)
    {
        hp -= dmg;

        print("hit! hp=" + hp);

        if (hp <= 0)
        {
            speed = 0;
            Transform.Destroy(gameObject, 5f);
            core.SetActive(false);


            animator.enabled = false;

            foreach (Rigidbody r in rbs)
            {
                r.constraints = RigidbodyConstraints.None;

                r.AddForceAtPosition(direction * 100f, hitPos, ForceMode.Impulse);
            }

            dead  = true;
            state = SpiderState.Dead;
        }
    }
Esempio n. 3
0
 void Jump()
 {
     state = SpiderState.JUMP;
     rigidbody2D.velocity = new Vector2(0, 0);
     rigidbody2D.AddForce(new Vector2(500, 6000));
     Invoke("RunUP", 2F);
 }
Esempio n. 4
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))
     {
         collision.rigidbody.AddForce(
             (-collision.transform.right + collision.transform.up) * 3f,
             ForceMode.VelocityChange);
         collision.transform.GetComponent <Player>().damage(1f);
     }
     else if (collision.transform.tag == "ShadowObject")
     {
         if (!flag)
         {
             ShadowCol = collision.collider;
             State     = EState;
             flag      = true;
         }
         EState         = SpiderState.SHADOW;
         rb.isKinematic = true;
         for (int i = 0; i < 2; i++)
         {
             col[i].isTrigger = true;
         }
     }
 }
Esempio n. 5
0
 void Lower()
 {
     transform.position = Vector3.MoveTowards(this.transform.position, newDestination, speed * Time.deltaTime);
     if (transform.position.y < newDestination.y + 0.2f)
     {
         currentState = SpiderState.IDLE;
     }
 }
Esempio n. 6
0
    public void JumpAttack()
    {
        if (state != SpiderState.IDLE)
        {

            state = SpiderState.JUMP_ATTACK;
        }
    }
Esempio n. 7
0
        private void UpdateGridView(string url, SpiderState state)
        {
            switch (state)
            {
            case SpiderState.等待中:
                _totalCount++;
                break;

            case SpiderState.准备爬取:
                break;

            case SpiderState.爬取中:
                break;

            case SpiderState.已完成:
                _completedCount++;
                break;

            case SpiderState.失败:
                _failedCount++;
                break;

            case SpiderState.取消:
                _completedCount++;
                break;

            default:
                break;
            }
            if (dataGridView2.InvokeRequired)
            {
                dataGridView2.Invoke(UpdateGrid, dataGridView2, url, state);
            }
            if (lblTotal.InvokeRequired)
            {
                lblTotal.Invoke(UpdateCount, new object[] { lblTotal, _totalCount });
            }
            if (lblLeft.InvokeRequired)
            {
                lblLeft.Invoke(UpdateCount, new object[] { lblLeft, _totalCount - _completedCount - _failedCount });
            }
            if (lblFailed.InvokeRequired)
            {
                lblFailed.Invoke(UpdateCount, new object[] { lblFailed, _failedCount });
            }
            if (lblComplete.InvokeRequired)
            {
                lblComplete.Invoke(UpdateCount, new object[] { lblComplete, _completedCount });
            }
            if (pbAll.InvokeRequired)
            {
                pbAll.Invoke(new Action <int>((t) => { pbAll.Value = t; }), new object[] { (int)((_completedCount + _failedCount) * 100 / _totalCount) });
            }
            if (lblFileCount.InvokeRequired)
            {
                lblFileCount.Invoke(new Action <int>((t) => { lblFileCount.Text = t.ToString(); }), new object[] { _downloadFileCount });
            }
        }
Esempio n. 8
0
 void Idle()
 {
     interval += Time.deltaTime;
     if(interval > idleTime)
     {
         interval = 0f;
         state = SpiderState.Move;
     }
 }
Esempio n. 9
0
 void Raise()
 {
     transform.position = Vector3.MoveTowards(this.transform.position, homeDestination, speed * Time.deltaTime);
     if (transform.position.y > homeDestination.y - 0.2f)
     {
         currentState = SpiderState.IDLE;
         trail.Clear();
     }
 }
Esempio n. 10
0
    ///===============================///
    /// FUNCTIONS FOR HANDLING STATES ///
    ///===============================///

    //In the hurt state, this enemy is flinching and won't move
    void Hurt()
    {
        hurtTimer -= Time.deltaTime;

        if (hurtTimer <= 0f)
        {
            hurtTimer   = 0f;
            spiderState = SpiderState.Pursuit;
        }
    }
Esempio n. 11
0
 public void moveSpider()
 {
     // If the Spider's state is Stationary and the game is not over:
     if (state == SpiderState.Stationary && !GameManager.gameOver)
     {
         // Signal the Spider to move downward by changing its state to Descending
         SoundManager.instance.playSpiderTouchSound();
         state = SpiderState.Descending;
     }
 }
Esempio n. 12
0
 void DropSpider()
 {
     if (!setPosition)
     {
         setPosition = true;
         float randY = Random.Range(minLower, maxLower);
         newDestination = new Vector3(this.transform.position.x, randY, -1);
         currentState   = SpiderState.LOWER;
     }
 }
Esempio n. 13
0
    //@obj: contains attack direction and attack force
    void ObjectHit(AttackInfoContainer obj)
    {
        Debug.Log("ENEMY HIT");
        healthComponent.TakeDamage(obj.damage);

        //Change state to hurt
        hurtTimer   = flinchTime;
        spiderState = SpiderState.Hurt;

        rb.AddForce(obj.direction * obj.force);
    }
Esempio n. 14
0
    void Roam()
    {
        //Check radius to see if player is within range
        float distance = Vector2.Distance(transform.position, player.transform.position);

        if (distance <= pursuitRange)
        {
            //If player is within range, switch to pursuit state
            spiderState = SpiderState.Pursuit;
        }
    }
 public void BeginAttack(Transform target)
 {
     if (state == SpiderState.Running)
     {
         remainingChargeTime = chargeTime;
         remainingAttackTime = attackTime;
         state = SpiderState.Charging;
         animator.SetBool("attack", true);
         laser.GetComponent <LaserController>().SetTarget(target);
         //laser.transform.parent.parent.LookAt(target);
         this.target = target;
     }
 }
Esempio n. 16
0
    void Dead()
    {
        if(state == SpiderState.None)
        {
            return;
        }

        ani.Play("Death");
        state = SpiderState.None;

        StartCoroutine(DeadProcess());
        //Destroy(this.gameObject);
    }
 // Update is called once per frame
 void Update()
 {
     if(spiderHP <= 0){
         resetTriggers();
         anim.SetTrigger("dieTrigger");
         Destroy(this.transform.parent.gameObject, 3);
         Destroy(this.gameObject, 3);
         state = SpiderState.dead;
         nav.Stop();
         return;
     }
     if (target && state != SpiderState.dead) {StartCoroutine(Follow());}
 }
Esempio n. 18
0
    void OnCollisionEnter(Collision other)
    {
        if(state == SpiderState.Dead || state == SpiderState.None)
        {
            return;
        }

        int layerIndex = other.gameObject.layer;

        if (layerIndex == LayerMask.NameToLayer("Ball"))
        {
            state = SpiderState.Damage;
        }
    }
Esempio n. 19
0
    /* private void OnTriggerEnter(Collider collision)
     * {
     *   if(collision.transform.tag=="ShadowObject")
     *   {
     *       if (!flag)
     *       {
     *           State = EState;
     *           flag = true;
     *       }
     *       EState = SpiderState.SHADOW;
     *       rb.isKinematic = true;
     *       for (int i = 0; i < 2; i++)
     *           col[i].isTrigger = true;
     *       Debug.Log("ShadowEnter");
     *   }
     * }*/

    private void OnTriggerExit(Collider other)
    {
        rb.isKinematic = false;
        for (int i = 0; i < 2; i++)
        {
            col[i].isTrigger = false;
        }
        if (flag)
        {
            EState = State;
            flag   = false;
        }
        Debug.Log(other.bounds.size);
    }
Esempio n. 20
0
    void Damage()
    {
        interval = 0f;

        if (--hp <= 0)
        {
            state = SpiderState.Dead;
            return;
        }

        ani.Play("Damage");
        ani.PlayQueued("Idle");
        state = SpiderState.Idle;
    }
Esempio n. 21
0
    void OnTriggerEnter2D(Collider2D other)
    {
        Vector2 jumpVector;

        if (other.gameObject.CompareTag("Player") && State != SpiderState.Returning)
        {
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            State          = SpiderState.Jump;
            timer          = 1000;
            if ((player.position.y < transform.position.y))
            {
                jumpVector = (player.position - transform.position);
                jumpVector.Scale(new Vector3(2, Behavour == SpiderBehavour.FallAndBack ? 20 : 1, 0));
                jumpVector.Normalize();
                rb.AddForce((Vector2)(jumpVector * JumpForce), ForceMode2D.Impulse);
            }
        }
    }
Esempio n. 22
0
    // Use this for initialization
    void Start()
    {
        attackInfo            = GetComponent <AttackInfoContainer> ();
        attackInfo.attackType = AttackType.MeleeWeakAttack;
        attackInfo.direction  = -transform.up.normalized;
        attackInfo.force      = baseAttackForce;

        //Get reference of player
        player = GameObject.Find("Player");
        rb     = GetComponent <Rigidbody2D> ();

        //Starting state
        spiderState     = SpiderState.Roaming;
        pState          = PursuitState.Chasing;
        waitTimer       = startWaitTime;
        projectileTimer = 0f;
        //targetSpot = Random.Range (0, moveSpots.Length);
        targetSpot = 0;         //first spot
    }
Esempio n. 23
0
    void Attack()
    {
        interval += Time.deltaTime;

        if (interval > attackTime)
        {
            interval = 0f;
            playerState.Damage();
            ani.Play("Attack");
            ani.PlayQueued("Idle");
        }

        float dist = Vector3.Distance(player.transform.position, this.transform.position);

        if(dist > attackRange)
        {
            state = SpiderState.Idle;
        }
    }
Esempio n. 24
0
    //If the player runs away from the enemy, the enemy
    //will stop pursuing and pause for a bit, searching for
    //the player and then return roaming if player not found
    void Search()
    {
        searchTimer -= Time.deltaTime;

        if (searchTimer <= 0f)
        {
            searchTimer = 0f;
            spiderState = SpiderState.Roaming;
        }

        //Check if player is within range
        float distance = Vector2.Distance(transform.position, player.transform.position);

        if (distance <= pursuitRange)
        {
            //If player is within range, switch to pursuit state
            spiderState = SpiderState.Pursuit;
            searchTimer = 0f;
        }
    }
Esempio n. 25
0
	void Awake () {
		myState = this.gameObject.GetComponent<SpiderState> ();
		agent = GetComponent<NavMeshAgent>();
		agent.updatePosition = false;
		agent.updateRotation = false;
		
		if (target == null) {
			GameObject goTarget = getPlayerGameObject ();
			if ( goTarget != null ) {
				target = goTarget.transform;
			}
		}
		
		path = new NavMeshPath ();
		/* if ( target != null ) {
			agent.CalculatePath(target.position, path);
			lastTargetPos = target.position;
		} */
		current_corner = 1;
		InvokeRepeating ("checkPath", 0, 0.25f);
	}
Esempio n. 26
0
    void Move()
    {
        float dist = Vector3.Distance(player.transform.position, this.transform.position);

        if (dist < attackRange)
        {
            interval = attackTime;
            state = SpiderState.Attack;
        }
        else
        {
            ani.Play("Run");
            Vector3 dir = player.transform.position - this.transform.position;
            dir.Normalize();
            dir.y = 0f;

            this.transform.position += dir * 5f * Time.deltaTime;

            Quaternion to = Quaternion.LookRotation(dir);
            this.transform.rotation = Quaternion.Lerp(this.transform.rotation, to, 10f * Time.deltaTime);
        }
    }
Esempio n. 27
0
    void Pursuit()
    {
        //Check radius to see if player out of range
        float distance = Vector2.Distance(transform.position, player.transform.position);

        if (distance > pursuitRange)
        {
            //Player has escaped enemy
            spiderState     = SpiderState.Searching;
            pState          = PursuitState.Chasing;    //reset
            projectileTimer = 0f;
            searchTimer     = searchTime;
            return;
        }

        //Shoot projectile
        ShootProjectile();

        //Check if we are within attacking distance and not too close to player
        if (distance <= stoppingDistance && distance >= retreatDistance)
        {
            //Stop moving for a better attack shot
            pState = PursuitState.Stopped;

            //Face the target as well
        }
        else if (distance < retreatDistance)
        {
            //If too close to player, retreat
            pState = PursuitState.Retreating;
        }
        else
        {
            //Keep chasing
            pState = PursuitState.Chasing;
        }
    }
 IEnumerator Follow()
 {
     resetTriggers ();
     switch(state){
     case SpiderState.rushing:
         resetTriggers();
         anim.SetTrigger("walkTrigger");
         nav.SetDestination(target.position);
         if(nav.remainingDistance >0 && nav.remainingDistance < 2f){
             state = SpiderState.attacking;
         }
         break;
     case SpiderState.attacking:
         transform.LookAt(target.position);
         resetTriggers();
         anim.SetTrigger("attackTrigger");
         yield return new WaitForSeconds (0.25f);
         resetTriggers();
         anim.SetTrigger("idleTrigger");
         yield return new WaitForSeconds (3f);
         state = SpiderState.rushing;
         break;
     }
 }
Esempio n. 29
0
    private bool CheckCollide()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position + transform.up * 0.65f,
                            -transform.right,
                            out hit, 0.33f,
                            LayerMask.GetMask("Stage")))
        {
            //Debug.Log("Efored" + hit.distance);
            Vector3 normal = hit.normal;

            // onPlane = Vector3.ProjectOnPlane(transform.right, normal);
            quat = Quaternion.FromToRotation(Vector3.up, normal);

            if (transform.rotation != quat)
            {
                quat.eulerAngles = AngleSet(quat.eulerAngles);
                if (hit.distance >= 0.001f)
                {
                    // Debug.Log(hit.point);
                    //quatPos = hit.point;
                    rb.MovePosition(hit.point);
                }

                EState = SpiderState.ROTATE;
                //Debug.Log("forward");
                return(true);
            }
        }

        if (!Physics.Raycast(transform.position + transform.up * 0.01f,
                             -transform.up, out hit, 0.01f))
        {
            if (Physics.Raycast(transform.position,
                                (transform.right) + (-transform.up),
                                out hit, 1.5f))
            {
                //Debug.Log(hit.distance);

                Vector3 normal = hit.normal;

                // onPlane = Vector3.ProjectOnPlane(transform.right, normal);
                quat = Quaternion.FromToRotation(Vector3.up, normal);

                if (transform.localRotation != quat)
                {
                    quat.eulerAngles = AngleSet(quat.eulerAngles);

                    if (hit.distance >= 0.001f)
                    {
                        //quatPos =  hit.point;
                        quatPos = Vector3.zero;
                        rb.MovePosition(hit.point);
                    }
                    EState = SpiderState.ROTATE;
                    //Debug.Log("down");
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 30
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            RaycastHit hit2;
            if (Physics.Raycast(transform.position + transform.up * 0.1f,
                                -transform.right, //-transform.up, //
                                out hit2, 2f))
            {
                //Debug.Log(hit2.distance);
            }
            Debug.Log(EState);
            //Debug.Log(State);
            //Debug.Log(transform.rotation + "<->" + quat);
        }

        if (EState == SpiderState.SHADOW)
        {
            if (!ShadowCol.enabled)
            {
                rb.isKinematic = false;
                for (int i = 0; i < 2; i++)
                {
                    col[i].isTrigger = false;
                }
                EState = State;
                flag   = false;
            }
        }

        if (EState == SpiderState.WALK && !CheckCollide())
        {
            rb.MovePosition(-transform.right * Time.deltaTime + transform.position);

            if (transform.position.x <= xRange[0])
            {
                quat   = Quaternion.Euler(0, 180, 0);
                EState = SpiderState.ROTATE;
            }
            else if (transform.position.x >= xRange[1])
            {
                quat   = Quaternion.Euler(0, 0, 0);
                EState = SpiderState.ROTATE;
            }
        }
        if (EState == SpiderState.ROTATE)
        {
            if (quatPos != Vector3.zero)
            {
                rb.MovePosition(quatPos);
            }

            transform.localRotation =
                Quaternion.Slerp(transform.localRotation, quat, 0.3f);

            if (transform.localRotation.eulerAngles == quat.eulerAngles)
            {
                Debug.Log("RotComplete");
                EState = SpiderState.WALK;
            }
        }
    }
Esempio n. 31
0
    void phase_control()
    {
        if (playerEntity.isAlive())
        {
            GameObject[]   enemies = GameObject.FindGameObjectsWithTag("Enemy");
            GameObject     enemy;
            AbstractEntity enemyEntity;
            if (phase == INITIAL_PHASE)
            {
                bool spidersCleared = true;
                for (int i = 0; i < enemies.Length; i++)
                {
                    enemy       = enemies[i];
                    enemyEntity = enemy.GetComponent <AbstractEntity>();
                    if (enemyEntity != null)
                    {
                        if (!enemyEntity.isAlive())
                        {
                            //enemy.GetComponent<SpiderState>().destroyWithDelay(1f);
                        }
                        else
                        {
                            spidersCleared = false;
                        }
                    }
                }
                if (spidersCleared)
                {
                    phase = TROLL_FIGHT;

                    for (int i = 0; i < enemies.Length; i++)
                    {
                        enemy       = enemies[i];
                        enemyEntity = enemy.GetComponent <AbstractEntity>();
                        if (enemyEntity != null)
                        {
                            if (!enemyEntity.isAlive())
                            {
                                enemy.GetComponent <SpiderState>().destroyObject();
                            }
                        }
                    }

                    Invoke("spawnSpiders", 2f);
                    Invoke("open_door", 2f);

                    if (trollSpawner != null)
                    {
                        Object     prefab = Resources.Load("troll", typeof(GameObject));
                        GameObject clone  = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
                        clone.transform.position = trollSpawner.position;
                        clone.GetComponent <NavMeshAgent> ().enabled = true;
                        clone.GetComponent <TrollAI> ().enabled      = true;
                    }
                }
            }
            else if (phase == TROLL_FIGHT)
            {
                SpiderState spiderstate;
                TrollState  trollstate;
                for (int i = 0; i < enemies.Length && phase == TROLL_FIGHT; i++)
                {
                    enemy       = enemies[i];
                    enemyEntity = enemy.GetComponent <AbstractEntity>();
                    if (enemyEntity != null)
                    {
                        if (!enemyEntity.isAlive())
                        {
                            spiderstate = enemy.GetComponent <SpiderState>();
                            trollstate  = enemy.GetComponent <TrollState>();
                            if (spiderstate != null)
                            {
                                spiderstate.destroyWithDelay(1.5f);
                                Invoke("spawnSpiders", 2f);
                            }
                            if (trollstate != null)
                            {
                                if (!trollstate.isAlive())
                                {
                                    phase = GAME_COMPLETE;
                                    GameObject player = GameObject.FindGameObjectWithTag("Player");
                                    Animator   a      = player.GetComponent <Animator>();
                                    a.SetBool("fanfare", true);
                                    Invoke("show_win_message", 3);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < enemies.Length; i++)
                {
                    enemy = enemies[i];
                    SpiderState spiderstate = enemy.GetComponent <SpiderState>();
                    if (spiderstate != null)
                    {
                        spiderstate.substractHealth(spiderstate.getHP());
                        spiderstate.destroyWithDelay(1f);
                    }
                }
            }
        }
        else if (phase != GAME_OVER)
        {
            phase = GAME_OVER;
        }
    }
Esempio n. 32
0
 void RaiseSpider()
 {
     currentState = SpiderState.RAISE;
     setPosition  = false;
 }
Esempio n. 33
0
	//------------------------------------------------------------------------------------------------------------------
	// incrementa o valor de detecçao
	//------------------------------------------------------------------------------------------------------------------
	void incrementDetectionCount(){
		float previousCount = playerDetectionCount;
		playerDetectionCount = Mathf.Clamp(playerDetectionCount + (playerInSight? detectionSpeed:0) + (hearing>0? hearing:0),0.0f,1.0f);
		if(playerDetectionCount >= 1){
			callHey();
			state = SpiderState.alert;
			returningDelayCount = returningDelayTime;
		}
		if(playerDetectionCount <= 0 && state != SpiderState.normal){
			heyed = false;
			callWut();
			if(--returningDelayCount <= 0){
				state = SpiderState.returning;
			}
		}

		if(previousCount != playerDetectionCount)
			setSightColor();
		else
			playerDetectionCount = Mathf.Clamp(playerDetectionCount - undetectionSpeed,0.0f,1.0f);
	}
Esempio n. 34
0
 void RunUP()
 {
     if (state == SpiderState.JUMP || state == SpiderState.WEB_ATTACK)
     {
         endWebAttack = false;
         state = SpiderState.RUN_UP;
         Invoke("WebAttack", 5F);
     }
 }
Esempio n. 35
0
 void Run()
 {
     state = SpiderState.RUN;
     webAttacks = 0;
     Invoke("Jump", 5F);
 }
Esempio n. 36
0
    void WebAttack()
    {
        if (state == SpiderState.RUN_UP && webAttacks < 3)
        {
            state = SpiderState.WEB_ATTACK;
            webAttacks++;
            rigidbody2D.velocity = new Vector2(0, 0);

            GameObject web1 = Instantiate(web, this.transform.position, Quaternion.identity) as GameObject;
            web1.GetComponent<WebSpider>().direction = 1;
            web1.GetComponent<WebSpider>().spider = this.gameObject;

            GameObject web2 = Instantiate(web, this.transform.position, Quaternion.identity) as GameObject;
            web2.GetComponent<WebSpider>().direction = 2;
            web2.GetComponent<WebSpider>().spider = this.gameObject;

            GameObject web3 = Instantiate(web, this.transform.position, Quaternion.identity) as GameObject;
            web3.GetComponent<WebSpider>().direction = 3;
            web3.GetComponent<WebSpider>().spider = this.gameObject;

            GameObject web4 = Instantiate(web, this.transform.position, Quaternion.identity) as GameObject;
            web4.GetComponent<WebSpider>().direction = 4;
            web4.GetComponent<WebSpider>().spider = this.gameObject;

            GameObject web5 = Instantiate(web, this.transform.position, Quaternion.identity) as GameObject;
            web5.GetComponent<WebSpider>().direction = 5;
            web5.GetComponent<WebSpider>().spider = this.gameObject;
            Invoke("RunUP", 2F);
        }
        else if (state == SpiderState.RUN_UP)
        {
            state = SpiderState.JUMP_ATTACK;
        }
    }
 // Use this for initialization
 void Start()
 {
     anim = GetComponent<Animator> ();
     nav = GetComponent<NavMeshAgent> ();
     state = SpiderState.rushing;
 }
Esempio n. 38
0
	//------------------------------------------------------------------------------------------------------------------
	// Instancia de alerta da aranha
	//------------------------------------------------------------------------------------------------------------------
	void returningInstance(){
		// Faz a aranha olhar para a posiçao inicial
		if(lastPlayerHeardPosition.x < initialXPosition != transform.localScale.x > 0)
			transform.localScale = new Vector3(-transform.localScale.x,transform.localScale.y,transform.localScale.z);

		if(!platformColliding){
			float increment = Mathf.Clamp(initialXPosition - lastPlayerHeardPosition.x,-speed,speed);
			transform.position += new Vector3(increment,0,0);
		}
		if(transform.position.x == initialXPosition){
			Instantiate(wut,transform.position + new Vector3(0,0.5f,0),Quaternion.identity);
			state = SpiderState.normal;
			wuted = false;
			returningDelayCount = 0;
		}
	}
Esempio n. 39
0
 // Use this for initialization
 void Start()
 {
     // Start the spider in the stationary state
     state = SpiderState.Stationary;
 }
Esempio n. 40
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 jumpVector;

        switch (State)
        {
        case SpiderState.WaitForPlayer:
            if ((transform.position.x - player.position.x <= 4) && ((transform.position.y - player.position.y) * -1 >= 6))
            {
                rb.constraints = RigidbodyConstraints2D.FreezeRotation;
                State          = SpiderState.Jump;
                timer          = 1000;
                if ((player.position.y < transform.position.y))
                {
                    jumpVector = (player.position - transform.position);
                    jumpVector.Scale(new Vector3(2, Behavour == SpiderBehavour.FallAndBack ? 20 : 1, 0));
                    jumpVector.Normalize();
                    rb.AddForce((Vector2)(jumpVector * JumpForce), ForceMode2D.Impulse);
                }
            }
            // TODO - если паук висит на потолке - то чекать дополнительно что игрок внизу в зоне досягаемости прыжка
            break;

        case SpiderState.Jump:
            timer -= Time.fixedDeltaTime;
            if (rb.velocity.y >= -0.1f)
            {
                timer = Mathf.Min(timer, 0.3f);
            }
            if (timer <= 0)
            {
                if (Behavour == SpiderBehavour.FallAndRunAway)
                {
                    if (transform.position.x > player.position.x)
                    {
                        jumpVector = new Vector3(5, 3, 0);
                    }
                    else
                    {
                        jumpVector = new Vector3(-5, 3, 0);
                    }
                    jumpVector.Normalize();
                    jumpVector = jumpVector * JumpForce * 1.5f;
                    Debug.Log(jumpVector);
                    rb.AddForce(jumpVector, ForceMode2D.Impulse);
                    State = SpiderState.RunAway;
                }
                else if (Behavour == SpiderBehavour.FallAndBack)
                {
                    rb.gravityScale = 0;
                    AudioSystem("spider_up");
                    State = SpiderState.Returning;
                }
                else
                {
                    State = SpiderState.Attack;
                }
            }
            // Ждём конца падения
            break;

        case SpiderState.Attack:
            /*if (transform.position.x < player.position.x)
             *  //transform.Translate(new Vector2(1 * Time.deltaTime * MaxSpeed, 0), Space.World);
             *  rb.velocity.Set(10 * Time.deltaTime * MaxSpeed, 0);
             * else
             *  rb.velocity.Set(-10 * Time.deltaTime * MaxSpeed, 0);
             * //transform.Translate(new Vector2(1 * Time.deltaTime * MaxSpeed, 0), Space.World);
             * //jumpVector.Normalize();
             * //jumpVector = jumpVector * JumpForce * 1.5f;
             * //rb.AddForce(jumpVector, ForceMode2D.Force);
             * //rb.velocity.Set(Mathf.Min(MaxSpeed, rb.velocity.x), rb.velocity.y);*/
            if (transform.position.x < player.position.x)
            {
                jumpVector = new Vector3(20, 1, 0);
            }
            else
            {
                jumpVector = new Vector3(-20, 1, 0);
            }
            jumpVector.Normalize();
            jumpVector = jumpVector * MaxSpeed;
            //rb.AddForce(jumpVector, ForceMode2D.Force);
            rb.velocity = new Vector2(jumpVector.x, rb.velocity.y + jumpVector.y);
            //rb.velocity.Set(Mathf.Min(MaxSpeed, rb.velocity.x), rb.velocity.y);
            break;

        case SpiderState.RunAway:
            // Уменьшаемся
            transform.localScale -= new Vector3(0.15f, 0.15f) * Time.fixedDeltaTime * Mathf.Pow((player.position - this.transform.position).magnitude / 7, 2.5f);
            // И по съёбам
            if (transform.position.x > player.position.x)
            {
                jumpVector = new Vector3(5, 1, 0);
            }
            else
            {
                jumpVector = new Vector3(-5, 1, 0);
            }
            jumpVector.Normalize();
            jumpVector = jumpVector * JumpForce * 1.5f;
            rb.AddForce(jumpVector, ForceMode2D.Force);
            rb.velocity.Set(Mathf.Min(MaxSpeed, rb.velocity.x), rb.velocity.y);
            // Если совсем мелкие - удаляемся
            if (this.transform.localScale.x < 0.05)
            {
                Destroy(gameObject);
            }
            break;

        case SpiderState.Returning:
            var backVector = (startPosition - (Vector3)transform.position);
            AudioSystem("spider_up");
            if (backVector.magnitude > ReturningSpeed * Time.fixedDeltaTime)
            {
                transform.Translate(backVector.normalized * ReturningSpeed * Time.fixedDeltaTime, Space.World);
            }
            else
            {
                transform.position = startPosition;
                rb.gravityScale    = 1;
                rb.constraints     = RigidbodyConstraints2D.FreezeAll;
                State = SpiderState.WaitForPlayer;
            }
            break;

        default:
            break;
        }
    }
Esempio n. 41
0
    void Update()
    {
        switch (state)
        {
            case SpiderState.RUN:

                if (front)
                {
                    transform.localScale = new Vector3(-startScale.x, startScale.y, startScale.z);
                    rigidbody2D.velocity = new Vector2(-10, 0);
                }
                else
                {
                    transform.localScale = new Vector3(startScale.x, startScale.y, startScale.z);
                    rigidbody2D.velocity = new Vector2(10, 0);
                }

                break;

            case SpiderState.RUN_UP:

                if (front)
                {
                    if (transform.position.x > limitLeft)
                    {
                        transform.localScale = new Vector3(-startScale.x, -startScale.y, startScale.z);
                        rigidbody2D.velocity = new Vector2(-5, 0);
                    }
                    else { front = !front; }
                }
                else if (transform.position.x < limitRight)
                {
                    transform.localScale = new Vector3(startScale.x, -startScale.y, startScale.z);
                    rigidbody2D.velocity = new Vector2(5, 0);
                }
                else { front = !front; }

                break;
            case SpiderState.WEB_ATTACK:

                // a ação esta no metodo webAttack, não é nescessário estar aqui no update pois acontece apenas uma vez

                break;
            case SpiderState.JUMP_ATTACK:

               // print("Distance: " + Vector2.Distance(new Vector2(transform.position.x, 0), new Vector2(Player.transform.position.x, 0)));

                if (this.transform.position.x > Player.transform.position.x && Vector2.Distance(new Vector2(transform.position.x, 0), new Vector2(Player.transform.position.x, 0)) > 3)
                {
                    transform.localScale = new Vector3(-startScale.x, -startScale.y, startScale.z);
                    rigidbody2D.velocity = new Vector2(-5, 0);
                }
                else if (this.transform.position.x < Player.transform.position.x && Vector2.Distance(new Vector2(transform.position.x, 0), new Vector2(Player.transform.position.x, 0)) > 3)
                {
                    transform.localScale = new Vector3(startScale.x, -startScale.y, startScale.z);
                    rigidbody2D.velocity = new Vector2(5, 0);
                }
                else if (!endWebAttack)
                {
                    state = SpiderState.IDLE;
                    endWebAttack = true;
                    rigidbody2D.isKinematic = false;
                    transform.localScale = new Vector3(transform.localScale.x, startScale.y, startScale.z);
                    Invoke("Run", 4F);
                }

                break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        Vector3 nPos = cMath.CalcPositionByDistance(curveDistance);
        Vector3 nTan = cMath.CalcTangentByDistance(curveDistance);

        transform.position = nPos;
        transform.forward  = nTan;

        if (state == SpiderState.Running)
        {
            curveDistance += speed * Time.deltaTime;
            if (curveDistance > curveTotal)
            {
                if (looping)
                {
                    curveDistance = curveDistance % curveTotal;
                }
                else
                {
                    curveDistance = curveTotal;
                }
                if (removeAtEnd)
                {
                    GameObject.Destroy(this.gameObject);
                }
            }
        }
        else if (state == SpiderState.Charging)
        {
            LaserSlerp(2f);
            remainingChargeTime -= Time.deltaTime;
            if (remainingChargeTime <= 0f)
            {
                state = SpiderState.Attacking;
            }
        }
        else if (state == SpiderState.Attacking)
        {
            LaserSlerp(1f);
            laser.SetActive(true);
            remainingAttackTime -= Time.deltaTime;
            if (remainingAttackTime <= 0f)
            {
                state = SpiderState.Uncharging;
                laser.SetActive(false);
            }
        }

        if (dead)
        {
            invisiTimer -= Time.deltaTime;
            if (invisiTimer <= 0f)
            {
                foreach (Renderer r in rbRends)
                {
                    Color c = r.material.color;
                    c.a -= Time.deltaTime * 1f;
                    r.material.color = c;
                }
            }
        }
    }