Esempio n. 1
0
        public override void OnUpdate()
        {
            if (isMoving)
            {
                float finalMoveSpeed = moveSpeed;

                if (movementModifiers.Any(x => x.OverridePreviousModifiers == true))
                {
                    // Take the last overriding modifier and set the speed to it's value.
                    finalMoveSpeed *= movementModifiers.Where(x => x.OverridePreviousModifiers == true).Last().SpeedModifier;
                }
                else
                {
                    // Stack all current speed modifiers
                    foreach (var modifier in movementModifiers)
                    {
                        finalMoveSpeed *= modifier.SpeedModifier;
                    }
                }

                GameObject.Position += direction * finalMoveSpeed * FrameTime.Delta;

                if (startPosition.GetDistance(GameObject.Position) >= distance)
                {
                    isMoving = false;
                    OnMoveFinished?.Invoke();
                }
            }
        }
Esempio n. 2
0
        protected void FinishMove(EntityAction entityController)
        {
            MoveState = MoveState.Finished;
            OnMoveFinished?.Invoke(this);

            if (entityController != null)
            {
                entityController.OnMoveFinish -= FinishMove;
            }
        }
Esempio n. 3
0
        private void Flee(Vector3 selfPosition, Vector3 targetPos)
        {
            float factor = ArriveFactor(selfPosition, targetPos, SteeringData.AcceptDistance, SteeringData.MaxSteerForce);

            DesiredSpeed = (selfPosition - targetPos).normalized * factor * SteeringData.DesiredSpeed;

            bool hasReachedTarget = factor <= 0.005f;

            if (hasReachedTarget)
            {
                OnMoveFinished?.Invoke();
            }
        }
Esempio n. 4
0
        private void OnSwapeTileComplete(Vector2Int checkCoordinate, bool counting)
        {
            if (!counting)
            {
                return;
            }

            bool effectiveMove = false;

            if (ValidateBoardSimulation() > 0)
            {
                StartCoroutine(ValidateBoard(() =>
                {
                    effectiveMove = true;

                    if (!CheckBoardPlayable())
                    {
                        RecreateBoard();
                    }

                    if (OnMoveFinished != null)
                    {
                        OnMoveFinished.Invoke(effectiveMove);
                    }
                }));
            }
            else if (lastSwaped)
            {
                lastSwaped = false;

                if (expicitMatchs)
                {
                    SwapeTile(lastSwapePair[0], lastSwapePair[1], false); // Swape Back
                }
                else
                {
                    effectiveMove = true;
                }

                if (OnMoveFinished != null)
                {
                    OnMoveFinished.Invoke(effectiveMove);
                }
            }
        }
Esempio n. 5
0
        private void HandleUnitMoving(GameTime gameTime)
        {
            actionAnimationRemaining += gameTime.ElapsedGameTime.Milliseconds;
            if (actionAnimationRemaining > ACTION_ANIMATION_SPEED)
            {
                actionAnimationRemaining -= ACTION_ANIMATION_SPEED;
                currentSpriteRectangle    = UnitData.UnitAnimation.GetNextAnimation(AnimationType.Move);

                var currentPath         = UnitMapPath.GetCurrentPath();
                var currentLocation     = new Vector2(LocationRectangle.X, LocationRectangle.Y);
                var currentPathLocation = BattleMap.GetTileLocation((int)currentPath.X, (int)currentPath.Y);

                if (Vector2.Distance(currentLocation, currentPathLocation) < 0.01f)
                {
                    if (UnitMapPath.IsLastPath())
                    {
                        currentSpriteRectangle = UnitData.UnitAnimation.Animations[AnimationType.Waiting][0];

                        OnMoveFinished?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        UnitMapPath.NextPath();
                    }
                }
                else
                {
                    var direction = currentPathLocation - currentLocation;
                    direction.Normalize();

                    currentLocation += direction * ((BattleMap.TILE_SIZE + BattleMap.TILE_SPACE) / (float)UnitData.UnitAnimation.Animations[AnimationType.Move].Count);// * 0.5f;

                    LocationRectangle = new System.Drawing.RectangleF(currentLocation.X, currentLocation.Y, BattleMap.TILE_SIZE, BattleMap.TILE_SIZE);
                }
            }
        }
Esempio n. 6
0
 public void FinishMove()
 {
     SmashDown();
     OnMoveFinished?.Invoke();
 }
Esempio n. 7
0
 private void Awake()
 {
     pointsToFollow  = lines[currentIndex].curvePoints;
     onMoveFinished += FinalizeMove;
 }