예제 #1
0
        public override void Update()
        {
            //Increment time if we're not waiting
            if (CurState != States.Waiting)
            {
                ElapsedTime += Time.ElapsedMilliseconds;
            }

            //If we're moving down or moving up, move the box
            if (CurState == States.MovingDown || CurState == States.MovingUp)
            {
                Vector2 start = StartPos;
                Vector2 end   = EndPos;
                if (CurState == States.MovingUp)
                {
                    UtilityGlobals.Swap(ref start, ref end);
                }

                Position = Interpolation.Interpolate(start, end, ElapsedTime / MoveTime,
                                                     CurState == States.MovingDown ? Interpolation.InterpolationTypes.CubicOut : Interpolation.InterpolationTypes.CubicIn);

                if (ElapsedTime > MoveTime)
                {
                    CurState    = States.Waiting;
                    ElapsedTime = 0d;
                }
            }
            //If we're opening or closing the box, do the appropriate action
            else if (CurState == States.Opening || CurState == States.Closing)
            {
                if (CurState == States.Opening)
                {
                    CurTargetRegion.Y      = Interpolation.Interpolate(ScreenRegion.Height / 2, 0, ElapsedTime / OpenCloseTime, Interpolation.InterpolationTypes.Linear);
                    CurTargetRegion.Height = Interpolation.Interpolate(0, ScreenRegion.Height, ElapsedTime / OpenCloseTime, Interpolation.InterpolationTypes.Linear);
                }
                else
                {
                    CurTargetRegion.Y      = Interpolation.Interpolate(0, ScreenRegion.Height / 2, ElapsedTime / OpenCloseTime, Interpolation.InterpolationTypes.Linear);
                    CurTargetRegion.Height = Interpolation.Interpolate(ScreenRegion.Height, 0, ElapsedTime / OpenCloseTime, Interpolation.InterpolationTypes.Linear);
                }

                if (ElapsedTime > OpenCloseTime)
                {
                    CurState    = States.Waiting;
                    ElapsedTime = 0d;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles resolving the sorting of BattleEntities if their BattleIndices are the same.
        /// </summary>
        /// <param name="entity1">The first BattleEntity to compare.</param>
        /// <param name="entity2">The second BattleEntity to compare.</param>
        /// <returns>-1 if entity1 has a lower X position, 1 if entity2 has a lower X position. If players, higher X positions are favored instead.
        /// If X positions are equal, -1 if entity1 has a lower Y position and 1 if entity2 has a lower Y position.
        /// If X and Y positions are equal, 0.</returns>
        private static int ResolveSameBattleIndex(BattleEntity entity1, BattleEntity entity2)
        {
            //Check if they have the same X position
            //If so, compare the Y - lower Y values are favored
            if (entity1.BattlePosition.X == entity2.BattlePosition.X)
            {
                if (entity1.BattlePosition.Y < entity2.BattlePosition.Y)
                {
                    return(-1);
                }
                else if (entity1.BattlePosition.Y < entity2.BattlePosition.Y)
                {
                    return(1);
                }
            }
            //If not, compare X positions
            else
            {
                //Sorting occurs between same BattleEntities with the same EntityType
                BattleEntity leftEntity  = entity1;
                BattleEntity rightEntity = entity2;

                //Swap if they're players, as Players go from right to left
                if (entity1.EntityType == Enumerations.EntityTypes.Player)
                {
                    UtilityGlobals.Swap(ref leftEntity, ref rightEntity);
                }

                //Compare X position; favor the lower for enemies and the higher for players
                if (leftEntity.BattlePosition.X < rightEntity.BattlePosition.X)
                {
                    return(-1);
                }
                else if (leftEntity.BattlePosition.X > rightEntity.BattlePosition.X)
                {
                    return(1);
                }
            }

            return(0);
        }