Exemplo n.º 1
0
    IEnumerator PushingStretch(float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        //ends
        _pushingState = PushingState.Normal;
        _worldEntity.ChangeVisual(GetSpriteByID());
    }
Exemplo n.º 2
0
    private void InitaliseFSM()
    {
        _fsm = new FSM.FSM();

        State dormantState = new DormantState(this);
        State idleState    = new IdleState(this);
        State walkingState = new WalkingState(this);
        State pushingState = new PushingState(this);
        State liftingState = new LiftingState(this);

        _fsm.AddTransition(dormantState, idleState, () => { return(!_dormant); });
        _fsm.AddTransition(idleState, dormantState, () => { return(_dormant); });

        _fsm.AddTransition(idleState, walkingState, () => { return(_heading != Vector3.zero); });
        _fsm.AddTransition(walkingState, idleState, () =>
        {
            Vector3 vel = _rb.velocity;
            vel.y       = 0f;
            return(_heading == Vector3.zero && vel == Vector3.zero);
        });

        // Pushing
        _fsm.AddTransition(idleState, pushingState, () =>
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                return(BeginPushing());
            }

            return(false);
        });

        _fsm.AddTransition(pushingState, idleState, () =>
        {
            return(Input.GetKeyDown(KeyCode.E));
        });

        // Lifting
        _fsm.AddTransition(idleState, liftingState, () =>
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                return(BeginLifting());
            }

            return(false);
        });

        _fsm.AddTransition(liftingState, idleState, () =>
        {
            return(Input.GetKeyDown(KeyCode.Q));
        });

        _fsm.SetDefaultState(idleState);
    }
Exemplo n.º 3
0
    private void TryMove(Direction tryDirection)
    {
        switch (WorldManager.g.CanMove(_worldEntity.Location, tryDirection, _worldEntity))
        {
        case MoveResult.Move:
            isStuck = false;
            MoveOneStep(tryDirection);
            //AudioSource.PlayClipAtPoint(_audioMove, _worldEntity.Location.ToVector2(), LevelCode.audioVolume);

            //print("move");
            break;

        case MoveResult.Stuck:
            _needMove = false;
            print("error! pusher stuck!");
            StartCoroutine(PushingContract(_pushingContractDuration));
            StartCoroutine(PushingStretch(_pushingStrechDuration));
            isStuck = true;
            break;

        case MoveResult.Push:
            isStuck = false;
            MoveOneStep(tryDirection);
            AudioSource.PlayClipAtPoint(_audioPush, CameraControl.cameraLoc, LevelCode.audioVolume);
            _pushingState = PushingState.Contract;
            _worldEntity.ChangeVisual(GetSpriteByID());
            StartCoroutine(PushingContract(_pushingContractDuration));
            StartCoroutine(PushingStretch(_pushingStrechDuration));

            //print("push");
            break;

        default:
            break;
        }
    }