Exemple #1
0
    // +++ Event handler ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    private void OnPlayerScores(object sender, EventArgs e)
    {
        var ea = (StringEventArgs)e;

        if (ea.Value == "left")
        {
            GameController.PLAYERLEFTSCORE++;
        }
        else if (ea.Value == "right")
        {
            GameController.PLAYERRIGHTSCORE++;
        }

        var eventArgs = new ScoreEventArgs
        {
            scoreLeftPlayer  = GameController.PLAYERLEFTSCORE,
            scoreRightPlayer = GameController.PLAYERRIGHTSCORE
        };

        // trigger in game event
        NvpEventBus.Events(GameEvents.OnScoreChanged).TriggerEvent(this, eventArgs);

        // trigger State transition
        if (GameController.PLAYERLEFTSCORE < 11 && GameController.PLAYERRIGHTSCORE < 11)
        {
            NvpEventBus.Events(GameEvents.OnTransitionToServeState).TriggerEvent(this, null);
        }
        else
        {
            NvpEventBus.Events(GameEvents.OnTransitionToGameOver).TriggerEvent(this, null);
        }
    }
 public override void UpdateState()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         NvpEventBus.Events(GameEvents.OnTransitionToRunState).TriggerEvent(this, null);
     }
 }
 private void OnDisable()
 {
     NvpEventBus.Events(GameEvents.OnPlayerScores).GameEventHandler     -= OnPlayerScores;
     NvpEventBus.Events(GameEvents.OnPlayerHitsPipe).GameEventHandler   -= OnPlayerHitsPipe;
     NvpEventBus.Events(GameEvents.OnGameOverFinished).GameEventHandler -= OnGameOverFinished;
     _nvpStateMachine.Dispose();
 }
Exemple #4
0
 // +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void FixedUpdate()
 {
     if (Input.GetMouseButtonUp(0))
     {
         NvpEventBus.Events(GameEvents.OnPlayerJumps).TriggerEvent(null, null);
     }
 }
Exemple #5
0
 public void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         var ea = new GenericEventArgs(NvpGameStatesEnum.CountDown);
         NvpEventBus.Events(GameEvents.OnChangeGameState).TriggerEvent(this, ea);
     }
 }
Exemple #6
0
    // +++ state methods ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public void Enter()
    {
        Debug.Log("Enter Countdown State");
        _timer         = 1f;
        _secondDisplay = 3;

        // change ui
        NvpEventBus.Events(GameEvents.OnUIChanged).TriggerEvent(this, new GenericEventArgs(UiNames.countdown));
    }
    private void OnDisable()
    {
        NvpEventBus.Events(GameEvents.OnClearScoreboard).GameEventHandler -= OnClearScoreboard;
        NvpEventBus.Events(GameEvents.OnServeBall).GameEventHandler       -= OnState_Serve_Entered;
        NvpEventBus.Events(GameEvents.OnLaunchBall).GameEventHandler      -= OnBallLaunch;
        NvpEventBus.Events(GameEvents.OnGameOver).GameEventHandler        -= OnGameOver;

        NvpEventBus.Events(GameEvents.OnScoreChanged).GameEventHandler -= OnPlayerScores;
    }
    public void Update()
    {
        timer += Time.deltaTime;

        if (timer > 10 || Input.GetMouseButtonUp(1))
        {
            NvpEventBus.Events(GameEvents.OnGameOverFinished).TriggerEvent(this, null);
        }
    }
    public void Enter()
    {
        Debug.Log("Enter Game Over State");

        var ea = new GenericEventArgs(UiNames.gameover);

        NvpEventBus.Events(GameEvents.OnUIChanged).TriggerEvent(this, ea);
        timer = 0;
    }
Exemple #10
0
    public override void EnterState()
    {
        var ea = new ScoreEventArgs
        {
            scoreLeftPlayer  = GameController.PLAYERLEFTSCORE,
            scoreRightPlayer = GameController.PLAYERRIGHTSCORE
        };

        NvpEventBus.Events(GameEvents.OnGameOver).TriggerEvent(this, ea);
    }
    private void OnGameOverFinished(object sender, EventArgs e)
    {
        Score = 0;

        NvpEventBus.Events(GameEvents.OnResetPipes).TriggerEvent(this, null);

        var stateTransitionEventArgs = new GenericEventArgs(NvpGameStatesEnum.Title);

        NvpEventBus.Events(GameEvents.OnChangeGameState).TriggerEvent(this, stateTransitionEventArgs);
    }
    public override void EnterState()
    {
        var ea = new DefaultEventArgs
        {
            Value = GameController.CURRENTPLAYER
        };

        NvpEventBus.Events(GameEvents.OnServeBall).TriggerEvent(this, ea);
        Update = UpdateState;
    }
    public override void ExitState()
    {
        var ea = new DefaultEventArgs
        {
            Value = GameController.CURRENTPLAYER
        };

        if (Input.GetKeyDown(KeyCode.Space))
        {
            NvpEventBus.Events(GameEvents.OnLaunchBall).TriggerEvent(this, ea);
        }
    }
Exemple #14
0
    // +++ state methods ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public void Enter()
    {
        Debug.Log("Enter Title State");

        // instantiate new bird
        var bird = Object.Instantiate(_birdPrefab, Vector3.zero, Quaternion.identity);

        // request Title screen
        NvpEventBus.Events(GameEvents.OnUIChanged).TriggerEvent(this, new GenericEventArgs(UiNames.title));

        // pause Game
        NvpEventBus.Events(GameEvents.OnPauseGame).TriggerEvent(this, new GenericEventArgs(true));
    }
