Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Catches TopDownEnginePointsEvents and acts on them, playing the corresponding sounds
        /// </summary>
        /// <param name="pointEvent">TopDownEnginePointEvent event.</param>
        public virtual void OnMMEvent(TopDownEnginePointEvent pointEvent)
        {
            switch (pointEvent.PointsMethod)
            {
            case PointsMethods.Set:
                SetPoints(pointEvent.Points);
                break;

            case PointsMethods.Add:
                AddPoints(pointEvent.Points);
                break;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Triggered when something collides with the coin
 /// </summary>
 /// <param name="collider">Other.</param>
 protected override void Pick(GameObject picker)
 {
     // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
     TopDownEnginePointEvent.Trigger(PointsMethods.Add, PointsToAdd);
 }
Ejemplo n.º 4
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();
            }
        }