Ejemplo n.º 1
0
 /// <summary>
 /// When the item is picked, we add points
 /// </summary>
 public override bool Pick()
 {
     base.Pick();
     // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
     CorgiEnginePointsEvent.Trigger(PointsMethods.Add, PointsToAdd);
     return(true);
 }
Ejemplo n.º 2
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)
            {
                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)
                {
                    CorgiEngineEvent.Trigger(CorgiEngineEventTypes.GameOver);
                    if ((GameManager.Instance.GameOverScene != null) && (GameManager.Instance.GameOverScene != ""))
                    {
                        LoadingSceneManager.LoadScene(GameManager.Instance.GameOverScene);
                    }
                }
            }

            if (LevelCameraController != null)
            {
                LevelCameraController.FollowsPlayer = false;
            }

            yield return(new WaitForSeconds(RespawnDelay));

            if (LevelCameraController != null)
            {
                LevelCameraController.FollowsPlayer = true;
            }

            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)
            CorgiEnginePointsEvent.Trigger(PointsMethods.Set, 0);
            // we trigger a respawn event
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Respawn);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Kills the character, vibrates the device, instantiates death effects, handles points, etc
        /// </summary>
        public virtual void Kill()
        {
            // we make our handheld device vibrate
            if (VibrateOnDeath)
            {
                                #if UNITY_ANDROID || UNITY_IPHONE
                Handheld.Vibrate();
                                #endif
            }

            // we prevent further damage
            DamageDisabled();

            // instantiates the destroy effect
            if (DeathEffect != null)
            {
                GameObject instantiatedEffect = (GameObject)Instantiate(DeathEffect, transform.position, transform.rotation);
                instantiatedEffect.transform.localScale = transform.localScale;
            }

            // 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)
                CorgiEnginePointsEvent.Trigger(PointsMethods.Add, PointsWhenDestroyed);
            }

            if (_animator != null)
            {
                _animator.SetTrigger("Death");
            }

            if (OnDeath != null)
            {
                OnDeath();
            }

            // if we have a controller, removes collisions, restores parameters for a potential respawn, and applies a death force
            if (_controller != null)
            {
                // we make it ignore the collisions from now on
                if (CollisionsOffOnDeath)
                {
                    _controller.CollisionsOff();
                    if (_collider2D != null)
                    {
                        _collider2D.enabled = false;
                    }
                }

                // we reset our parameters
                _controller.ResetParameters();

                // we reset our controller's forces on death if needed
                if (ResetForcesOnDeath)
                {
                    _controller.SetForce(Vector2.zero);
                }

                // we apply our death force
                if (DeathForce != Vector2.zero)
                {
                    _controller.GravityActive(true);
                    _controller.SetForce(DeathForce);
                }
            }


            // if we have a character, we want to change its state
            if (_character != null)
            {
                // we set its dead state to true
                _character.ConditionState.ChangeState(CharacterStates.CharacterConditions.Dead);
                _character.Reset();

                // if this is a player, we quit here
                if (_character.CharacterType == Character.CharacterTypes.Player)
                {
                    return;
                }
            }

            if (DelayBeforeDestruction > 0f)
            {
                Invoke("DestroyObject", DelayBeforeDestruction);
            }
            else
            {
                // finally we destroy the object
                DestroyObject();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Triggered when something collides with the coin
 /// </summary>
 /// <param name="collider">Other.</param>
 protected override void Pick()
 {
     // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
     CorgiEnginePointsEvent.Trigger(PointsMethods.Add, PointsToAdd);
 }