コード例 #1
0
ファイル: Supplies.cs プロジェクト: flipvrijn/LudumDare
    // Update is called once per frame
    void FixedUpdate()
    {
        if (currentTick % tickRate == 0)
        {
            food += farm.CalculateEfficiency() * 0.5f;

            float foodConsumption = 0f;
            foreach (Worker worker in workerIndex.GetAllWorkers())
            {
                food -= worker.foodConsumption;
                if (food < 0)
                {
                    food = 0;
                }
                foodConsumption += worker.foodConsumption;
            }
            totalFoodConsumption = foodConsumption;
            Notify(this);

            currentTick = 0;
        }
        currentTick++;
    }
コード例 #2
0
    public override void Publish(Publisher publisher)
    {
        if (publisher.GetType() == typeof(Supplies))
        {
            Supplies supplies = (Supplies)publisher;

            this.food.text  = (System.Math.Floor(supplies.food)).ToString();
            this.stone.text = (System.Math.Floor(supplies.stones)).ToString();
        }
        else if (publisher.GetType() == typeof(TimeCycle))
        {
            TimeCycle timeCycle = (TimeCycle)publisher;

            hour      = timeCycle.hour;
            day       = timeCycle.daysPassed;
            time.text = day.ToString() + "d " + hour.ToString() + "h";
        }
        else if (publisher.GetType() == typeof(WorkerIndex))
        {
            WorkerIndex workerIndex = (WorkerIndex)publisher;

            this.workers.text = workerIndex.GetAllWorkers().Count.ToString();
        }
    }