Ejemplo n.º 1
0
 public void RandomOrder()                                                     //随机行动
 {
     g_lastOrderTime = Time.time;                                              //更新最后一次行动时间设置
     g_Weightnumber  = Random.Range(0, g_actionWeight[0] + g_actionWeight[1]); //行动权重
     //行为1:此处为待机
     if (g_Weightnumber < g_actionWeight[0] && g_health > 0)
     {
         g_currentState = g_State.IDLE;
         g_animator.SetInteger(g_name + "_State", 0);
     }
     //行为2:此处为漫步
     else if (g_Weightnumber < g_actionWeight[1] && g_Weightnumber > g_actionWeight[0] && g_health > 0)
     {
         g_currentState = g_State.WALK;
         g_animator.SetInteger(g_name + "_State", 1);
         g_randomMove = new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f));
         if (g_randomMove.x > 0)
         {
             GetComponent <SpriteRenderer>().flipX = false;
             g_faceDirection = 1;
         }
         else
         {
             GetComponent <SpriteRenderer>().flipX = true;
             g_faceDirection = -1;
         }
         g_randomMove.Normalize();
     }
 }
Ejemplo n.º 2
0
 public void EnemydistanceCheck()//距离检测
 {
     //更新和玩家的位置
     g_distanceToPlayer   = Vector2.Distance(PlayerLocation.position, thisLocation.position);
     g_distanceToPlayer_Y = Mathf.Abs(PlayerLocation.position.y - thisLocation.position.y);
     //判断是否进入攻击状态
     if (g_distanceToPlayer <= g_AttackRange && g_distanceToPlayer_Y <= g_AttackRange_Y && g_health > 0)
     {
         //Debug.Log("attack");
         if (PlayerLocation.position.x - thisLocation.position.x > 0 && !g_inAttack)
         {
             GetComponent <SpriteRenderer>().flipX = false;
             g_faceDirection = 1;
         }
         else if (PlayerLocation.position.x - thisLocation.position.x <= 0 && !g_inAttack)
         {
             GetComponent <SpriteRenderer>().flipX = true;
             g_faceDirection = -1;
         }
         g_lastAttackTime = Time.time;
         g_animator.SetInteger(g_name + "_State", 0);
         g_animator.SetTrigger(g_name + "_Attack");
         g_currentState = g_State.ATTACK;
         g_chase        = false;
         g_inAttack     = true;
     }
     //判断是否进入追逐状态
     else if (g_health > 0 && (g_distanceToPlayer <= g_WarningRange && g_distanceToPlayer > g_AttackRange) || (g_distanceToPlayer <= g_AttackRange && g_distanceToPlayer_Y > g_AttackRange_Y))
     {
         g_animator.SetInteger(g_name + "_State", 1);
         g_currentState = g_State.CHASE;
         g_chase        = true;
         g_inAttack     = false;
     }
     //判断是否远离警戒范围
     else if (g_health > 0 && g_distanceToPlayer > g_WarningRange && (g_currentState == g_State.CHASE || g_currentState == g_State.ATTACK))
     {
         g_animator.SetInteger(g_name + "_State", 0);
         g_currentState = g_State.IDLE;
         g_chase        = false;
         g_inAttack     = false;
     }
 }
Ejemplo n.º 3
0
    //受击判定
    public void beHited(int atk, int face)
    {
        //Debug.Log(g_name+"被打了");

        if (g_currentState != g_State.DEATH && g_hittime == 0 && g_health > 0)
        {
            if (Globel.Case30)//随机伤害 遗物效果
            {
                atk = Random.Range(0, 60);
            }
            if (Globel.Case31)//根据护盾增加伤害 遗物效果
            {
                atk += (Globel.Arrmo * 10 / 400);
            }
            if (Globel.Case34)//根据血量增加伤害 遗物效果
            {
                atk = (int)((float)atk * ((1f + ((float)(Globel.MAXHP) - (float)(Globel.HP)) / (float)(Globel.MAXHP)) * 0.9f + 0.1f));
            }
            //暴击检测---------------------
            g_luckHit   = false;
            g_luckCheck = Random.Range(0, 101);
            if (Globel.Luck > g_luckCheck)
            {
                g_luckHit = true;
            }
            //-----------------------------
            SoundManager.PlayG_hurt();
            g_hittime = 5;
            if (face == 0)
            {
                face = -g_faceDirection; //被弓箭击中
            }
            if (Globel.Case8)            //击中回血 遗物效果
            {
                Globel.HP += 2;
                GameObject gb = Instantiate(floatPoint_G, PlayerLocation.position, Quaternion.identity) as GameObject;
                gb.transform.GetChild(0).GetComponent <TextMesh>().text = "2";
            }
            if (Globel.Case38 && g_luckHit)//暴击回血 遗物效果
            {
                Globel.HP += 15;
                GameObject gb = Instantiate(floatPoint_G, PlayerLocation.position, Quaternion.identity) as GameObject;
                gb.transform.GetChild(0).GetComponent <TextMesh>().text = "15!";
            }

            if (g_luckHit == false)
            {
                GameObject gb = Instantiate(floatPoint, transform.position, Quaternion.identity) as GameObject;
                gb.transform.GetChild(0).GetComponent <TextMesh>().text = atk.ToString();
                g_health -= atk;
            }
            else
            {
                atk *= 2;
                GameObject gb = Instantiate(floatPoint_O, transform.position, Quaternion.identity) as GameObject;
                gb.transform.GetChild(0).GetComponent <TextMesh>().text = atk.ToString();
                g_health -= atk;
            }
            if (g_hard == false && g_health > 0)//怪物是否霸体
            {
                g_animator.SetTrigger(g_name + "_Hit");
                g_currentState = g_State.HIT;
            }
            g_hitMove         = new Vector2(face / 10, 0);
            g_body2d.velocity = g_hitMove;
            //transform.Translate(g_hitMove  );
            if (g_health <= 0)
            {
                g_currentState = g_State.DEATH;
                g_inDeath      = true;
            }
        }
    }
Ejemplo n.º 4
0
 //动画事件
 void AE_ResetHit()
 {
     g_currentState = g_State.IDLE;
 }