Esempio n. 1
0
        /// <summary>
        /// A coroutine used to trigger the pause event
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator PauseButtonCo()
        {
            yield return(null);

            // we trigger a Pause event for the GameManager and other classes that could be listening to it too
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.TogglePause, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Waits for a short time and then loads the specified level
        /// </summary>
        /// <returns>The level co.</returns>
        /// <param name="levelName">Level name.</param>
        protected virtual IEnumerator GotoLevelCo(string levelName)
        {
            if (Players != null && Players.Count > 0)
            {
                foreach (Character player in Players)
                {
                    player.Disable();
                }
            }

            MMFadeInEvent.Trigger(OutroFadeDuration, FadeCurve);
            if (Time.timeScale > 0.0f)
            {
                yield return(new WaitForSeconds(OutroFadeDuration));
            }
            // we trigger an unPause event for the GameManager (and potentially other classes)
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.UnPause, null);

            if (string.IsNullOrEmpty(levelName))
            {
                LoadingSceneManager.LoadScene("StartScreen");
            }
            else
            {
                LoadingSceneManager.LoadScene(levelName);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// On Start we grab our dependencies and initialize spawn
        /// </summary>
        protected virtual void Start()
        {
            BoundsCollider = _collider;
            InstantiatePlayableCharacters();

            MMCameraEvent.Trigger(MMCameraEventTypes.SetConfiner, null, BoundsCollider);

            if (Players == null || Players.Count == 0)
            {
                return;
            }

            Initialization();

            // we handle the spawn of the character(s)
            if (Players.Count == 1)
            {
                SpawnSingleCharacter();
            }
            else
            {
                SpawnMultipleCharacters();
            }

            CheckpointAssignment();

            // we trigger a level start event
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.LevelStart, null);
            MMGameEvent.Trigger("Load");

            MMCameraEvent.Trigger(MMCameraEventTypes.SetTargetCharacter, Players[0]);
            MMCameraEvent.Trigger(MMCameraEventTypes.StartFollowing);
            MMGameEvent.Trigger("CameraBound");
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the player to the specified level
        /// </summary>
        /// <param name="levelName">Level name.</param>
        public virtual void GotoLevel(string levelName)
        {
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.LevelEnd, null);
            MMGameEvent.Trigger("Save");

            StartCoroutine(GotoLevelCo(levelName));
        }
Esempio n. 5
0
 /// <summary>
 /// Restarts the current level, without reloading the whole scene
 /// </summary>
 public virtual void RestartLevel()
 {
     if (GameManager.Instance.Paused)
     {
         TopDownEngineEvent.Trigger(TopDownEngineEventTypes.UnPause, null);
     }
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.RespawnStarted, null);
 }
 /// <summary>
 /// Spawns all characters at the specified spawn points
 /// </summary>
 protected override void SpawnMultipleCharacters()
 {
     for (int i = 0; i < Players.Count; i++)
     {
         SpawnPoints[i].SpawnPlayer(Players[i]);
     }
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.SpawnComplete, null);
 }
Esempio n. 7
0
        /// <summary>
        /// Coroutine that kills the player, stops the camera, resets the points.
        /// </summary>
        /// <returns>The player co.</returns>
        protected virtual IEnumerator SoloModeRestart()
        {
            if ((PlayerPrefabs.Count() <= 0) && (SceneCharacters.Count <= 0))
            {
                yield break;
            }

            // if we've setup our game manager to use lives (meaning our max lives is more than zero)
            if (GameManager.Instance.MaximumLives > 0)
            {
                // we lose a life
                GameManager.Instance.LoseLife();
                // if we're out of lives, we check if we have an exit scene, and move there
                if (GameManager.Instance.CurrentLives <= 0)
                {
                    TopDownEngineEvent.Trigger(TopDownEngineEventTypes.GameOver, null);
                    if ((GameManager.Instance.GameOverScene != null) && (GameManager.Instance.GameOverScene != ""))
                    {
                        LoadingSceneManager.LoadScene(GameManager.Instance.GameOverScene);
                    }
                }
            }

            MMCameraEvent.Trigger(MMCameraEventTypes.StopFollowing);

            MMFadeInEvent.Trigger(OutroFadeDuration, FadeCurve, FaderID, true, Players[0].transform.position);
            yield return(new WaitForSeconds(OutroFadeDuration));

            yield return(new WaitForSeconds(RespawnDelay));

            GUIManager.Instance.SetPauseScreen(false);
            GUIManager.Instance.SetDeathScreen(false);
            MMFadeOutEvent.Trigger(OutroFadeDuration, FadeCurve, FaderID, true, Players[0].transform.position);


            MMCameraEvent.Trigger(MMCameraEventTypes.StartFollowing);

            if (CurrentCheckpoint == null)
            {
                CurrentCheckpoint = InitialSpawnPoint;
            }

            if (Players[0] == null)
            {
                InstantiatePlayableCharacters();
            }

            if (CurrentCheckpoint != null)
            {
                CurrentCheckpoint.SpawnPlayer(Players[0]);
            }
            _started = DateTime.UtcNow;

            // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
            TopDownEnginePointEvent.Trigger(PointsMethods.Set, 0);
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.RespawnComplete, Players[0]);
            yield break;
        }
