Example #1
0
        /// <summary>
        /// Stores the points of entry for the level whose name you pass as a parameter.
        /// </summary>
        /// <param name="levelName">Level name.</param>
        /// <param name="entryIndex">Entry index.</param>
        /// <param name="exitIndex">Exit index.</param>
        public virtual void StorePointsOfEntry(string levelName, int entryIndex, Character.FacingDirections facingDirection)
        {
            if (PointsOfEntry.Count > 0)
            {
                foreach (PointsOfEntryStorage point in PointsOfEntry)
                {
                    if (point.LevelName == levelName)
                    {
                        point.PointOfEntryIndex = entryIndex;
                        return;
                    }
                }
            }

            PointsOfEntry.Add(new PointsOfEntryStorage(levelName, entryIndex, facingDirection));
        }
Example #2
0
    /// <summary>
    /// Coroutine that kills the player, stops the camera, resets the points.
    /// </summary>
    /// <returns>The player co.</returns>
    protected IEnumerator SoloModeRestart(Character player, Transform respawnPoint, Character.FacingDirections facingDirection)
    {
        if ((PlayerPrefabs.Count() <= 0) && (SceneCharacters.Count <= 0))
        {
            yield break;
        }

        MMCameraEvent.Trigger(MMCameraEventTypes.StopFollowing);
        CharacterSwapManager.DisableSwap();
        yield return(new WaitForSeconds(RespawnDelay));

        CharacterSwapManager.EnableSwap();

        // if we've setup our game manager to use lives (meaning our max lives is more than zero)
        if (GameManager.Instance.MaximumLives > 0)
        {
            int lastCurrentLives = GameManager.Instance.CurrentLives;
            // we lose a life
            GameManager.Instance.LoseLife();
            Config.currentLives = GameManager.Instance.CurrentLives;
            var currentLives = GameManager.Instance.CurrentLives;
            //nếu đang ở level không cho phép hồi sinh dưới 0 mạng
            if (Config.currentSceneIndex > Config.UNLIMIT_LIVE_LEVEL)
            {
                //nếu âm mạng hoặc mạng đang bằng 0 từ đầu ván thì ending
                //còn nếu mạng về 0 thì vẫn cho chơi nốt một lần
                if (currentLives < 0 || (currentLives == 0 && lastCurrentLives == 0))
                {
                    StickmanManager.Instance.ShowRevivePanel();

                    yield return(new WaitUntil(() => !StickmanManager.Instance.isWaitToRevive));

                    yield return(null);
                }
            }
        }

        MMCameraEvent.Trigger(MMCameraEventTypes.StartFollowing);
        player.RespawnAt(respawnPoint, facingDirection);

        _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
        ResetLevelBoundsToOriginalBounds();
        CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Respawn);
    }
        protected virtual void DetermineFacingDirection()
        {
            if (_controller.CurrentDirection == Vector3.zero)
            {
                switch (CurrentFacingDirection)
                {
                case Character.FacingDirections.East:
                    _controller.CurrentDirection = Vector3.right;
                    break;

                case Character.FacingDirections.West:
                    _controller.CurrentDirection = Vector3.left;
                    break;

                case Character.FacingDirections.North:
                    _controller.CurrentDirection = Vector3.up;
                    break;

                case Character.FacingDirections.South:
                    _controller.CurrentDirection = Vector3.down;
                    break;
                }
            }

            if (_controller.CurrentDirection.normalized.magnitude >= AbsoluteThresholdMovement)
            {
                if (Mathf.Abs(_controller.CurrentDirection.y) > Mathf.Abs(_controller.CurrentDirection.x))
                {
                    CurrentFacingDirection = (_controller.CurrentDirection.y > 0) ? Character.FacingDirections.North : Character.FacingDirections.South;
                }
                else
                {
                    CurrentFacingDirection = (_controller.CurrentDirection.x > 0) ? Character.FacingDirections.East : Character.FacingDirections.West;
                }
                _horizontalDirection = Mathf.Abs(_controller.CurrentDirection.x) >= AbsoluteThresholdMovement ? _controller.CurrentDirection.x : 0f;
                _verticalDirection   = Mathf.Abs(_controller.CurrentDirection.y) >= AbsoluteThresholdMovement ? _controller.CurrentDirection.y : 0f;
            }
            else
            {
                _horizontalDirection = _lastDirectionX;
                _verticalDirection   = _lastDirectionY;
            }

            _lastDirectionX = _horizontalDirection;
            _lastDirectionY = _verticalDirection;
        }
        /// <summary>
        /// On awake we init our facing direction and grab components
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            if (InitialFacingDirection == Character.FacingDirections.West)
            {
                IsFacingRight = false;
                _direction    = -1;
            }
            else
            {
                IsFacingRight = true;
                _direction    = 1;
            }
            Face(InitialFacingDirection);
            _directionLastFrame    = 0;
            _characterHandleWeapon = this.gameObject.GetComponentInParent <CharacterHandleWeapon>();

            CurrentFacingDirection = InitialFacingDirection;
            switch (InitialFacingDirection)
            {
            case Character.FacingDirections.East:
                _lastDirectionX = 1f;
                _lastDirectionY = 0f;
                break;

            case Character.FacingDirections.West:
                _lastDirectionX = -1f;
                _lastDirectionY = 0f;
                break;

            case Character.FacingDirections.North:
                _lastDirectionX = 0f;
                _lastDirectionY = 1f;
                break;

            case Character.FacingDirections.South:
                _lastDirectionX = 0f;
                _lastDirectionY = -1f;
                break;
            }
        }
