Esempio n. 1
0
        public void CreateWind(int side)
        {
            const float ballDelay = 0.5f;

            if (Panda.Hearts < 0)
            {
                return;
            }

            if (_ballTimes.All(i => i < Time.time || (Time.time - i) > ballDelay))
            {
                if (side == 1)
                {
                    Branches[0].AnimateLeft();
                    Branches[1].AnimateLeft();
                    Winds[1].Play();
                }
                else
                {
                    {
                        Branches[0].AnimateRight();
                        Branches[1].AnimateRight();
                        Winds[0].Play();
                    }
                }

                TaskScheduler.CreateTask(() => CreateBall(side), Id, ballDelay);
            }

            var delay = Mathf.Max(0.25f, 2 - _progress / 100f);

            TaskScheduler.CreateTask(() => CreateWind(Random.Range(0, 2)), Id, Random.Range(delay, 1.5f * delay));
        }
Esempio n. 2
0
        public void HobbyLoop()
        {
            Hobby.alpha = 0;

            if (Person.Hobbies.Count == 0)
            {
                return;
            }

            if (Engine.State != GameState.Playing)
            {
                TaskScheduler.CreateTask(HobbyLoop, Engine.TaskId, 1 + CRandom.GetRandom(200) / 100f);
                return;
            }

            if (_hobby == Person.Hobbies.Count)
            {
                _hobby = 0;
            }

            var duration = 3 + CRandom.GetRandom(300) / 100f;

            Hobby.spriteName = Convert.ToString(Person.Hobbies[_hobby++]);
            TweenAlpha.Begin(Hobby.gameObject, 0.4f, 1);
            TaskScheduler.CreateTask(() => TweenAlpha.Begin(Hobby.gameObject, 0.4f, 0), Engine.TaskId, duration);
            TaskScheduler.CreateTask(HobbyLoop, Engine.TaskId, duration + 1);
        }
Esempio n. 3
0
        public void NextPage()
        {
            const float speed = 0.2f;

            var hide = Pages[0].activeSelf ? Pages[0] : Pages[1];
            var show = Pages[0].activeSelf ? Pages[1] : Pages[0];

            Unselect();

            foreach (var card in hide.GetComponentsInChildren <CharacterCard>())
            {
                TweenRotation.Begin(card.gameObject, speed, Quaternion.Euler(0, 90, 0));
                card.Button.Pressed = false;
            }

            TaskScheduler.CreateTask(() =>
            {
                hide.SetActive(false);
                show.SetActive(true);

                foreach (var card in hide.GetComponentsInChildren <CharacterCard>(true))
                {
                    card.transform.localRotation = Quaternion.Euler(0, 0, 0);
                }

                foreach (var card in show.GetComponentsInChildren <CharacterCard>(true))
                {
                    card.transform.localRotation = Quaternion.Euler(0, 90, 0);
                    TweenRotation.Begin(card.gameObject, speed, Quaternion.Euler(0, 0, 0));
                }
            }, speed);

            Get <AudioPlayer>().PlaySwap();
        }
Esempio n. 4
0
        public void Refresh()
        {
            if (Engine.Level.Type == LevelType.Memo)
            {
                return;
            }

            var characters = FindObjectsOfType <Character>().Where(i => i.Table == this).ToList();
            var sympathy   = GetSympathy(characters[0].Person, characters[1].Person);

            characters[0].Busy     = characters[1].Busy = true;
            characters[0].Sympathy = characters[1].Sympathy = 1;

            for (var i = 0; i < 3; i++)
            {
                TweenAlpha.Begin(Hearts[i].gameObject, TweenTime, 0);
            }

            TaskScheduler.CreateTask(() =>
            {
                Progress.Show(TweenTime);
                Progress.Animate(Settings.SwapDelay);
                TaskScheduler.CreateTask(() => ShowSympathy(characters[0], characters[1], sympathy), Engine.TaskId, Settings.SwapDelay);
            }, Engine.TaskId, TweenTime);
        }
