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); }
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); }
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())); }
public EntityMovingState( AbstractStateManager stateManager, MovementInstruction movementInstruction ) { Instruction = movementInstruction; _targetPosition = new Vector3( movementInstruction.Direction.x, 0, movementInstruction.Direction.y ) + stateManager.transform.position; }
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); }
public void Exit(AbstractStateManager stateManager) { _playerMovementManager.playerInputService.OnInput -= HandleInput; }
public void Enter(AbstractStateManager stateManager) { _playerMovementManager.playerInputService.OnInput += HandleInput; LevelManager.Instance.CheckWinCondition(); }
public void Exit(AbstractStateManager stateManager) { _movementManager.repelService.OnRepel -= HandleRepel; }