示例#1
0
    void GameTick()
    {
        UseEnergy(EnergyUsePerTick);

        TickCount++;
        TickText.text = TickCount.ToString("Game Ticks: 0");
        int drownCount          = 0;
        int vegetationWashedOut = 0;

        UpdatesText.text = "";
        RaycastHit[] hits;
        Collider[]   colliders;
        colliders = Physics.OverlapSphere(waterCollider.transform.position, waterCollider.transform.localScale.x, spawnerRay.planetLayer);
        foreach (Collider h in colliders)
        {
            Creation c = h.transform.GetComponent <Creation>();
            //Debug.Log(h.transform.name);
            if (c != null)
            {
                ecosystem.Kill(h.transform.gameObject.GetComponent <Creation>());
                if (c.spawnableObject.name == "Vegetation")
                {
                    vegetationWashedOut++;
                }
                else
                {
                    BodyCounter.RecordDeath(c.spawnableObject.name, "drowned", 1);
                    drownCount += 1;
                }
            }
        }
        if (drownCount > 0)
        {
            UpdatesText.text += drownCount.ToString("<color=red>0</color> creatures drowned\n");
        }
        if (vegetationWashedOut > 0)
        {
            BodyCounter.RecordDeath("Vegetation", "washed away", vegetationWashedOut);
            UpdatesText.text += vegetationWashedOut.ToString("<color=red>0</color> vegetation washed away\n");
        }
        if (WaterTransform.localScale.x >= 1.4f)
        {
            LoseGame(LoseText[0]);
            // Player has drowned the planet and lost
            Debug.Log("Planet DROWNED!");
        }
        ecosystem.PopulationTick();
        VictoryCheck();
    }
示例#2
0
    public void PopulationTick()
    {
        foreach (SpawnableObject o in GameCore.SpawnableList)
        {
            o.TotalConsumptionOfMe = 0f;
        }

        foreach (SpawnableObject o in GameCore.SpawnableList)
        {
            foreach (Consumption c in o.Consumption)
            {
                c.SpawnableObject.TotalConsumptionOfMe += c.Amount * o.Population;
            }
        }

        foreach (SpawnableObject o in GameCore.SpawnableList)
        {
            if (o.TotalConsumptionOfMe > o.Population)
            {
                int unitsToKill = Mathf.FloorToInt(o.TotalConsumptionOfMe - o.Population);
                Cull(o, unitsToKill);
                if (o.name != "Water")
                {
                    if (o.Population > 0)
                    {
                        if (o.Population < o.TotalConsumptionOfMe)
                        {
                            BodyCounter.RecordDeath(o.name, "eaten", Mathf.FloorToInt(o.Population));
                            GameCore.instance.UpdatesText.text = o.Population.ToString("<color=red>0</color> " + o.name.ToLower() + "s were eaten\n");
                        }
                        else
                        {
                            BodyCounter.RecordDeath(o.name, "eaten", unitsToKill);
                            GameCore.instance.UpdatesText.text = unitsToKill.ToString("<color=red>0</color> " + o.name.ToLower() + "s were eaten\n");
                        }
                    }
                }
            }
        }

        foreach (SpawnableObject o in GameCore.SpawnableList)
        {
            int unitsToKill = 0;
            foreach (Consumption c in o.Consumption)
            {
                // When the population is insufficient for this creature to feed
                if (c.SpawnableObject.TotalConsumptionOfMe > c.SpawnableObject.Population)
                {
                    unitsToKill += Random.Range(0, Mathf.FloorToInt(c.SpawnableObject.TotalConsumptionOfMe - c.SpawnableObject.Population) + 1);
                }
            }
            if (unitsToKill > 0 && o.Population > 0)
            {
                if (o.name != "Vegetation")
                {
                    BodyCounter.RecordDeath(o.name, "starved to death", unitsToKill);
                    GameCore.instance.UpdatesText.text += unitsToKill.ToString("<color=red>0</color> " + o.name.ToLower() + "s starved to death\n");
                }
                else
                {
                    BodyCounter.RecordDeath(o.name, "died from lack of water", unitsToKill);
                    GameCore.instance.UpdatesText.text += unitsToKill.ToString("<color=red>0</color> " + o.name.ToLower() + " withered and died without water\n");
                }
                Cull(o, unitsToKill);
            }
        }

        uiController.UpdatePopulationDetails();
    }