Esempio n. 5
0
        public void ContiniousPlay()
        {
            if (!MusicAudioSource.isPlaying && MusicAudioSource.clip != null)
            {
                PlayMusicNext(GameMusic.Ingame);
            }

            TaskScheduler.CreateTask(ContiniousPlay, Id, 2);
        }
Esempio n. 6
0
 public void Continue()
 {
     TaskScheduler.CreateTask(() => CreateWind(Random.Range(0, 2)), Id, 2);
     Stage.transform.localPosition = new Vector3(0, -15, 0);
     TweenPosition.Begin(Stage, 0.5f, new Vector3(0, 0, 0));
     UI.OpenIngame();
     Panda.Continue();
     _continue = true;
     _ballTimes.Clear();
 }
Esempio n. 7
0
 public void Play()
 {
     TaskScheduler.CreateTask(() => CreateWind(0), Id, 3);
     UI.OpenIngame();
     Panda.Reset();
     _progress = 0;
     _continue = false;
     _ballTimes.Clear();
     AppMetrica.Instance.ReportEvent("Play");
 }
Esempio n. 8
0
        private void Evade()
        {
            if (!Colliders[0].enabled)
            {
                return;
            }

            SetReflection(-_evasion);
            Animator.Play(EvadeAnimation.name);
            TaskScheduler.CreateTask(Stand, Id, EvadeAnimation.length);
        }
Esempio n. 9
0
        private void PlayInGameNext(AudioClip clip)
        {
            AudioSource.Stop();
            AudioSource.clip = clip;
            AudioSource.loop = false;
            AudioSource.Play();

            var nexts = Music.Where(i => i != clip).ToList();
            var next  = nexts[CRandom.GetRandom(0, nexts.Count)];

            TaskScheduler.Kill(888);
            TaskScheduler.CreateTask(() => PlayInGameNext(next), 888, clip.length);
        }
Esempio n. 10
0
        public void Open(Action callback = null)
        {
            var prev = Current;

            Current = null;
            GetComponent <Loading>().Open(LoadingTime);
            TaskScheduler.CreateTask(() => DelayedOpen(callback), LoadingTime);

            if (prev != null && !ReferenceEquals(prev, this))
            {
                TaskScheduler.CreateTask(prev.Close, LoadingTime);
            }
        }
Esempio n. 11
0
        public void Abort()
        {
            Time.timeScale = 1;
            AbortButton.GetComponent <GameButton>().Enabled = false;
            PauseButton.GetComponent <GameButton>().Enabled = false;

            Engine.Panda.Fall();

            TaskScheduler.CreateTask(() => { Engine.Abort(); OpenMenu(); }, Id, 2);

            foreach (var panel in IngamePanels)
            {
                panel.Hide();
            }
        }
Esempio n. 12
0
        private void ShowSympathy(Character character1, Character character2, int sympathy)
        {
            Progress.Hide(TweenTime);

            TaskScheduler.CreateTask(() =>
            {
                for (var i = 0; i < 3; i++)
                {
                    TweenAlpha.Begin(Hearts[i].gameObject, TweenTime, sympathy >= i + 1 ? 1 : 0);
                }

                character1.Sympathy = character2.Sympathy = sympathy;
            }, Engine.TaskId, TweenTime);

            character1.Busy = character2.Busy = false;

            if (sympathy >= 3)
            {
                TaskScheduler.CreateTask(() =>
                {
                    character1.PositionSpring.enabled = character2.PositionSpring.enabled = true;
                    Find <AudioPlayer>().PlayBlink();
                }, 0.5f);
            }

            if (FindObjectsOfType <Character>().Any(i => i.Busy) || Engine.State != GameState.Playing)
            {
                return;
            }

            Find <Play>().RefreshScore();

            if (Engine.CalcScore() >= Engine.Level.Target && Engine.Level.Target != -1)
            {
                Engine.State = GameState.Ready;
                TaskScheduler.CreateTask(Find <AudioPlayer>().PlaySuccess, Engine.TaskId, 0.5f);
                TaskScheduler.CreateTask(Find <Engine>().CompleteGame, Engine.TaskId, 2f);
            }
            else if (Engine.Level.Type == LevelType.Swap)
            {
                var swapsleft = Engine.Level.Swaps - Engine.Swaps;

                if (swapsleft <= 0)
                {
                    TaskScheduler.CreateTask(Find <Engine>().CompleteGame, Engine.TaskId, 1);
                }
            }
        }