Esempio n. 8
0
 /// <summary>
 /// When we grab a TopDownEngineEvent, and if it's a PlayerDeath event, we unlock our achievement
 /// </summary>
 /// <param name="topDownEngineEvent"></param>
 public virtual void OnMMEvent(TopDownEngineEvent topDownEngineEvent)
 {
     switch (topDownEngineEvent.EventType)
     {
     case TopDownEngineEventTypes.PlayerDeath:
         MMAchievementManager.UnlockAchievement("DeathIsOnlyTheBeginning");
         break;
     }
 }
Esempio n. 9
0
 /// <summary>
 /// If the pause button has been pressed, we change the pause state
 /// </summary>
 protected virtual void TriggerPause()
 {
     if (!AbilityPermitted &&
         (_condition.CurrentState == CharacterStates.CharacterConditions.Normal || _condition.CurrentState == CharacterStates.CharacterConditions.Paused))
     {
         return;
     }
     PlayAbilityStartFeedbacks();
     // we trigger a Pause event for the GameManager and other classes that could be listening to it too
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.TogglePause, null);
 }
Esempio n. 10
0
 /// <summary>
 /// When a coin gets picked, we increase the amount of points of the character who picked it
 /// </summary>
 /// <param name="pickEvent"></param>
 public virtual void OnMMEvent(PickableItemEvent pickEvent)
 {
     _playerID = pickEvent.Picker.MMGetComponentNoAlloc <Character>()?.PlayerID;
     for (int i = 0; i < Points.Length; i++)
     {
         if (Points[i].PlayerID == _playerID)
         {
             Points[i].Points++;
             TopDownEngineEvent.Trigger(TopDownEngineEventTypes.Repaint, null);
         }
     }
 }
        /// <summary>
        /// On game over, freezes time and displays the game over screen
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator GameOver()
        {
            yield return(new WaitForSeconds(2f));

            if (WinnerID == "")
            {
                WinnerID = "Player1";
            }
            MMTimeScaleEvent.Trigger(MMTimeScaleMethods.For, 0f, 0f, false, 0f, true);
            _gameOver = true;
            TopDownEngineEvent.Trigger(TopDownEngineEventTypes.GameOver, null);
        }
Esempio n. 12
0
        /// <summary>
        /// Catches TopDownEngineEvents and acts on them, playing the corresponding sounds
        /// </summary>
        /// <param name="engineEvent">TopDownEngineEvent event.</param>
        public virtual void OnMMEvent(TopDownEngineEvent engineEvent)
        {
            switch (engineEvent.EventType)
            {
            case TopDownEngineEventTypes.PlayerDeath:
                PlayerDead(engineEvent.OriginCharacter);
                break;

            case TopDownEngineEventTypes.RespawnStarted:
                Respawn();
                break;
            }
        }
