예제 #1
0
    //Corners the player in the passed tactical region
    private void CornerPlayer(GameObject corner)
    {
        List <Vector2> tacticalLocations = corner.GetComponent <TacticalRegion>().getTacticalWaypointLocations();
        List <int>     indexes_unused    = Enumerable.Range(0, cats.Length).ToList();

        foreach (Vector2 loc in tacticalLocations)
        {
            int   ind_used = -1;
            float min_dist = float.MaxValue;
            for (int i = 0; i < cats.Length; ++i)
            {
                if (!indexes_unused.Contains(i))
                {
                    continue;
                }

                float dist = Vector2.Distance(cats[i].transform.position, loc);
                if (dist < min_dist)
                {
                    min_dist = dist;
                    ind_used = i;
                }
            }

            if (ind_used == -1)
            {
                return;
            }

            CatMovementController cmc = cats[ind_used].GetComponent <CatMovementController>();
            cmc.ForceUpdatePath(loc);
            cmc.ChangeMovementState(MovementBehaviorState.ARRIVE);

            indexes_unused.Remove(ind_used);
        }

        foreach (int unused in indexes_unused)
        {
            CatMovementController cmc = cats[unused].GetComponent <CatMovementController>();
            cmc.ChangeMovementState(MovementBehaviorState.WANDER);
        }
    }
예제 #2
0
    void CheckPlayerCornered()
    {
        Vector2?targetPos = CalculateGlobalLocationEstimate();

        //TODO: Might wanna make all cats just wander
        if (targetPos == null)
        {
            return;
        }

        GameObject corner = player.getCorner(targetPos.Value);

        if (corner != null)
        {
            //if corner was already computed, do nothing cats shoul already be cornering
            if (playerCornered)
            {
                return;
            }

            playerCornered = true;
            CornerPlayer(corner);
        }
        else
        {
            playerCornered = false;

            //check for closest cat and go to mouse estimate location
            //other cats will wander
            CatMovementController closest = null;
            float min_dist = float.MaxValue;
            for (int i = 0; i < cats.Length; ++i)
            {
                CatMovementController cmc = cats[i].GetComponent <CatMovementController>();
                cmc.ForceUpdatePath(targetPos.Value);
                float curr_dist = cmc.GetPath().GetPathLength();

                if (closest == null)
                {
                    cmc.ChangeMovementState(MovementBehaviorState.PURSUE);
                    min_dist = curr_dist;
                    closest  = cmc;
                }
                else if (curr_dist < min_dist)
                {
                    closest.ChangeMovementState(MovementBehaviorState.WANDER);

                    cmc.ChangeMovementState(MovementBehaviorState.PURSUE);
                    min_dist = curr_dist;
                    closest  = cmc;
                }
                else
                {
                    cmc.ChangeMovementState(MovementBehaviorState.WANDER);
                }
            }

            //debugging
            gizmoEstimate = targetPos.Value;
        }
    }