Esempio n. 13
0
        public void OpenIngame()
        {
            foreach (var p in MenuPanels)
            {
                p.Hide();
            }

            AbortButton.GetComponent <GameButton>().Enabled = true;
            PauseButton.GetComponent <GameButton>().Enabled = true;

            TaskScheduler.CreateTask(() => { foreach (var panel in IngamePanels)
                                             {
                                                 panel.Show();
                                             }
                                     }, Id, 0.5f);
        }
Esempio n. 14
0
        public void OnTriggerEnter2D(Collider2D c)
        {
            if (_hit != 0)
            {
                return;
            }

            var sign = Math.Sign(c.GetComponent <Rigidbody2D>().velocity.x);
            var ball = c.name.Split('/')[1].ToEnum <BallId>();

            if (Math.Sign(_evasion) == sign)
            {
                UI.UpdateScore(++Score);
                AudioPlayer.Instance.PlayEffect(AudioPlayer.Instance.Swing);
            }
            else
            {
                Hearts -= 1;

                if (ball == BallId.Rugby)
                {
                    Hearts -= 1;
                }

                UI.UpdateHearts(Hearts);
                c.gameObject.GetComponent <Ball>().Recoil(-sign);
                _hit = -sign;
                SetReflection(_hit);

                if (Hearts >= 0)
                {
                    TaskScheduler.Kill(Id);
                    Animator.Play(HitAnimation.name);
                    AudioPlayer.Instance.PlayEffect(AudioPlayer.Instance.Hit);
                    TaskScheduler.CreateTask(Stand, Id, HitAnimation.length);
                }
                else
                {
                    Item = ball;
                    TaskScheduler.Kill(Id);
                    Animator.Play(FallAnimation.name);
                    AudioPlayer.Instance.PlayEffect(AudioPlayer.Instance.Fall);
                    Beads.Fall();
                    TaskScheduler.CreateTask(() => Engine.Stop(Score), Id, 2);
                }
            }
        }
Esempio n. 15
0
        public void Swapped()
        {
            Swaps++;

            if (Level.Type == LevelType.Memo)
            {
                var formation = GetFormation();

                Debug.Log(formation);

                if (formation == Level.FormationHash)
                {
                    TaskScheduler.CreateTask(Find <AudioPlayer>().PlaySuccess, TaskId, 0f);
                    TaskScheduler.CreateTask(Find <Engine>().CompleteGame, TaskId, 1f);
                }
            }
        }
Esempio n. 16
0
        public void StartGame(bool restart = false)
        {
            Level.Restart = restart;

            TaskScheduler.Kill(TaskId++);

            State = GameState.Ready;

            var play = Get <Play>();

            play.Open(BeginGame);

            if ((Level.Type == LevelType.Easy || Level.Type == LevelType.Swap || Level.Type == LevelType.Memo) && Level.Progress == 0)
            {
                TaskScheduler.CreateTask(() => PauseGame(play.HelpDialog), TaskId, 1);
            }
        }
Esempio n. 17
0
        private void SetLaunchOnWindowsStart(bool enable)
        {
            var has_task = LaunchOnWindowsStart;

            if (enable == has_task)
            {
                return;
            }

            if (enable)
            {
                TaskScheduler.CreateTask(TASK_NAME, TASK_INPUT_FILE);
            }
            else
            {
                TaskScheduler.DeleteTask(TASK_NAME);
            }
        }