Example #5
0
    /// <summary>
    /// Kills the player.
    /// </summary>
    public void KillPlayer(Character player, Transform respawnPoint, Character.FacingDirections facingDirection)
    {
        Health characterHealth = player.GetComponent <Health>();

        if (characterHealth == null)
        {
            return;
        }
        else
        {
            // we kill the character
            characterHealth.Kill();
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.PlayerDeath);

            // if we have only one player, we restart the level
            if (Players.Count < 2)
            {
                StartCoroutine(SoloModeRestart(player, respawnPoint, facingDirection));
            }
        }
    }
        /// <summary>
        /// Forces the character's model to face in the specified direction
        /// </summary>
        /// <param name="direction"></param>
        public virtual void Face(Character.FacingDirections direction)
        {
            switch (direction)
            {
            case Character.FacingDirections.East:
                _newMovementQuaternion = Quaternion.LookRotation(Vector3.right);
                break;

            case Character.FacingDirections.North:
                _newMovementQuaternion = Quaternion.LookRotation(Vector3.forward);
                break;

            case Character.FacingDirections.South:
                _newMovementQuaternion = Quaternion.LookRotation(Vector3.back);
                break;

            case Character.FacingDirections.West:
                _newMovementQuaternion = Quaternion.LookRotation(Vector3.left);
                break;
            }
        }
Example #7
0
        protected virtual void DetermineFacingDirection()
        {
            if (_controller.CurrentDirection.normalized.magnitude >= AbsoluteThresholdMovement)
            {
                if (Mathf.Abs(_controller.CurrentDirection.y) > Mathf.Abs(_controller.CurrentDirection.x))
                {
                    CurrentFacingDirection = (_controller.CurrentDirection.y > 0) ? Character.FacingDirections.North : Character.FacingDirections.South;
                }
                else
                {
                    CurrentFacingDirection = (_controller.CurrentDirection.x > 0) ? Character.FacingDirections.East : Character.FacingDirections.West;
                }
                _horizontalDirection = Mathf.Abs(_controller.CurrentDirection.x) >= AbsoluteThresholdMovement ? _controller.CurrentDirection.x : 0f;
                _verticalDirection   = Mathf.Abs(_controller.CurrentDirection.y) >= AbsoluteThresholdMovement ? _controller.CurrentDirection.y : 0f;
            }
            else
            {
                _horizontalDirection = _lastDirectionX;
                _verticalDirection   = _lastDirectionY;
            }

            _lastDirectionX = _horizontalDirection;
            _lastDirectionY = _verticalDirection;
        }
Example #8
0
 public virtual void Face(Character.FacingDirections direction)
 {
     CurrentFacingDirection = direction;
 }
 public PointsOfEntryStorage(string levelName, int pointOfEntryIndex, Character.FacingDirections facingDirection)
 {
     LevelName         = levelName;
     FacingDirection   = facingDirection;
     PointOfEntryIndex = pointOfEntryIndex;
 }