Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (isBusy == true)
        {
            return;
        }

        if (model.actions.Count != 0)
        {
            currentAction    = (FarmerAction)model.actions[0];
            currentFlowerbed = currentAction.Flowerbed;
            float dt = MoveTo(new Vector2(currentAction.Flowerbed.GetComponent <RectTransform>().position.x,
                                          currentAction.Flowerbed.GetComponent <RectTransform>().position.y));
        }
    }
Esempio n. 2
0
    public void onTick()
    {
        FarmerAction curAction = actions[curActionIndex];

        if (curAction.isFinished())
        {
            curActionIndex += 1;
            if (curActionIndex >= actions.Count)
            {
                curActionIndex = 0;
            }
            FarmerAction nextAction = actions[curActionIndex];
            nextAction.onStart();
        }
    }
Esempio n. 3
0
    public void EnqueueAction (FarmerActionType actionType, Vector2 target) {
        // don't judge me for not having a constructor
        FarmerAction newAction = new FarmerAction {
            type = actionType,
            target = target
        };

        actions.AddLast(newAction);

        SetMarkers();
    }
Esempio n. 4
0
    void DequeueAction () {
        if (actions.Count == 0) {
            currentAction = null;
            SetMarkers();
            return;
        }
        currentAction = actions.First.Value;
        actions.RemoveFirst();

        if (!toolbar.CanAffordAction(currentAction.type)) {
            toolbar.UnsetTools();
            DequeueAction();
            return;
        }

        SetMarkers();
        target = currentAction.target;
        startPos = transform.position;
        Debug.DrawLine(startPos, target, Color.blue, 0.1f);
        state = FarmerState.Moving;
        moveStartTime = Time.time;

        if (allowInstantAction && currentAction.type != FarmerActionType.Move) {
            target = transform.position;
        }

        float moveDistance = Vector2.Distance(transform.position, target);
        moveDuration = Mathf.Max(moveDistance / moveSpeed, 0.01f);
        rend.flipX = (target.x > transform.position.x);
    }