Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (pathingType != SheepPathingType.Fleeing && escapeSequence && PositionToWorldVector2Int((Vector2)transform.position).x >= RoomManager.MAINAREA_INNER_X)
        {
            SetOldPos();
            pathingType = SheepPathingType.ToPlayer;
        }

        switch (pathingType)
        {
            case SheepPathingType.Stationary:
                oldPos = transform.position;
                oldRot = detectionComponent.rotation;
                oldScale = transform.localScale;
                break;
            case SheepPathingType.Patrolling:
                Patrol();
                break;
            case SheepPathingType.ToSweater:
                isVisibleInLog = true;
                ChaseSweater();
                break;
            case SheepPathingType.ToPlayer:
                ChasePlayer();
                break;
            case SheepPathingType.Returning:
                ReturnToSpot();
                break;
            case SheepPathingType.Fleeing:
                Flee();
                break;
        }

        Move();
    }
Exemplo n.º 2
0
 void ChaseSweater()
 {
     if (this.tag == "Clothed")
     {
         pathingType = SheepPathingType.Returning;
         return;
     }
     nextPos = sweaterPos;
 }
Exemplo n.º 3
0
 void ReturnToSpot()
 {
     nextPos = oldPos;
     if (((Vector2)transform.position - oldPos).magnitude < arrivalDistance)
     {
         pathingType = oldPathingType;
         returnedToOldPos = true;
         travelPath.Clear();
         if (oldPathingType == SheepPathingType.Stationary)
         {
             transform.localScale = oldScale;
             detectionComponent.rotation = oldRot;
         }
     }
 }
Exemplo n.º 4
0
 public void IsNowFleeing()
 {
     if (!goldenSheep)
     {
         SetOldPos();
         pathingType = SheepPathingType.Fleeing;
         travelPath.Clear();
         current_velocity = movementSpeed * 2;
         howlTimer = HOWL_DURATION;
     }
     else
     {
         pathingType = SheepPathingType.Fleeing;
         current_velocity = movementSpeed * 0.7f;
         howlTimer = HOWL_DURATION;
     }
 }
Exemplo n.º 5
0
    // Start is called before the first frame update
    void Start()
    {
        current_velocity = movementSpeed;
        pathFound = false;
        movingToNextTile = false;
        travelPath = new List<Vector2>();
        oldPathingType = pathingType;
        nextPos = transform.position;
        oldPos = nextPos;
        returnedToOldPos = true;
        sheep = GetComponent<Sheep>();
        pos = Vector2Int.RoundToInt(new Vector2(transform.position.x, transform.position.y));

        wolf = GameObject.Find("Wolf").GetComponent<Wolf>();
        howlTimer = 0;
        detectionComponent = transform.GetChild(3);
        // AI has a patrol spot

        if (PatrolPlot != null)
        {
            pathingType = SheepPathingType.Patrolling;
            // Debug.Log("I am " + gameObject.name + " and I am initializing my patrol route");
            foreach (Transform child in PatrolPlot.transform)
            {
                if (child.tag == "PatrolNode")
                {
                    patrol_nodes.Add(child);
                }
            }
            target_node_index = 0;
        }
        oldPathingType = pathingType;

        if (goldenSheep)
        {
            movementSpeed *= 1.5f;
            current_velocity = movementSpeed;
        }

        InvokeRepeating("clearPath", 10.0f, 1.0f);
    }
Exemplo n.º 6
0
 void Flee()
 {
     // only occurs if near a wolf howl
     if (howlTimer > 0)
     {
         howlTimer -= Time.deltaTime;
         if (!goldenSheep)
         {
             nextPos = ((Vector2)transform.position - wolf.GetWolfPos()) + (Vector2)transform.position;
         }
         else
         {
             nextPos = wolf.GetWolfPos();
         }
     }
     else
     {
         current_velocity = movementSpeed;
         pathingType = SheepPathingType.ToPlayer;
         travelPath.Clear();
     }
 }
Exemplo n.º 7
0
    private void Patrol()
    {
        oldPathingType = SheepPathingType.Patrolling;
        if(slot == null)
        {
            if(patrol_nodes == null || patrol_nodes.Count == 0)
            {
                throw new System.Exception(gameObject.name + "Sheep is set to patrol but has nothing to patrol to");
            }
            // when you reach a node, go to next node. If you're at the edge of a patrol path, change direction
            if ((patrol_nodes[target_node_index].position - transform.position).magnitude <= arrivalDistance)
            {
                if (target_node_index == patrol_nodes.Count - 1 && forward == true)
                {
                    forward = false;
                }
                else if (target_node_index == 0 && forward == false)
                {
                    forward = true;
                }

                if (forward)
                {
                    target_node_index++;
                }
                else
                {
                    target_node_index--;
                }
            }
            nextPos = patrol_nodes[target_node_index].position;
        }
        else
        {
            nextPos = slot.position;
        }
    }
Exemplo n.º 8
0
 void ChasePlayer()
 {
     nextPos = wolf.GetWolfPos();
     // Return to old position if wolf escapes sheep's FoV
     if (!seesPlayer && !escapeSequence)
     {
         if (giveUpTimer <= 0)
         {
             // Debug.Log("Giving up");
             pathingType = SheepPathingType.Returning;
             travelPath.Clear();
         }
         else
         {
             // Debug.Log(giveUpTimer);
             giveUpTimer -= 1.0f * Time.deltaTime;
             travelPath.Clear();
         }
     }
     else if (!seesPlayer && escapeSequence)
     {
         travelPath.Clear();
     }
 }