Ejemplo n.º 1
0
        private void Movement()
        {
            var inputVector = inputActions.OpenArea.Movement.ReadValue <Vector2>();

            OnPlayerMove?.Invoke(inputVector.normalized);

            rb.velocity = new Vector3(inputVector.x, 0, inputVector.y) * speed;
        }
Ejemplo n.º 2
0
    private void Update()
    {
        if (!isMovementAllowed)
        {
            return;
        }

        //Get input
        if (!gameOver.activeSelf)
        {
            float moveVertical   = Input.GetAxisRaw("Vertical");
            float moveHorizontal = Input.GetAxisRaw("Horizontal");

            //Calculations
            direction           = new Vector3(moveHorizontal, 0.0f, moveVertical);
            normalizedDirection = direction.normalized * directionMultiplier;
            float targetAngle = Mathf.Atan2(normalizedDirection.x, normalizedDirection.z) * Mathf.Rad2Deg;
            moveDirection = Quaternion.Euler(0.0f, targetAngle, 0.0f) * Vector3.forward;
            bool isRangeInvoked = dungeonPlayerRange ? dungeonPlayerRange.GetIsInvoking() : false;
            bool isMeleeInvoked = dungeonPlayerMelee ? dungeonPlayerMelee.GetIsInvoking() : false;
            if (!isRangeInvoked && !isMeleeInvoked)
            {
                this.SetIsInvoking(true);

                if (direction == Vector3.zero)
                {
                    OnPlayerMove?.Invoke(moveDirection.normalized, 0.0f, 0.0f, false);
                }
                else
                {
                    if (canRun && Input.GetKey(KeyCode.LeftShift))
                    {
                        OnPlayerMove?.Invoke(moveDirection.normalized, runSpeed, 1.0f, true);
                    }
                    else
                    {
                        OnPlayerMove?.Invoke(moveDirection.normalized, walkSpeed, 0.5f, true);
                    }
                }

                if (direction != Vector3.zero)
                {
                    OnPlayerRotate?.Invoke(normalizedDirection, turnSpeed);
                }
            }
            else
            {
                this.SetIsInvoking(false);
            }
        }
        else
        {
            gameOverBool = true;
            this.DisableMovement();
        }
    }
    private void MoveWorld()
    {
        direction.z = Input.GetAxis("Vertical");
        isMoving    = direction.sqrMagnitude > 0;

        if (isMoving)
        {
            OnPlayerMove?.Invoke(direction * Time.deltaTime * navigationSpeed);
        }
    }
Ejemplo n.º 4
0
    private void Move(GameObject player, Animator animator, Vector3 direction)
    {
        animator.SetFloat("HorizontalMovement", Abs(direction.x));

        if (Abs(direction.x) > movementThreshold)
        {
            player.transform.localScale = new Vector3(3 * Sign(direction.x), 3, 1);
        }

        player.transform.position += direction * speed * Time.deltaTime;

        OnPlayerMove?.Invoke();
    }
Ejemplo n.º 5
0
    public void SetBattleStage(EBattleStage nextStage, RythmMove move = null)
    {
        _currentBattleStage = nextStage;
        if (move != null)
        {
            currentMove = move;
        }
        switch (_currentBattleStage)
        {
        case EBattleStage.Intro:
            SetCharacterValues();
            pauseController.CanPause = false;
            OnIntro?.Invoke();
            break;

        case EBattleStage.PlayerTurn:
            SetEnemyAnimation(enemy.IdleAnimation);
            pauseController.CanPause = true;
            OnPlayerTurn?.Invoke();
            break;

        case EBattleStage.PlayerMove:
            _lastToMoveIsPlayer = true;
            OnPlayerMove?.Invoke();
            break;

        case EBattleStage.EnemyTurn:
            SetPlayerAnimation(player.IdleAnimation);
            pauseController.CanPause = true;
            OnEnemyTurn?.Invoke();
            StartCoroutine(WaitToEnemyMove());
            break;

        case EBattleStage.EnemyMove:
            _lastToMoveIsPlayer = false;
            OnEnemyMove?.Invoke();
            break;

        case EBattleStage.DamageStep:
            OnDamage?.Invoke();
            StartCoroutine(DelayedDamage());
            break;

        case EBattleStage.Conclusion:
            pauseController.CanPause = false;
            OnConclusion?.Invoke();
            break;
        }
    }
