Exemplo n.º 1
0
    protected override IEnumerator MoveToTar()
    {
        audio.clip = music[0];
        audio.PlayOneShot(music[0]);
        if (now_movelim > 0)
        {
            for (int i = 0; i <= now_movedis; i++)
            {
                yield return(new WaitForSeconds(0.5f));

                transform.position = Vector3.Lerp(transform.position, show_List[i].getPosition(), 0.99f);
                if (tarChess == show_List[i].GetComponent <Transform>())
                {
                    currentPart = show_List[i].transform;
                    if (currentPart.GetComponent <Part>().life == 0)
                    {
                        currentPart.GetComponent <Part>().belong = false;
                    }
                    currentPart.GetComponent <Part>().isControl = true;
                    animator.SetBool("ismove", false);
                    break;
                }
                currentPart = show_List[i].transform;
                if (currentPart.GetComponent <Part>().life == 0)
                {
                    currentPart.GetComponent <Part>().belong = false;
                }
            }
        }

        GameManager.instance.anbeavior = true;
        GameManager.instance.game_state.update_Townlist();
        if (near_player != null)
        {
            int tempdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), near_player.GetComponent <ChessControl>().currentPart.GetComponent <Part>());
            now_movelim--;
            if (tempdis <= now_attck_dis && now_attacklim > 0)
            {
                Invoke("Chess_Attack", 0.6f);
            }
            else
            {
                isdone = true;
            }
        }
    }
Exemplo n.º 2
0
 void attack_atTown()
 {
     getnearest_chess_and_dis();
     if (near_player != null)
     {
         int tempdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), near_player.GetComponent <ChessControl>().currentPart.GetComponent <Part>());
         now_movelim--;
         if (tempdis <= now_attck_dis && now_attacklim > 0)
         {
             Invoke("Chess_Attack", 0.6f);
         }
         else
         {
             isdone = true;
         }
     }
 }
Exemplo n.º 3
0
    protected virtual void Chess_Move()
    {
        //Debug.Log("选择移动点");
        if (init)
        {
            getnowPart();
            show_move_Dis(true, now_movedis, true);
            init = false;
        }

        animator.SetBool("ismove", true);
        if (Input.GetMouseButtonDown(1))
        {
            //show_move_Dis(false, now_movedis, true);
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit mouseHit;
            if (Physics.Raycast(mouseRay, out mouseHit))
            {
                if (mouseHit.transform.GetComponent <Part>() != null && !mouseHit.transform.GetComponent <Part>().isControl)
                {
                    tarChess = mouseHit.transform;

                    int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
                    if (dis <= now_movedis)
                    {
                        float temp = tarChess.position.x - currentPart.position.x;
                        if (temp > 0)
                        {
                            this.GetComponent <SpriteRenderer>().flipX = true;
                        }
                        else
                        {
                            this.GetComponent <SpriteRenderer>().flipX = false;
                        }
                        StartCoroutine(MoveToTar());
                        currentPart.GetComponent <Part>().isControl = false;//离开当前part
                    }
                }
                Chess_ideal();

                animator.SetBool("ismove", false);
            }
            show_move_Dis(false, now_movedis, true);
        }
    }
Exemplo n.º 4
0
 protected virtual void Chess_Attack()
 {
     if (init)
     {
         getnowPart();
         show_move_Dis(true, now_attck_dis, false);
         init = false;
     }
     if (Input.GetMouseButtonDown(1))
     {
         //show_move_Dis(false, now_attck_dis, false);
         Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit mouseHit;
         if (Physics.Raycast(mouseRay, out mouseHit))
         {
             if (mouseHit.transform.GetComponent <EnemyBehavior>() != null &&
                 mouseHit.transform.CompareTag("Enemy"))
             {
                 //Debug.Log(mouseHit.transform);
                 tarChess = mouseHit.transform;
                 int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), tarChess.GetComponent <EnemyBehavior>().currentPart.GetComponent <Part>());
                 if (dis <= now_attck_dis)
                 {
                     float temp = tarChess.position.x - currentPart.position.x;
                     if (temp > 0)
                     {
                         this.GetComponent <SpriteRenderer>().flipX = true;
                     }
                     else
                     {
                         this.GetComponent <SpriteRenderer>().flipX = false;
                     }
                     StartCoroutine(AttackTar());
                 }
             }
         }
         show_move_Dis(false, now_attck_dis, false);
         Chess_ideal();
     }
 }