Esempio n. 13
0
        public virtual void OnMMEvent(TopDownEngineEvent topdownEngineEvent)
        {
            if (topdownEngineEvent.EventType == TopDownEngineEventTypes.CharacterSwitch)
            {
                SetTarget(LevelManager.Instance.Players[0]);
                StartFollowing();
            }

            if (topdownEngineEvent.EventType == TopDownEngineEventTypes.CharacterSwap)
            {
                SetTarget(LevelManager.Instance.Players[0]);
                MMCameraEvent.Trigger(MMCameraEventTypes.RefreshPosition);
            }
        }
 public virtual void OnMMEvent(TopDownEngineEvent tdEvent)
 {
     if (tdEvent.EventType == TopDownEngineEventTypes.PlayerDeath)
     {
         int i = 0;
         foreach (Character character in LevelManager.Instance.Players)
         {
             if (character.ConditionState.CurrentState == CharacterStates.CharacterConditions.Dead)
             {
                 _targetGroup.m_Targets[i].weight = 0f;
             }
             i++;
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Watches for pause events to cut the sound on pause
 /// </summary>
 /// <param name="engineEvent"></param>
 public virtual void OnMMEvent(TopDownEngineEvent engineEvent)
 {
     if (engineEvent.EventType == TopDownEngineEventTypes.Pause)
     {
         if (MuteSfxOnPause)
         {
             MuteAllSfx();
         }
     }
     if (engineEvent.EventType == TopDownEngineEventTypes.UnPause)
     {
         if (MuteSfxOnPause)
         {
             UnmuteAllSfx();
         }
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Spawns a playable character into the scene
        /// </summary>
        protected virtual void SpawnSingleCharacter()
        {
            PointsOfEntryStorage point = GameManager.Instance.GetPointsOfEntry(SceneManager.GetActiveScene().name);

            if ((point != null) && (PointsOfEntry.Length >= (point.PointOfEntryIndex + 1)))
            {
                Players[0].RespawnAt(PointsOfEntry[point.PointOfEntryIndex], point.FacingDirection);
                TopDownEngineEvent.Trigger(TopDownEngineEventTypes.SpawnComplete, null);
                return;
            }

            if (InitialSpawnPoint != null)
            {
                InitialSpawnPoint.SpawnPlayer(Players[0]);
                TopDownEngineEvent.Trigger(TopDownEngineEventTypes.SpawnComplete, null);
                return;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Catches TopDownEngineEvents and acts on them, playing the corresponding sounds
        /// </summary>
        /// <param name="engineEvent">TopDownEngineEvent event.</param>
        public virtual void OnMMEvent(TopDownEngineEvent engineEvent)
        {
            switch (engineEvent.EventType)
            {
            case TopDownEngineEventTypes.TogglePause:
                if (Paused)
                {
                    TopDownEngineEvent.Trigger(TopDownEngineEventTypes.UnPause, null);
                }
                else
                {
                    TopDownEngineEvent.Trigger(TopDownEngineEventTypes.Pause, null);
                }
                break;

            case TopDownEngineEventTypes.Pause:
                Pause();
                break;

            case TopDownEngineEventTypes.UnPause:
                UnPause();
                break;
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Reloads the current level
 /// </summary>
 public virtual void ReloadLevel()
 {
     // we trigger an unPause event for the GameManager (and potentially other classes)
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.UnPause, null);
     LoadingSceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
Esempio n. 19
0
 /// <summary>
 /// Restarts the current level, without reloading the whole scene
 /// </summary>
 public virtual void RestartLevel()
 {
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.UnPause, null);
     TopDownEngineEvent.Trigger(TopDownEngineEventTypes.RespawnStarted, null);
 }
Esempio n. 20
0
        /// <summary>
        /// Kills the character, vibrates the device, instantiates death effects, handles points, etc
        /// </summary>
        public virtual void Kill()
        {
            if (_character != null)
            {
                // we set its dead state to true
                _character.ConditionState.ChangeState(CharacterStates.CharacterConditions.Dead);
                _character.Reset();

                if (_character.CharacterType == Character.CharacterTypes.Player)
                {
                    TopDownEngineEvent.Trigger(TopDownEngineEventTypes.PlayerDeath, _character);
                }
            }
            CurrentHealth = 0;

            // we prevent further damage
            DamageDisabled();

            DeathMMFeedbacks?.PlayFeedbacks(this.transform.position);

            // Adds points if needed.
            if (PointsWhenDestroyed != 0)
            {
                // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
                TopDownEnginePointEvent.Trigger(PointsMethods.Add, PointsWhenDestroyed);
            }

            if (_animator != null)
            {
                _animator.SetTrigger("Death");
            }
            // we make it ignore the collisions from now on
            if (DisableCollisionsOnDeath)
            {
                if (_collider2D != null)
                {
                    _collider2D.enabled = false;
                }
                if (_collider3D != null)
                {
                    _collider3D.enabled = false;
                }

                // if we have a controller, removes collisions, restores parameters for a potential respawn, and applies a death force
                if (_controller != null)
                {
                    _controller.CollisionsOff();
                }

                if (DisableChildCollisionsOnDeath)
                {
                    foreach (Collider2D collider in this.gameObject.GetComponentsInChildren <Collider2D>())
                    {
                        collider.enabled = false;
                    }
                    foreach (Collider collider in this.gameObject.GetComponentsInChildren <Collider>())
                    {
                        collider.enabled = false;
                    }
                }
            }

            if (ChangeLayerOnDeath)
            {
                gameObject.layer = LayerOnDeath.LayerIndex;
                if (ChangeLayersRecursivelyOnDeath)
                {
                    this.transform.ChangeLayersRecursively(LayerOnDeath.LayerIndex);
                }
            }

            OnDeath?.Invoke();

            if (DisableControllerOnDeath && (_controller != null))
            {
                _controller.enabled = false;
            }

            if (DisableControllerOnDeath && (_characterController != null))
            {
                _characterController.enabled = false;
            }

            if (DisableModelOnDeath && (Model != null))
            {
                Model.SetActive(false);
            }

            if (DelayBeforeDestruction > 0f)
            {
                Invoke("DestroyObject", DelayBeforeDestruction);
            }
            else
            {
                // finally we destroy the object
                DestroyObject();
            }
        }