/// <summary> /// Carries out the movements stored in the movements queue. /// </summary> /// <returns></returns> protected virtual IEnumerator CR_Move() { while (movements.Count > 0) { MovementPackage mp = movements.Peek(); RemoveOccupation(); while (Vector3.Distance(transform.position, mp.Target) > 0.01) { transform.position = Vector3.SmoothDamp(transform.position, mp.Target, ref movementVelocity, mp.SmoothTime, mp.MaxSpeed); yield return(null); } if (mp.TargetTile != null && mp.OccupyAtDestination) { OccupyTile(mp.TargetTile); } if (mp.RaiseEvent) { OnMoveComplete(new MoveCompleteArgs(this)); //Raise MoveComplete Event } movements.Dequeue(); } CR_Relocating = null; }
public void Tick() { if (!_mover.IsMoving) { _playerDashMonitor.RefundChargesWhileNotMoving(); } if (_mover.MovementPackage?.Destination != null) { _player.PlayerCollider2D.enabled = _mover.MovementPackage.Destination.DestinationType == DestinationType.Exit; } else { _player.PlayerCollider2D.enabled = true; } if (_mover.HasDestination) { _mover.Move(); // _playerSafetyRedirect.Tick(); } if (_playerSafetyRedirect.SafetyRedirectAllowed) { if (_startPosition.HasValue) { _mover.Reset(); _playerSafetyRedirect.SafetyRedirectAllowed = false; } } if (_startPosition.HasValue && _mover.MovementPackage?.Destination?.DestinationType == DestinationType.Intersection) { _mover.IsMoving = false; Time.timeScale = 1f; _mover.SetMoveSpeed(40); } var startingDirection = _playerDashMonitor.CurrentCharges > 0 ? InputDestination() : null; if (startingDirection.HasValue == false) { return; } _startPosition = null; _endPosition = null; if (_mover.IsMoving) { return; } _mover.CanMove = true; _currentMovementPackage = _destinationSetter.GetDestinationFromFirstMove(_player.MoveAmountPerSwipe, startingDirection.Value); _mover.SetMovementPackage(_currentMovementPackage); }
public void Reset() { _isInDanger = false; MovementPackage.MovementCount = 0; RedirectDisplayManager.Instance.ResetDisplay(); _movementPackage = null; IsMoving = false; Time.timeScale = 1f; _currentMoveSpeed = _defaultMoveSpeed; }
private void EvaluateNextMove(MovementPackage previousPackage, Action <MovementPackage> callback, bool redirectSuccess) { callback(redirectSuccess ? ContinueFromRedirectSuccess(previousPackage) : ContinueFromRedirectFailure(previousPackage)); if (redirectSuccess && previousPackage.IntersectionAnalysis.IntersectingUnit != null) { UnitChainEvaluator.Instance.RemoveUnit(previousPackage.IntersectionAnalysis.IntersectingUnit); } }
private MovementPackage ContinueFromRedirectSuccess(MovementPackage previousPackage) { var redirectedMoveDirection = ((Vector2)previousPackage.IntersectionAnalysis.IntersectingUnit.Transform.position - previousPackage.Destination.TargetLocation).normalized; var newRedirectDestination = new Destination(); newRedirectDestination.Initialize(previousPackage.Destination.TargetLocation, redirectedMoveDirection, null); newRedirectDestination.DestinationType = previousPackage.Destination.DestinationType; newRedirectDestination.PreviousIntersectingUnit = previousPackage.IntersectionAnalysis.IntersectingUnit; return(new MovementPackage(newRedirectDestination, null, _transform, previousPackage.DistanceScalar)); }
public MovementPackage GetDestinationFromFirstMove(float distanceScalar, Vector2 moveDirection) { var unit = TargetDetector.GetValidUnitInFrontFromTargetPosition(null, distanceScalar, moveDirection, _transform.position, 0.7f); var destination = EvaluateStartingMove(unit, distanceScalar, moveDirection); if (Vector2.Distance(_transform.position, destination.TargetLocation) < 0.1f) { return(null); } var startingPackage = new MovementPackage(_transform, destination, distanceScalar); return(startingPackage); }
public void SetMovementPackage(MovementPackage movementPackage) { _requested = false; _movementPackage = movementPackage; if (movementPackage?.Destination != null) { _distanceToCurrentDestination = Vector2.Distance(_transform.position, _movementPackage.Destination.TargetLocation); OnNewMovementStart?.Invoke(_movementPackage.Destination.DestinationType); if (MovementPackage.MovementCount % 2 != 0) { OnFirstMove?.Invoke(); } else { OnKill?.Invoke(); } } }
/// <summary> /// Moves the GamePiece unrestricted by the GameBoard. /// </summary> /// <param name="position">The position to move the piece to.</param> /// <param name="smoothTime">The amount of time in seconds spent smoothing the movement.</param> /// <param name="maxSpeed">The maximum clamp of the speed.</param> /// <param name="interrupt">True if this should immediately halt and replace any other movement the GamePiece is undergoing.</param> public virtual void MoveOffBoard(Vector3 position, float smoothTime, float maxSpeed, bool interrupt) { RemoveOccupation(); if (interrupt) { movements.Clear(); if (CR_Relocating != null) { StopCoroutine(CR_Relocating); CR_Relocating = null; } } MovementPackage mp = new MovementPackage(position, smoothTime, maxSpeed, false) { RaiseEvent = true }; movements.Enqueue(mp); StartMovement(); }
private MovementPackage ContinueFromRedirectFailure(MovementPackage previousPackage) { return(new MovementPackage(previousPackage.Destination, previousPackage.IntersectionAnalysis, _transform, previousPackage.DistanceScalar)); }