Пример #1
0
    public void UpdateSpawn()
    {
        if (this._activeConsumables.Count > MainGame.Instance.level + this._initialMax)
        {
            return;
        }

        Vector3 playerLocation = MainGame.Instance.playerObject.transform.position;

        //spawn a piece of food offscreen
        //Always make sure there's at least one human on board
        bool humanExists = false;

        foreach (GameObject go in this._activeConsumables)
        {
            PossibleFood pf = go.GetComponent <PossibleFood>();
            if (pf.lifeStatus == PossibleFood.FoodStatus.Alive)
            {
                humanExists = true;
                break;
            }
        }

        for (int i = 0; i < MainGame.Instance.level + this._initialMax; i++)
        {
            List <Vector3> positions = new List <Vector3>();

            int n = 0;
            if (!humanExists)
            {
                for (n = 0; n < this._humanSpawnPoint.Length; n++)
                {
                    if (Vector3.Distance(playerLocation, this._humanSpawnPoint[n].position) > 3)
                    {
                        positions.Add(this._humanSpawnPoint[n].position);
                    }
                }

                GameObject newHumanFood = Instantiate(this._humanPrefab, this._humanSpawnPoint[Random.Range(0, this._humanSpawnPoint.Length)].position, Quaternion.identity);

                //Pick one of the 4 entrences and have the human spawn there
                humanExists = true;

                OnSpawnFoodItem(newHumanFood);
                continue;
            }

            for (n = 0; n < this._foodSpawnPoint.Length; n++)
            {
                if (Vector3.Distance(playerLocation, this._foodSpawnPoint[n].position) > 6)
                {
                    positions.Add(this._foodSpawnPoint[n].position);
                }
            }

            GameObject newFoodFood = Instantiate(((Random.Range(0f, 1f) > .75f) ? this._humanPrefab: this._veggiesPrefab), positions[Random.Range(0, positions.Count)], Quaternion.identity);

            OnSpawnFoodItem(newFoodFood);
        }
    }
Пример #2
0
    /// <summary>
    /// OnTriggerEnter is called when the Collider other enters the trigger.
    /// </summary>
    /// <param name="other">The other Collider involved in this collision.</param>
    void OnTriggerEnter(Collider other)
    {
        PossibleFood pf = other.GetComponentInParent <PossibleFood>();

        if (pf && pf.lifeStatus != PossibleFood.FoodStatus.Inedible)
        {
            this._foodInArea.Add(new FoodInArea(pf));

            if (this._foodInArea.Count == 1)
            {
                this._animator.Play("FoodIndicator");
                this._mouth.LookAt(pf.transform);
                this._plantAnimator.Play("Idle");
            }
        }
    }
Пример #3
0
    public void OnEat(PossibleFood possibleFood)
    {
        this._hungerGauge += possibleFood.nurishValue;

        if (this._hungerGauge > 55)
        {
            print("Level up!");
            MainGame.Instance.OnLevelUp();
            this._hungerPerSecond = .5f + (MainGame.Instance.level * .2f);
        }

        this._hungerGauge = Mathf.Clamp(this._hungerGauge, 0, 52);
        print("EAT");
        if (possibleFood.lifeStatus == PossibleFood.FoodStatus.Meat || possibleFood.lifeStatus == PossibleFood.FoodStatus.Alive)
        {
            this._tasteForMeat += .05f;

            if (possibleFood.lifeStatus == PossibleFood.FoodStatus.Alive)
            {
                this._tasteForMeat += .05f;
            }
        }

        if (this._tasteForMeat > 1)
        {
            this._tasteForMeat = 1;
        }

        if (possibleFood.gameObject.tag == "Player")
        {
            MainGame.Instance.OnKillPlayer();
        }

        MainGame.Instance.OnFoodConsumed(possibleFood.gameObject);

        Destroy(possibleFood.gameObject, .01f);

        if (this._foodInArea.Count < 2)
        {
            this._animator.Play("FoodRemove");
        }
    }
Пример #4
0
    void OnTriggerExit(Collider other)
    {
        PossibleFood pf = other.GetComponentInParent <PossibleFood>();

        if (pf)
        {
            FoodInArea fia;
            for (int i = this._foodInArea.Count - 1; i >= 0; i--)
            {
                fia = this._foodInArea[i];
                if (pf == fia.food)
                {
                    this._foodInArea.RemoveAt(i);
                    continue;
                }
            }
        }

        if (this._foodInArea.Count < 1)
        {
            this._animator.Play("FoodRemove");
        }
    }