Esempio n. 18
0
    private void Tween(bool show, float timeout, TweenDirection tweenDirection)
    {
        Vector3 vector;

        if (show)
        {
            vector = Vector3.zero;
        }
        else
        {
            if (UseCustomTweenPosition)
            {
                vector = new Vector2(CustomTweenPosition.x * transform.localScale.x, CustomTweenPosition.y * transform.localScale.y);
            }
            else
            {
                vector = GetVector(tweenDirection, 1000 * Camera.main.aspect);
            }
        }

        if (Math.Abs(timeout - 0) < 0.001f)
        {
            transform.localPosition = vector;
        }
        else
        {
            var tweenPosition = GetComponent <TweenPosition>();

            if (tweenPosition != null)
            {
                var animationCurve = tweenPosition.animationCurve;

                TweenPosition.Begin(gameObject, timeout, vector).animationCurve = animationCurve;
            }
            else
            {
                TweenPosition.Begin(gameObject, timeout, vector);
            }
        }

        TweenAlpha.Begin(gameObject, timeout / 2, show ? 1 : 0);
        TaskScheduler.CreateTask(() => gameObject.SetActive(show), show ? 0 : timeout);
    }
Esempio n. 19
0
        public void ScheduleFix()
        {
            if (Time.timeScale > 0)
            {
                var nexts = Music.Where(i => i != AudioSource.clip).ToList();
                var next  = nexts[CRandom.GetRandom(0, nexts.Count)];

                if (AudioSource.isPlaying)
                {
                    TaskScheduler.Kill(888);
                    TaskScheduler.CreateTask(() => PlayInGameNext(next), 888, AudioSource.clip.length - AudioSource.time);
                }
                else
                {
                    PlayInGameNext(next);
                }
            }
            else
            {
                TaskScheduler.Kill(888);
            }
        }
Esempio n. 20
0
        public void CompleteGame()
        {
            Debug.Log("Profile.ShowAdTime=" + Profile.ShowAdTime);

            if (DateTime.UtcNow > Profile.ShowAdTime.AddSeconds(300) || Settings.Debug)
            {
                if (Advertisement.isSupported && Advertisement.IsReady() && !Profile.Deluxe)
                {
                    Advertisement.Show();
                    Profile.ShowAdTime = DateTime.UtcNow;
                    TaskScheduler.CreateTask(CompleteGameNoAds, 0.2f);
                }
                else
                {
                    CompleteGameNoAds();
                }
            }
            else
            {
                CompleteGameNoAds();
            }
        }
Esempio n. 21
0
        public void ShowAds()
        {
            ContinuePanel.Hide();

            TaskScheduler.CreateTask(() =>
            {
                Advertisement.Show("rewardedVideo", new ShowOptions
                {
                    resultCallback = result =>
                    {
                        if (result == ShowResult.Finished)
                        {
                            TaskScheduler.CreateTask(Engine.Continue, Id, 1);
                            AppMetrica.Instance.ReportEvent("AdWatch");
                        }
                        else
                        {
                            TaskScheduler.CreateTask(ContinuePanel.Show, Id, 1);
                        }
                    }
                });
            }, Id, 1);
        }
Esempio n. 22
0
 public void AnimateRight()
 {
     Animator.Play(RightAnimation.name);
     TaskScheduler.CreateTask(Stand, Id, RightAnimation.length);
 }