Ejemplo n.º 6
0
    public void CheckCurrentFloors()
    {
        int goalFloorCount = 0;

        foreach (GameObject child in MapManager.inst.players)
        {
            OnPlayerMove?.Invoke(Vector2Int.RoundToInt(new Vector2(child.transform.position.x, child.transform.position.z)));
            if (child.GetComponent <Player>().currentFloor.isGoalFloor)
            {
                goalFloorCount++;
            }
        }
        if (GameManager.aFloor >= 0)
        {
            MapManager.inst.currentMap.clearConditions[GameManager.aFloor].count = goalFloorCount;
            MapManager.inst.currentMap.clearConditions[GameManager.aFloor].IsDone();
        }
        if (GameManager.nFloor >= 0)
        {
            MapManager.inst.currentMap.clearConditions[GameManager.nFloor].count = goalFloorCount;
            MapManager.inst.currentMap.clearConditions[GameManager.nFloor].IsDone();
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Moves player to new position. Returns true if player has been moved correctly.
    /// </summary>
    public bool MovePlayer(Vector2Int newPos, Vector2Int dir)
    {
        if (!CanMove)
        {
            return(false);
        }

        Vector2Int oldPlayerPos = PlayerPosition;

        if (newPos.x >= currentMap.mapSize.x || newPos.y >= currentMap.mapSize.y || newPos.x < 0 || newPos.y < 0)
        {
            return(false);
        }

        if (GetElementType(newPos) == ElementType.Air)
        {
            return(false);
        }

        if (GetElementType(newPos) == ElementType.Box || GetElementType(newPos) == ElementType.DoneTarget)
        {
            if (GetElementType(newPos + dir) == ElementType.Ground || GetElementType(newPos + dir) == ElementType.Target)
            {
                Vector2Int newBoxPos = new Vector2Int(newPos.x + dir.x, newPos.y + dir.y);
                GameObject box       = currentElements[newPos.y, newPos.x];

                print($"old player pos = {oldPlayerPos}");
                print($"new pos = {newPos}");
                print($"new box pos = {newBoxPos}");

                StartCoroutine(SmoothMoveElement(Player.transform, new Vector3(newPos.x, 1f, -newPos.y)));
                StartCoroutine(SmoothMoveElement(currentElements[newPos.y, newPos.x].transform, new Vector3(newBoxPos.x, 1f, -newBoxPos.y)));

                if (GetElementType(newPos) == ElementType.DoneTarget)
                {
                    Debug.Log("<color=red>EXIT TARGET</color>");
                    SoundsManager.Manager.ExitTargetSound.Play();
                    currentElements[newPos.y, newPos.x].GetComponent <Box>().ExitTarget();
                }

                if (GetElementType(newBoxPos) == ElementType.Target)
                {
                    Debug.Log("<color=green>ENTER TARGET</color>");
                    SoundsManager.Manager.EnterTargetSound.Play();
                    currentElements[newPos.y, newPos.x].GetComponent <Box>().EnterTarget();
                }

                currentMap.mapDefinition[oldPlayerPos.y, oldPlayerPos.x] =
                    GetElementType(oldPlayerPos) == ElementType.PlayerOnTarget ? ElementType.Target : ElementType.Ground;

                currentMap.mapDefinition[newPos.y, newPos.x] =
                    GetElementType(newPos) == ElementType.DoneTarget ? ElementType.PlayerOnTarget : ElementType.Player;

                currentMap.mapDefinition[newBoxPos.y, newBoxPos.x] =
                    GetElementType(newBoxPos) == ElementType.Target ? ElementType.DoneTarget : ElementType.Box;

                currentElements[oldPlayerPos.y, oldPlayerPos.x] = null;
                currentElements[newPos.y, newPos.x]             = Player;
                currentElements[newBoxPos.y, newBoxPos.x]       = box;

                if (OnPlayerMove != null)
                {
                    OnPlayerMove.Invoke(newPos);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }

        print($"old player pos = {oldPlayerPos}");
        print($"new pos = {newPos}");

        StartCoroutine(SmoothMoveElement(Player.transform, new Vector3(newPos.x, 1f, -newPos.y)));

        currentMap.mapDefinition[oldPlayerPos.y, oldPlayerPos.x] =
            GetElementType(oldPlayerPos) == ElementType.PlayerOnTarget ? ElementType.Target : ElementType.Ground;
        currentMap.mapDefinition[newPos.y, newPos.x] = GetElementType(newPos) == ElementType.Target ? ElementType.PlayerOnTarget : ElementType.Player;

        currentElements[oldPlayerPos.y, oldPlayerPos.x] = null;
        currentElements[newPos.y, newPos.x]             = Player;

        if (OnPlayerMove != null)
        {
            OnPlayerMove.Invoke(newPos);
        }
        return(true);
    }
Ejemplo n.º 8
0
 protected virtual void OnPlayerTurn(byte i_Line, byte i_Colom)
 {
     OnPlayerMove?.Invoke(i_Line, i_Colom);
 }
Ejemplo n.º 9
0
 public void MovePlayer(Vector2 position)
 {
     OnPlayerMove?.Invoke(position);
 }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (!GameManager.inst.isGameOver)
        {
            if (prePos != MapPos)
            {
                //Debug.Log(MapPos);
                OnPlayerMove?.Invoke(MapPos);
                prePos = MapPos;
            }

            //Control player only if camera is not zooming in to or out from the current player
            if (!GameManager.inst.isZooming && !GameManager.inst.isBulletFlying)
            {
                if (Input.GetMouseButtonDown(0) && zoomReady == null)
                {
                    //Move the current player.
                    if (!GameManager.inst.isPlayerMoving && !GameManager.inst.isPlayerShooting)
                    {
                        Ray        mouseRay  = Camera.main.ScreenPointToRay(Input.mousePosition);
                        int        layerMask = (-1) - (1 << LayerMask.NameToLayer("Scattered"));
                        RaycastHit hit;
                        if (Physics.Raycast(mouseRay, out hit, float.MaxValue, layerMask) && hit.collider.gameObject.tag.Equals("Player"))
                        {
                            if (currentPlayer != null)
                            {
                                currentPlayer.ResetCurrentPlayer();
                            }
                            currentPlayer = hit.transform.gameObject.GetComponent <Player>();
                            StartCoroutine(currentPlayer.SetCurrentPlayer());
                            zoomReady = StartCoroutine(currentPlayer.CountPlayerClick(Time.time));
                            //Debug.Log(hit.collider.gameObject.tag);
                        }
                        else if (Physics.Raycast(mouseRay, out hit, float.MaxValue, layerMask) && hit.collider.gameObject.tag.Equals("floor"))
                        {
                            if (currentPlayer != null)
                            {
                                currentPlayer.MovePlayer(hit.collider.gameObject.transform.position);
                            }
                            //Debug.Log(hit.collider.gameObject.tag);
                        }
                        else if (hit.collider == null)
                        {
                            if (currentPlayer != null)
                            {
                                currentPlayer.ResetCurrentPlayer();
                            }
                        }
                    }
                    else if (GameManager.inst.isPlayerShooting && currentPlayer.laser.activeSelf)
                    {
                        if (bulletList.Count > 0 && currentPlayer.canShoot)
                        {
                            currentPlayer.Shoot(bulletList[0]);
                        }
                    }
                    else if (GameManager.inst.isPlayerMoving && !GameManager.inst.isFast)
                    {
                        currentPlayer.GetComponent <NavMeshAgent>().speed *= 5;
                        currentPlayer.anim.speed *= 5;
                        GameManager.inst.isFast   = true;
                    }
                }
                else if (Input.GetMouseButtonDown(1) && GameManager.inst.isPlayerShooting)
                {
                    StartCoroutine(Camera.main.GetComponent <CameraController>().ZoomOutFromPlayer(currentPlayer));
                    currentPlayer.OffAllOutline();
                    currentPlayer.shootingArm.rotation = currentPlayer.armRotation;
                }
            }
        }
    }