Beispiel #1
0
    // Update is called once per frame
    void Startimus()
    {
        currentSheepPos = grid.ClosestTile(this);

        if (grid.SheepSearching(this) == false)
        {
            currentSheepPos = grid.ClosestTile(this);
            newPos          = grid.ClosestGrass(this);
        }
        else
        {
            newPos = new Vector2(Random.Range(0, 20), Random.Range(0, 20));
        }
        if (grid.grassTaken(newPos, this) == false)
        {
            currentSheepPos = grid.ClosestTile(this);
            oldPos          = currentSheepPos;
            currentSheepPos = newPos;
        }
        else
        {
            currentSheepPos = grid.ClosestTile(this);
            newPos          = new Vector2(Random.Range(0, 20), Random.Range(0, 20));
            oldPos          = currentSheepPos;
            currentSheepPos = newPos;
        }
        sheepStates = _states.moving;
        run         = false;
    }
Beispiel #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        hp -= 0.003f;


        if (wolfStates == _states.hunting)
        {
            currentWolfPos = WolfnewPos;
            if (transform.position.x != WolfnewPos.x)
            {
                transform.position = Vector3.MoveTowards(transform.position, new Vector3(WolfnewPos.x, WolfoldPos.y), 1f * Time.deltaTime);
            }
            else if (transform.position.x == WolfnewPos.x)
            {
                transform.position = Vector3.MoveTowards(transform.position, new Vector3(WolfnewPos.x, WolfnewPos.y), 1f * Time.deltaTime);
                if (transform.position.x == WolfnewPos.x && transform.position.y == WolfnewPos.y)
                {
                    if (grid.WolfEating(this) == false)
                    {
                        this.GetComponent <SpriteRenderer>().color = NormalColor;
                        Startimus();
                    }
                    else
                    {
                        hp += 5;
                        this.GetComponent <SpriteRenderer>().color = EatingColor;
                    }
                }
            }
        }

        if (hp >= 30)
        {
            grid.AddWolf(currentWolfPos.x, currentWolfPos.y);
            hp = 5;
        }

        if (hp <= 0)
        {
            currentWolfPos = grid.ClosestTile(this);
            grid.AddWolfGrass(currentWolfPos.x, currentWolfPos.y, this);
            Destroy(gameObject);
        }
    }