Exemple #15
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        var ea = new GenericEventArgs(this.transform.position);

        if (collision.tag == "ScoreTrigger")
        {
            NvpEventBus.Events(GameEvents.OnPlayerScores).TriggerEvent(this, ea);
        }

        if (collision.tag == "Pipe")
        {
            NvpEventBus.Events(GameEvents.OnPlayerHitsPipe).TriggerEvent(this, ea);
            NvpEventBus.Events(GameEvents.OnPauseGame).TriggerEvent(this, new GenericEventArgs(true));
        }
    }
    // +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    private void OnEnable()
    {
        _nvpStateMachine = new NvpStateMachine_Builder()
                           .AddGameState(NvpGameStatesEnum.Idle, new NvpGameState_IdleState())
                           .AddGameState(NvpGameStatesEnum.Title, new NvpGameState_TitleState(birdPrefab))
                           .AddGameState(NvpGameStatesEnum.CountDown, new NvpGameState_CountDownState())
                           .AddGameState(NvpGameStatesEnum.Play, new NvpGameState_PlayState())
                           .AddGameState(NvpGameStatesEnum.Score, new NvpGameState_ScoreState())
                           .AddGameState(NvpGameStatesEnum.GameOver, new NvpGameState_GameOverState())
                           .Build();

        _nvpStateMachine.DoStateTransition(NvpGameStatesEnum.Title);

        NvpEventBus.Events(GameEvents.OnPlayerScores).GameEventHandler     += OnPlayerScores;
        NvpEventBus.Events(GameEvents.OnPlayerHitsPipe).GameEventHandler   += OnPlayerHitsPipe;
        NvpEventBus.Events(GameEvents.OnGameOverFinished).GameEventHandler += OnGameOverFinished;
    }
Exemple #17
0
    public void Update()
    {
        _timer -= Time.deltaTime;
        if (_timer < 0)
        {
            if (_secondDisplay > 0)
            {
                _secondDisplay--;
                _timer = 1f;

                Debug.Log("Display Countdown:" + _secondDisplay);
                NvpEventBus.Events(GameEvents.OnCountDownValueChanged).TriggerEvent(this, new GenericEventArgs(_secondDisplay));
            }
            else
            {
                NvpEventBus.Events(GameEvents.OnCountDownValueChanged).TriggerEvent(this, new GenericEventArgs(3));
                NvpEventBus.Events(GameEvents.OnChangeGameState).TriggerEvent(this, new GenericEventArgs(NvpGameStatesEnum.Play));
            }
        }
    }
Exemple #18
0
    private void CheckPlayerScored()
    {
        var x = _t.position.x;

        if (Mathf.Abs(x) > 33f)
        {
            var eventArgs = new StringEventArgs();

            if (x < 0)
            {
                // right player scores
                eventArgs.Value = "right";
            }
            else
            {
                // left player scores
                eventArgs.Value = "left";
            }

            NvpEventBus.Events(GameEvents.OnPlayerScores).TriggerEvent(this, eventArgs);

            PrepareBallForServe();
        }
    }
 // +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 public StateMachine()
 {
     NvpEventBus.Events(GameEvents.OnTransitionToServeState).GameEventHandler += OnTransitionToServeState;
     NvpEventBus.Events(GameEvents.OnTransitionToRunState).GameEventHandler   += OnTransitionToRunState;
     NvpEventBus.Events(GameEvents.OnTransitionToGameOver).GameEventHandler   += OnTransitionToGameOverState;
 }
Exemple #20
0
 private void OnDisable()
 {
     NvpEventBus.Events(GameEvents.OnPauseGame).GameEventHandler -= OnPause;
 }
 private void OnDisable()
 {
     NvpEventBus.Events(GameEvents.OnCountDownValueChanged).GameEventHandler -= OnCountDownValueChanged;
 }
    private void OnPlayerHitsPipe(object sender, EventArgs e)
    {
        var stateTransitionEventArgs = new GenericEventArgs(NvpGameStatesEnum.GameOver);

        NvpEventBus.Events(GameEvents.OnChangeGameState).TriggerEvent(this, stateTransitionEventArgs);
    }
 // +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 public NvpStateMachine()
 {
     NvpEventBus.Events(GameEvents.OnChangeGameState).GameEventHandler += OnGameStateChanged;
 }
 private void OnDisable()
 {
     NvpEventBus.Events(GameEvents.OnUIChanged).GameEventHandler -= OnShowGameScreen;
 }
Exemple #25
0
 private void OnEnable()
 {
     NvpEventBus.Events(GameEvents.OnPauseGame).GameEventHandler  += OnPause;
     NvpEventBus.Events(GameEvents.OnResetPipes).GameEventHandler += OnResetPipes;
 }
Exemple #26
0
 private void OnDisable()
 {
     NvpEventBus.Events(_subscribedAudioEvent).GameEventHandler -= OnPlayerScores;
 }
Exemple #27
0
 private void OnDisable()
 {
     NvpEventBus.Events(GameEvents.OnLaunchBall).GameEventHandler -= OnServeBall;
 }
 public void Dispose()
 {
     NvpEventBus.Events(GameEvents.OnTransitionToServeState).GameEventHandler -= OnTransitionToServeState;
     NvpEventBus.Events(GameEvents.OnTransitionToRunState).GameEventHandler   -= OnTransitionToRunState;
     NvpEventBus.Events(GameEvents.OnTransitionToGameOver).GameEventHandler   -= OnTransitionToGameOverState;
 }
 public void Dispose()
 {
     NvpEventBus.Events(GameEvents.OnChangeGameState).GameEventHandler -= OnGameStateChanged;
 }
 // +++ event handler ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 private void OnPlayerScores(object sender, EventArgs e)
 {
     Score++;
     NvpEventBus.Events(GameEvents.OnScoreChanged).TriggerEvent(this, new GenericEventArgs(Score));
 }