Пример #5
0
 public FoodInArea(PossibleFood possibleFood)
 {
     this.food       = possibleFood;
     this.timeInArea = 0;
 }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        //If the player is within Range look at the player

        this._hungerGauge -= Time.deltaTime * this._hungerPerSecond;
        if (this._hungerGauge < 0)
        {
            print("dead?");
            this._hungerGauge = 0;
            this.enabled      = false;

            MainGame.Instance.GameOver();
        }

        this.healthBarPercentage = Mathf.Clamp(this._hungerGauge / (this._maxHungerArea * 10f), 0.001f, 1f);


        for (int i = this._foodInArea.Count - 1; i >= 0; i--)
        {
            FoodInArea fia = this._foodInArea[i];
            if (fia.food == null)
            {
                this._foodInArea.RemoveAt(i);
                continue;
            }

            fia.timeInArea += (fia.food.lifeStatus == PossibleFood.FoodStatus.Veggies) ?  Time.deltaTime * (1 - this._tasteForMeat) : Time.deltaTime;
            if (this._currentBehaviour != PlantAttackMode.Idle)
            {
                continue;
            }

            if (fia.timeInArea > this._hungerGauge || fia.timeInArea > this._maxHungerArea)
            {
                if (fia.food == null)
                {
                    continue;
                }
                //TODO: Attack charge up
                this._currentBehaviour = PlantAttackMode.Attacking;

                this._plantAnimator.Play("Bite");
                this._attackPoint = fia.food.transform.position;
                this._attackTime  = 0;
            }
        }

        if (this._currentBehaviour == PlantAttackMode.Attacking)
        {
            this._attackTime += Time.deltaTime;
            this._mouth.transform.position = Vector3.Lerp(this._startingLocation, this._attackPoint, this._attackTime / this._attackSpeed);
            this._mouth.LookAt(this._attackPoint);
            if (this._attackTime > this._attackSpeed)
            {
                this._attackTime       = 0;
                this._currentBehaviour = PlantAttackMode.Recoiling;

                Collider[] hitColliders = Physics.OverlapSphere(this._mouth.position, .25f);
                if (hitColliders.Length > 0)
                {
                    for (int n = 0; n < hitColliders.Length; n++)
                    {
                        if (hitColliders[n].gameObject.layer == LayerMask.NameToLayer("Plant"))
                        {
                            continue;
                        }

                        PossibleFood pf = hitColliders[n].gameObject.GetComponentInParent <PossibleFood>();
                        if (pf == null)
                        {
                            continue;
                        }

                        if (pf.lifeStatus == PossibleFood.FoodStatus.Veggies || pf.lifeStatus == PossibleFood.FoodStatus.Meat)
                        {
                            OnEat(pf);
                        }
                    }
                }
            }
        }

        if (this._currentBehaviour == PlantAttackMode.Recoiling)
        {
            this._attackTime += Time.deltaTime;
            this._mouth.transform.position = Vector3.Lerp(this._attackPoint, this._startingLocation, this._attackTime / this._attackSpeed);

            if (this._attackTime > this._attackSpeed)
            {
                this._attackTime       = 0;
                this._currentBehaviour = PlantAttackMode.Idle;
            }
        }



        switch (this._currentBehaviour)
        {
        case PlantAttackMode.Idle:
            OnIdling();
            break;
        }
    }
Пример #7
0
    public void OnInteract()
    {
        if (this._itemInHand && this._interactable == null)
        {
            this._itemInHand = false;
        }
        if (!this._interactable)
        {
            return;
        }

        this._pickupIntructions++;

        if (!this._itemInHand)
        {
            //Check to see how to interact with it
            PossibleFood pf = this._interactable.GetComponentInParent <PossibleFood>();
            if (!pf)
            {
                //Say I won't touch it
                return;
            }

            Transform objectParent = this._interactable.transform.parent;
            Rigidbody rb;
            switch (pf.lifeStatus)
            {
            case PossibleFood.FoodStatus.Veggies:
                objectParent.parent = this.transform;
                this._itemInHand    = true;
                objectParent.transform.localPosition = this._triggerBox.transform.localPosition;

                rb = objectParent.GetComponent <Rigidbody>();
                if (rb)
                {
                    rb.detectCollisions = false;
                    rb.velocity         = Vector3.zero;
                    rb.isKinematic      = true;
                    rb.useGravity       = false;
                }

                if (this._pickupIntructions < 3)
                {
                    MainGame.Instance.ShowTip("Press Spacebar to drop", 4);
                }

                break;

            case PossibleFood.FoodStatus.Meat:
                objectParent.parent = this.transform;
                this._itemInHand    = true;
                objectParent.transform.localPosition = this._triggerBox.transform.localPosition;

                rb = objectParent.GetComponent <Rigidbody>();
                if (rb)
                {
                    rb.detectCollisions = false;
                    rb.velocity         = Vector3.zero;
                    rb.isKinematic      = true;               rb.isKinematic = false;
                    rb.useGravity       = false;
                }
                break;

            case PossibleFood.FoodStatus.Alive:

                string message = "Not while it lives";

                switch (Random.Range(0, 3))
                {
                case 0:
                    message = "First I must murder it.";
                    break;

                case 1:
                    message = "I must make it stop moving.";
                    break;
                }

                MainGame.Instance.speechManager.OnSpeech(this.transform, message, 2);
                MainGame.Instance.ShowTip("Press CTRL to murder...", 4);
                pf.GetComponentInParent <Character>().Invoke("Confused", 2);
                break;
            }
        }
        else if (this._itemInHand)
        {
            Transform parentObject = this._interactable.transform.parent;
            //Drop said item

            parentObject.parent = null;
            this._itemInHand    = false;

            Rigidbody rb = parentObject.GetComponent <Rigidbody>();
            if (rb)
            {
                rb.useGravity       = true;
                rb.isKinematic      = false;
                rb.detectCollisions = true;
            }
        }
    }