コード例 #1
0
        private IEnumerator PullDown(BoardController board, Action after, SubHUDSprite tentacle, BoardController.BoardSpace startSpace)
        {
            yield return(1.5f);

            // The highest space with the exact same x
            // Or if there is no space with the same x
            // Then the closest space to the point at the bottom of the screen but with the same x
            BoardController.BoardSpace endSpace = BoardController.boardSpaces
                                                  .FindAll(s => s.x == startSpace.x && !s.screenPosition.Equals(startSpace.screenPosition))
                                                  .OrderBy(a => a.y)
                                                  .DefaultIfEmpty(BoardController.boardSpaces
                                                                  .OrderBy(a => (a.screenPosition - new Vector2(startSpace.screenPosition.X, Engine.ViewHeight)).LengthSquared())
                                                                  .First(s => !s.screenPosition.Equals(startSpace.screenPosition)))
                                                  .First();

            var grabbed = board.playerTokens.Where(t => t != null && t.currentSpace.screenPosition.Equals(startSpace.screenPosition));

            tentacle.sprite.Play("tentacle_pull");
            Vector2 offset = new Vector2(tentacle.sprite.Width * scaleFactor / 2, 27 * scaleFactor);
            Vector2 speed  = (endSpace.screenPosition - startSpace.screenPosition).SafeNormalize() * 150 * Engine.DeltaTime;
            Vector2 pos    = startSpace.screenPosition;

            while (tentacle.Position != endSpace.screenPosition - offset)
            {
                pos    = Vector2.Clamp(pos + speed, Vector2.Min(startSpace.screenPosition, endSpace.screenPosition), Vector2.Max(startSpace.screenPosition, endSpace.screenPosition));
                speed += speed.SafeNormalize() * 150 * Engine.DeltaTime;
                dragToPos(tentacle, grabbed, pos, offset);
                yield return(null);
            }
            yield return(0.5f);

            float tentacleStartY = tentacle.Position.Y;

            tentacle.sprite.Rate = 0.5f;
            tentacle.sprite.Play("tentacle_ungrab");

            tentacle.sprite.OnLastFrame = s => {
                tentacle.sprite.OnLastFrame = null;
                Tween fallTween = Tween.Create(Tween.TweenMode.Oneshot, Ease.CubeInOut, 0.25f, true);
                fallTween.OnUpdate   = t => tentacle.Position.Y = Calc.LerpClamp(tentacleStartY, Engine.ViewHeight + tentacle.sprite.Height * scaleFactor, t.Percent);
                fallTween.OnComplete = t => {
                    tentacle.RemoveSelf();
                    after();
                };
                board.Add(fallTween);
            };

            foreach (PlayerToken token in grabbed)
            {
                token.currentSpace = endSpace;
            }
        }
コード例 #2
0
        private IEnumerator SeekerCharge(BoardController board, Action after, SubHUDSprite seeker, Vector2 start, Vector2 end)
        {
            yield return(0.6f);

            float speed = -6;

            while ((start - end).Sign().Equals((seeker.Position - end).Sign()))
            {
                CheckSeekerCollision(board, seeker);
                speed            = Calc.Approach(speed, 26f, 30f * Engine.DeltaTime);
                seeker.Position += speed * (end - start).SafeNormalize();
                yield return(null);
            }
            while (speed > 0.5)
            {
                CheckSeekerCollision(board, seeker);
                speed            = Calc.Approach(speed, 0, 40f * Engine.DeltaTime);
                seeker.Position += speed * (end - start).SafeNormalize();
                yield return(null);
            }
            seeker.sprite.Play("takeHit");
            seeker.sprite.OnLoop = s => { seeker.RemoveSelf(); after(); };
        }