Esempio n. 23
0
        public void CreateBall(int side)
        {
            const float returnTime = 1;

            var collection = new List <BallId>();

            var order = new[]
            {
                BallId.Beach,
                BallId.Tennis,
                BallId.Tomato,
                BallId.Boomerang,
                BallId.Rugby,
                BallId.Football,
                BallId.Banana,
                BallId.Lifebuoy,
                BallId.Boomerang,
                BallId.ToiletPaper,
                BallId.Cactus,
                BallId.LightBeer,
                BallId.Bread,
                BallId.Icecream,
                BallId.Football,
                BallId.Hammer,
                BallId.PremiumBeer,
                BallId.Pokeball,
                BallId.Grenade,
                BallId.Cactus
            };

            var distribution = new Dictionary <BallId, int>
            {
                { order[0], 1 },
                { order[1], 1 },
                { order[2], 1 }
            };

            for (var i = 1; i < order.Length - 3; i++)
            {
                if (_progress > 5 * i)
                {
                    if (distribution.ContainsKey(order[i]))
                    {
                        distribution[order[i]]++;
                    }
                    else
                    {
                        distribution.Add(order[i], 1);
                    }
                }
                else
                {
                    break;
                }
            }

            foreach (var item in distribution)
            {
                for (var i = 0; i < item.Value; i++)
                {
                    collection.Add(item.Key);
                }
            }

            var ballId = collection[CRandom.GetRandom(collection.Count)];
            var ball   = CreateBall(ballId, side);

            switch (ballId)
            {
            case BallId.Boomerang:
                TaskScheduler.CreateTask(() => { if (Panda.Hearts >= 0 && !ball.Hit)
                                                 {
                                                     CreateBall(BallId.Boomerang, side == 0 ? 1 : 0);
                                                 }
                                         }, Id, returnTime);
                _ballTimes.Add(Time.time + returnTime);
                break;

            case BallId.Pokeball:
                TaskScheduler.CreateTask(() => { if (Panda.Hearts >= 0 && !ball.Hit)
                                                 {
                                                     CreateBall(BallId.Pikachu, side == 0 ? 1 : 0);
                                                 }
                                         }, Id, returnTime);
                _ballTimes.Add(Time.time + returnTime);
                break;

            case BallId.Football:
                TaskScheduler.CreateTask(() => { if (Panda.Hearts >= 0)
                                                 {
                                                     CreateBall(BallId.Shoe, side);
                                                 }
                                         }, Id, returnTime);
                _ballTimes.Add(Time.time + returnTime);
                break;

            case BallId.Cactus:
                TaskScheduler.CreateTask(() => { if (Panda.Hearts >= 0)
                                                 {
                                                     CreateBall(BallId.Flowerpot, side);
                                                 }
                                         }, Id, returnTime);
                _ballTimes.Add(Time.time + returnTime);
                break;
            }

            _progress++;
            _ballTimes.Add(Time.time);
        }
Esempio n. 24
0
 public void Fall()
 {
     BeadAnimator.Play(BeadFallAnimation.name);
     TaskScheduler.Kill(Id);
     TaskScheduler.CreateTask(() => BeadAnimator.Play(BeadStandAnimation.name), Id, BeadFallAnimation.length);
 }
Esempio n. 25
0
        protected override void OnPress(bool down)
        {
            const float tweenTime = 0.2f;

            if ((Engine.State != GameState.Playing && down) || Busy || !Engine.CanShift || Engine.Level.Memorize)
            {
                return;
            }

            base.OnPress(down);

            _delta = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;

            if (down)
            {
                _image.depth = 50;
            }
            else
            {
                _image.depth = 0;

                var characters = FindObjectsOfType <Character>().ToList();

                characters.Remove(this);

                Character nearest     = null;
                var       minDistance = float.MaxValue;

                foreach (var character in characters)
                {
                    var distance = Vector2.Distance(transform.parent.localPosition / transform.parent.localScale.x
                                                    + transform.localPosition, character.transform.parent.localPosition / character.transform.parent.localScale.x + character.transform.localPosition);

                    if (distance < 200 && distance < minDistance)
                    {
                        nearest     = character;
                        minDistance = distance;
                    }
                }

                if (nearest == null || nearest.Busy)
                {
                    TweenPosition.Begin(gameObject, tweenTime, Position);
                }
                else
                {
                    var transformParent = nearest.transform.parent;
                    nearest.transform.parent = transform.parent;
                    transform.parent         = transformParent;

                    TweenPosition.Begin(gameObject, tweenTime, nearest.Position);
                    TweenPosition.Begin(nearest.gameObject, tweenTime, Position);

                    var pos = Position;

                    Position         = nearest.Position;
                    nearest.Position = pos;

                    var table = Table;

                    Table         = nearest.Table;
                    nearest.Table = table;

                    Flip();
                    nearest.Flip();

                    if (Table != nearest.Table)
                    {
                        Table.Refresh();
                        nearest.Table.Refresh();
                        Find <Engine>().Swapped();
                    }

                    TaskScheduler.CreateTask(() => nearest.PositionSpring.enabled = true, tweenTime);
                }

                TaskScheduler.CreateTask(() => PositionSpring.enabled = true, tweenTime);
            }
        }
Esempio n. 26
0
 public void AnimateLeft()
 {
     Animator.Play(LeftAnimation.name);
     TaskScheduler.CreateTask(Stand, Id, LeftAnimation.length);
 }