Exemplo n.º 5
0
    void chooseTarget()
    {
        List <Part> List_Town = new List <Part>();
        Part        min       = null;
        float       mindis    = 99999;

        if (GameManager.instance.getEnemyNum() < GameManager.instance.getPlayerNum())
        {
            List_Town = GameManager.instance.game_state.enemy_town;
        }
        else
        {
            List_Town = GameManager.instance.game_state.play_town;
        }
        foreach (Part p in List_Town)
        {
            if (p == null)
            {
                continue;
            }
            int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), p);
            if (mindis > dis)
            {
                mindis = dis;
                min    = p;
            }
        }
        if (min != null)
        {
            show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), min);
            near_city = min.transform;
            if (show_List.Count > 2)
            {
                if (!show_List[now_movedis].isControl && show_List[now_movedis].thistype != PartType.WATER)
                {
                    tarChess = show_List[now_movedis].GetComponent <Transform>();
                }
                else
                {
                    show_List = Chess_manager.getShowArea(currentPart.GetComponent <Part>(), now_movedis, true);
                    //Debug.Log(show_List.Count);
                    int standdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), min);
                    for (int i = 0; i < show_List.Count; i++)
                    {
                        int dis = Chess_manager.GetRouteDis(show_List[i], min);
                        if ((show_List[i] != null && show_List[i].thistype == PartType.WATER && arm_type == Arm_type.ARMY) || (dis > standdis))
                        {
                            show_List.Remove(show_List[i]);
                        }
                    }
                    int index1 = (int)(Random.Range(0, 1) * (show_List.Count - 1));
                    if (show_List[index1].isControl || (show_List[index1].thistype == PartType.WATER && this.arm_type == Arm_type.ARMY))
                    {
                        tarChess = currentPart;
                    }
                    else
                    {
                        tarChess = show_List[index1].GetComponent <Transform>();
                    }
                }
            }
            else
            {
                tarChess = currentPart;
            }
        }
        show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
    }
Exemplo n.º 6
0
    void getnearest_chess_and_dis()
    {
        show_List.Clear();
        List <ChessControl> player_arm = new List <ChessControl>();

        player_arm = GameManager.player_arm;
        ChessControl min    = null;
        float        mindis = 99999;

        getnowPart();
        foreach (ChessControl p in player_arm)
        {
            if (p == null)
            {
                continue;
            }
            int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), p.currentPart.GetComponent <Part>());
            if (mindis > dis)
            {
                mindis = dis;
                min    = p;
            }
        }
        if (min != null)
        {
            show_List   = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), min.currentPart.GetComponent <Part>());
            near_player = min.transform;
            if (show_List.Count > 2)
            {
                if (!show_List[now_movedis].isControl)
                {
                    tarChess = show_List[now_movedis].GetComponent <Transform>();
                }
                else
                {
                    show_List = Chess_manager.getShowArea(currentPart.GetComponent <Part>(), now_movedis, true);
                    //Debug.Log(show_List.Count);
                    int standdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), min.currentPart.GetComponent <Part>());
                    for (int i = 0; i < show_List.Count; i++)
                    {
                        int dis = Chess_manager.GetRouteDis(show_List[i], min.currentPart.GetComponent <Part>());
                        if ((show_List[i] != null && show_List[i].thistype == PartType.WATER && arm_type == Arm_type.ARMY) || (dis > standdis))
                        {
                            show_List.Remove(show_List[i]);
                        }
                    }
                    int index1 = (int)(Random.Range(0, 1) * (show_List.Count - 1));
                    if (show_List[index1].isControl || (show_List[index1].thistype == PartType.WATER && this.arm_type == Arm_type.ARMY))
                    {
                        tarChess = currentPart;
                    }
                    else
                    {
                        tarChess = show_List[index1].GetComponent <Transform>();
                    }
                }
            }
            else
            {
                tarChess = currentPart;
            }
        }
        show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
    }