Exemple #1
0
        public IState Update(AbstractStateManager stateManager)
        {
            SetEntityPosition(stateManager, GetNewPosition(stateManager));

            if (HasArrived(_targetPosition, stateManager))
            {
                SetEntityPosition(stateManager, _targetPosition);

                if (stateManager is PlayerMovementManager)
                {
                    return(new PlayerIdleState((PlayerMovementManager)stateManager));
                }

                if (stateManager is BlockMovementManager)
                {
                    return(new BlockIdleState((BlockMovementManager)stateManager));
                }

                if (stateManager is SheepMovementManager)
                {
                    return(new SheepIdleState((SheepMovementManager)stateManager));
                }

                return(new IdleState());
            }

            return(null);
        }
Exemple #2
0
        private bool HasArrived(Vector3 target, AbstractStateManager stateManager)
        {
            float           snap           = 0;
            IEntityWithSnap entityWithSnap = stateManager as IEntityWithSnap;

            if (entityWithSnap != null)
            {
                snap = entityWithSnap.GetSnapDistance();
            }

            return(Vector3.Distance(target, stateManager.transform.position) <= snap);
        }
Exemple #3
0
        private Vector3 GetNewPosition(AbstractStateManager stateManager)
        {
            IEntityWithSpeed entityWithSpeed = stateManager as IEntityWithSpeed;

            if (entityWithSpeed == null)
            {
                throw new Exception("Entity that moves must implement IEntityWithSpeed");
            }

            return(Vector3.SmoothDamp(stateManager.transform.position, _targetPosition, ref _velocity,
                                      Time.deltaTime * entityWithSpeed.GetSpeed()));
        }
Exemple #4
0
 public EntityMovingState(
     AbstractStateManager stateManager,
     MovementInstruction movementInstruction
     )
 {
     Instruction     = movementInstruction;
     _targetPosition = new Vector3(
         movementInstruction.Direction.x,
         0,
         movementInstruction.Direction.y
         ) + stateManager.transform.position;
 }
Exemple #5
0
 private void SetEntityPosition(AbstractStateManager stateManager, Vector3 position)
 {
     stateManager.transform.position = position;
 }
 public void Exit(AbstractStateManager stateManager)
 {
     _movementManager.collisionService.OnCollision -= HandleCollision;
 }
 public IState Update(AbstractStateManager stateManager)
 {
     return(null);
 }
Exemple #8
0
 public void Exit(AbstractStateManager stateManager)
 {
     _playerMovementManager.playerInputService.OnInput -= HandleInput;
 }
Exemple #9
0
 public void Enter(AbstractStateManager stateManager)
 {
     _playerMovementManager.playerInputService.OnInput += HandleInput;
     LevelManager.Instance.CheckWinCondition();
 }
 public void Exit(AbstractStateManager stateManager)
 {
     _movementManager.repelService.OnRepel -= HandleRepel;
 }