Exemple #1
0
    public void OnHomePressed()
    {
        Services.AudioManager.CreateTrackAndPlay(Clips.TAP);
        Services.AudioManager.FadeAudio();
        Services.EventManager.Fire(new RefreshGameBaord());

        Task fadeIndicatorIconTask = new LERPColor(_turnIndicatorIcon, _turnIndicatorIcon.color, _transparent, 0.5f);
        Task fadeIndicatorTextTask = new LERPColor(_turnIndicator, _turnIndicator.color, _transparent, 0.5f);
        Task fadeHomeButtonTask    = new LERPColor(_homeButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeReplayButtonTask  = new LERPColor(_replayButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeGradient          = new LERPColor(_gradient, _gradient.color, _transparent, 0.75f);

        // This is the smae idea found in the OnRestartPressed function above
        TaskTree returnHomeTasks = new TaskTree(new EmptyTask(),
                                                new TaskTree(fadeIndicatorIconTask),
                                                new TaskTree(fadeIndicatorTextTask),
                                                new TaskTree(fadeHomeButtonTask),
                                                new TaskTree(fadeReplayButtonTask),
                                                new TaskTree(fadeGradient),
                                                new TaskTree(new BoardEntryAnimation()),
                                                new TaskTree(new Wait(3),
                                                             new TaskTree(new ActionTask(ReturnHome))));

        _tm.Do(returnHomeTasks);
    }
Exemple #2
0
    public void OnRestartPressed()
    {
        Services.AudioManager.CreateTrackAndPlay(Clips.TAP);
        Services.AudioManager.FadeAudio();
        Services.EventManager.Fire(new RefreshGameBaord());

        Task fadeIndicatorIconTask = new LERPColor(_turnIndicatorIcon, _turnIndicatorIcon.color, _transparent, 0.5f);
        Task fadeIndicatorTextTask = new LERPColor(_turnIndicator, _turnIndicator.color, _transparent, 0.5f);
        Task fadeHomeButtonTask    = new LERPColor(_homeButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeReplayButtonTask  = new LERPColor(_replayButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeGradient          = new LERPColor(_gradient, _gradient.color, _transparent, 0.75f);

        //  Here we have a modification of the Task tree where we want to compelte the fading
        //  board animation and waiting tasks in parallel, than compete the ResetGameScene Task.
        //  To accomplish this, I made the ResetGameScene Task a child of the Wait task.
        TaskTree restartGameTasks = new TaskTree(new EmptyTask(),
                                                 new TaskTree(fadeIndicatorIconTask),
                                                 new TaskTree(fadeIndicatorTextTask),
                                                 new TaskTree(fadeHomeButtonTask),
                                                 new TaskTree(fadeReplayButtonTask),
                                                 new TaskTree(fadeGradient),
                                                 new TaskTree(new BoardEntryAnimation()),
                                                 new TaskTree(new Wait(3),
                                                              new TaskTree(new ActionTask(ResetGameScene))));

        _tm.Do(restartGameTasks);
    }
Exemple #3
0
 public void OnGameEnd(GameEndEvent e)
 {
     endGame = true;
     if (e.winner != null)
     {
         float pitch = e.winner.playerNum == 0 ? 0.8f : 2f;
         Services.AudioManager.CreateTrackAndPlay(Clips.WIN, pitch);
         _turnIndicatorIcon.sprite = e.winner.PlayerIcon;
         _turnIndicatorIcon.color  = e.winner.playerColor[0];
         _turnIndicator.color      = e.winner.playerColor[0];
         _turnIndicator.text       = "    WINS";
         WinnerConfetti winnerConfetti = Instantiate(Services.Prefabs.WinnerConfetti);
         winnerConfetti.Init(e.winner);
         Task fadeGradient = new LERPColor(_gradient, _transparent, e.winner.playerColor[0], 0.75f);
         _tm.Do(fadeGradient);
     }
     else
     {
         Services.AudioManager.CreateTrackAndPlay(Clips.TIE);
         _turnIndicatorIcon.color = new Color(0, 0, 0, 0);
         _turnIndicator.color     = new Color(127 / 256f, 127 / 256f, 127 / 256f);
         _turnIndicator.text      = "TIE GAME";
         Task fadeGradient = new LERPColor(_gradient, _transparent, _iconGray, 0.75f);
         _tm.Do(fadeGradient);
     }
 }
Exemple #4
0
    public void FadeOutFlockAgents()
    {
        TaskTree fadeAgents = new TaskTree(new EmptyTask());

        foreach (FlockAgent agent in _agents)
        {
            Task fadeOut = new LERPColor(agent.sr, agent.sr.color, _transparent, 0.3f);
            fadeAgents.AddChild(fadeOut);
        }
        _tm.Do(fadeAgents);
    }
    public void StartGame()
    {
        hasLoadGame = false;
        TaskQueue startGameTasks = new TaskQueue();
        Task      slideTitleOut  = new TitleEntryAnimation(titleText, true);
        Task      fadeStartText  = new LERPColor(buttonText, buttonText[0].color, transparent, 0.3f);
        Task      beginGame      = new ActionTask(TransitionToGame);

        startGameTasks.Add(fadeStartText);
        startGameTasks.Add(slideTitleOut);
        startGameTasks.Add(beginGame);

        _tm.Do(startGameTasks);
    }
Exemple #6
0
    public void StartGame()
    {
        Services.AudioManager.CreateTrackAndPlay(Clips.TAP);
        Services.AudioManager.FadeAudio();

        hasLoadGame = false;
        TaskQueue startGameTasks = new TaskQueue();
        Task      slideTitleOut  = new TitleEntryAnimation(titleText, true);
        Task      fadeStartText  = new LERPColor(buttonText, buttonText[0].color, transparent, 0.3f);
        Task      fadeFlockX     = new ActionTask(_flocks[0].FadeOutFlockAgents);
        Task      fadeFlockO     = new ActionTask(_flocks[1].FadeOutFlockAgents);
        Task      beginGame      = new ActionTask(TransitionToGame);

        startGameTasks.Add(fadeStartText);
        startGameTasks.Add(fadeFlockO);
        startGameTasks.Add(fadeFlockX);
        startGameTasks.Add(slideTitleOut);
        startGameTasks.Add(beginGame);

        _tm.Do(startGameTasks);
    }
    public void OnHomePressed()
    {
        Services.EventManager.Fire(new RefreshGameBaord());

        Task fadeIndicatorIconTask = new LERPColor(_turnIndicatorIcon, _turnIndicatorIcon.color, _transparent, 0.5f);
        Task fadeIndicatorTextTask = new LERPColor(_turnIndicator, _turnIndicator.color, _transparent, 0.5f);
        Task fadeHomeButtonTask    = new LERPColor(_homeButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeReplayButtonTask  = new LERPColor(_replayButtonIcon, _iconGray, _transparent, 0.5f);
        Task fadeGradient          = new LERPColor(_gradient, _gradient.color, _transparent, 0.75f);

        TaskTree returnHomeTasks = new TaskTree(new EmptyTask(),
                                                new TaskTree(fadeIndicatorIconTask),
                                                new TaskTree(fadeIndicatorTextTask),
                                                new TaskTree(fadeHomeButtonTask),
                                                new TaskTree(fadeReplayButtonTask),
                                                new TaskTree(fadeGradient),
                                                new TaskTree(new BoardEntryAnimation()),
                                                new TaskTree(new Wait(3),
                                                             new TaskTree(new ActionTask(ReturnHome))));

        _tm.Do(returnHomeTasks);
    }
Exemple #8
0
    public void FadeInFlockAgents()
    {
        TaskTree fadeAgents = new TaskTree(new EmptyTask());

        Color targetColor;

        if (_icon == FlockIcon.X)
        {
            targetColor = Services.GameManager.Player1Color[1];
        }
        else
        {
            targetColor = Services.GameManager.Player2Color[1];
        }

        foreach (FlockAgent agent in _agents)
        {
            Task fadeOut = new LERPColor(agent.sr, _transparent, targetColor, 0.3f);
            fadeAgents.AddChild(fadeOut);
        }
        _tm.Do(fadeAgents);
    }
 public void OnGameEnd(GameEndEvent e)
 {
     endGame = true;
     if (e.winner != null)
     {
         _turnIndicatorIcon.sprite = e.winner.PlayerIcon;
         _turnIndicatorIcon.color  = e.winner.playerColor[0];
         _turnIndicator.color      = e.winner.playerColor[0];
         _turnIndicator.text       = "    WINS";
         WinnerConfetti winnerConfetti = Instantiate(Services.Prefabs.WinnerConfetti);
         winnerConfetti.Init(e.winner);
         Task fadeGradient = new LERPColor(_gradient, _transparent, e.winner.playerColor[0], 0.75f);
         _tm.Do(fadeGradient);
     }
     else
     {
         _turnIndicatorIcon.color = new Color(0, 0, 0, 0);
         _turnIndicator.color     = new Color(127 / 256f, 127 / 256f, 127 / 256f);
         _turnIndicator.text      = "TIE GAME";
         Task fadeGradient = new LERPColor(_gradient, _transparent, _iconGray, 0.75f);
         _tm.Do(fadeGradient);
     }
 }
    internal override void OnEnter(TransitionData data)
    {
        Services.GameScene = this;
        players            = new Player[Services.GameManager.TotalPlayers];
        for (int i = 0; i < Services.GameManager.TotalPlayers; i++)
        {
            players[i] = Instantiate(Services.Prefabs.Player, Vector3.zero, Quaternion.identity, transform);
            int playerNum = i + 1;
            players[i].name = "Player " + playerNum;
            Color[] colors;
            switch (i)
            {
            case 0: colors = Services.GameManager.Player1Color; break;

            case 1: colors = Services.GameManager.Player2Color; break;

            default: colors = Services.GameManager.Player1Color; break;
            }
            players[i].Init(playerNum, Services.GameManager.AvailableIcons[i], colors);
        }

        board = GetComponent <GameBoard>();
        BoardInfo info;

        info.row = 3;
        info.col = 3;


        board.Init(info);

        currentPlayerIndex = UnityEngine.Random.Range(0, 2);
        currentPlayer      = players[currentPlayerIndex];

        if (currentPlayerIndex == 0)
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER1;
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER1].PlayerIcon;
        }
        else
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER2;
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER2].PlayerIcon;
        }

        Task fadeIndicatorIconTask = new LERPColor(_turnIndicatorIcon, _transparent, currentPlayer.playerColor[0], 3f);
        Task fadeIndicatorTextTask = new LERPColor(_turnIndicator, _transparent, currentPlayer.playerColor[0], 3f);
        Task fadeHomeButtonTask    = new LERPColor(_homeButtonIcon, _transparent, _iconGray, 1f);
        Task fadeReplayButtonTask  = new LERPColor(_replayButtonIcon, _transparent, _iconGray, 1f);


        TaskTree uiEntryTask = new TaskTree(new EmptyTask(),
                                            new TaskTree(fadeIndicatorIconTask),
                                            new TaskTree(fadeIndicatorTextTask),
                                            new TaskTree(fadeHomeButtonTask),
                                            new TaskTree(fadeReplayButtonTask));

        _tm.Do(uiEntryTask);

        Services.EventManager.Register <PlayMadeEvent>(OnPlayMade);
        Services.EventManager.Register <GameEndEvent>(OnGameEnd);
    }
Exemple #11
0
    internal override void OnEnter(TransitionData data)
    {
        Services.AudioManager.StopClip();
        if (!Services.AudioManager.muted)
        {
            Services.AudioManager.SetVolume(0.5f);
        }
        Services.AudioManager.PlayClip(Clips.MATCH_SONG);
        Services.GameManager.UpdateMutIcon(audioStatusIcon);

        Services.GameScene = this;
        players            = new Player[Services.GameManager.TotalPlayers];
        for (int i = 0; i < Services.GameManager.TotalPlayers; i++)
        {
            players[i] = Instantiate(Services.Prefabs.Player, Vector3.zero, Quaternion.identity, transform);
            int playerNum = i + 1;
            players[i].name = "Player " + playerNum;
            Color[] colors;
            switch (i)
            {
            case 0: colors = Services.GameManager.Player1Color; break;

            case 1: colors = Services.GameManager.Player2Color; break;

            default: colors = Services.GameManager.Player1Color; break;
            }
            players[i].Init(playerNum, Services.GameManager.AvailableIcons[i], colors);
        }

        board = GetComponent <GameBoard>();
        BoardInfo info;

        info.row = 3;
        info.col = 3;


        board.Init(info);

        currentPlayerIndex = UnityEngine.Random.Range(0, 2);
        currentPlayer      = players[currentPlayerIndex];

        if (currentPlayerIndex == 0)
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER1;
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER1].PlayerIcon;
        }
        else
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER2;
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER2].PlayerIcon;
        }

        // These are independent tasks I want to complete when entering the game scene
        Task fadeIndicatorIconTask = new LERPColor(_turnIndicatorIcon, _transparent, currentPlayer.playerColor[0], 3f);
        Task fadeIndicatorTextTask = new LERPColor(_turnIndicator, _transparent, currentPlayer.playerColor[0], 3f);
        Task fadeHomeButtonTask    = new LERPColor(_homeButtonIcon, _transparent, _iconGray, 1f);
        Task fadeReplayButtonTask  = new LERPColor(_replayButtonIcon, _transparent, _iconGray, 1f);

        // I want to compelte these tasks in parallel so I use a TaskTree.
        // How it works:
        //              A Task tree will complete the Task at its root first, then move on to complete
        //              the tasks in in child nodes in parallel.
        TaskTree uiEntryTask = new TaskTree(new EmptyTask(),
                                            new TaskTree(fadeIndicatorIconTask),
                                            new TaskTree(fadeIndicatorTextTask),
                                            new TaskTree(fadeHomeButtonTask),
                                            new TaskTree(fadeReplayButtonTask));

        _tm.Do(uiEntryTask);

        Services.EventManager.Register <PlayMadeEvent>(OnPlayMade);
        Services.EventManager.Register <GameEndEvent>(OnGameEnd);
    }