Exemple #1
0
    // todo
    public void DoMove()
    {
        Vector3 dst;

        switch (target)
        {
        case Target.Cat:
            dst = catTrans.position;
            break;

        case Target.Human:
            dst = humanTrans.position;
            break;

        case Target.None:
        default:
            dst = transform.position;
            break;
        }

        var search   = new PathSearch(transform.position, dst); //, MapObj.Air | MapObj.Cat | MapObj.Enemy | MapObj.Human);
        var nextGrid = search.NextGrid();
        var nextPos  = new Vector3(nextGrid.x, 0, nextGrid.y);

        StartCoroutine(SmoothMove(nextPos));
    }
Exemple #2
0
    private void Update()
    {
        if (GameState.Instance.Turn == GameState.TurnOf.Human)
        {
            Vector3 dst;

            // todo: testcode
            var exitPos = new Vector3(GridManager.gridSizeX - 2, 0, GridManager.gridSizeY - 2);

            switch (catMeow.State)
            {
            case CatMeow.MeowState.MeowAttrackHuman:
                dst = catTrans.position;
                break;

            case CatMeow.MeowState.PassOut:
                // todo: kill all enemies
                if (enemyManager.enemyMoves.Count == 0)
                {
                    dst = exitPos;
                }
                else
                {
                    var       minSqrDis    = float.MaxValue;
                    Transform nearestEnemy = null;
                    foreach (var enemy in enemyManager.enemyMoves)
                    {
                        var sqrDis = (enemy.transform.position - transform.position).sqrMagnitude;
                        if (sqrDis < minSqrDis)
                        {
                            minSqrDis    = sqrDis;
                            nearestEnemy = enemy.transform;
                        }
                    }
                    dst = nearestEnemy.position;
                }
                break;

            case CatMeow.MeowState.NoMeow:
            default:
                // todo: find path to key
                // attack ~2 block enemies
                dst = exitPos;
                break;
            }

            var search   = new PathSearch(transform.position, dst); //, MapObj.Air | MapObj.Enemy);
            var nextGrid = search.NextGrid();
            var nextPos  = new Vector3(nextGrid.x, 0, nextGrid.y);

            StartCoroutine(SmoothMove(nextPos));
        }
    }