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)); }
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); }
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(); }
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); }
public void ContiniousPlay() { if (!MusicAudioSource.isPlaying && MusicAudioSource.clip != null) { PlayMusicNext(GameMusic.Ingame); } TaskScheduler.CreateTask(ContiniousPlay, Id, 2); }
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(); }
public void Play() { TaskScheduler.CreateTask(() => CreateWind(0), Id, 3); UI.OpenIngame(); Panda.Reset(); _progress = 0; _continue = false; _ballTimes.Clear(); AppMetrica.Instance.ReportEvent("Play"); }
private void Evade() { if (!Colliders[0].enabled) { return; } SetReflection(-_evasion); Animator.Play(EvadeAnimation.name); TaskScheduler.CreateTask(Stand, Id, EvadeAnimation.length); }
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); }
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); } }
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(); } }
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); } } }
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); }
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); } } }
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); } } }
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); } }
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); } }
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); }
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); } }
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(); } }
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); }
public void AnimateRight() { Animator.Play(RightAnimation.name); TaskScheduler.CreateTask(Stand, Id, RightAnimation.length); }
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); }
public void Fall() { BeadAnimator.Play(BeadFallAnimation.name); TaskScheduler.Kill(Id); TaskScheduler.CreateTask(() => BeadAnimator.Play(BeadStandAnimation.name), Id, BeadFallAnimation.length); }
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); } }
public void AnimateLeft() { Animator.Play(LeftAnimation.name); TaskScheduler.CreateTask(Stand, Id, LeftAnimation.length); }