Ejemplo n.º 1
0
        public void Move(float movement, bool crouch, bool jump)
        {
            if (!crouch)
            {
                if (Physics2D.OverlapCircle(_playerHead.position, CeilingOverlapRadius, _groundLayerMask))
                {
                    // Can't stand up due to obstacle on head, even though the player has stopped crouching
                    crouch = true;
                }
            }

            if (_grounded || _canSteerWhileAirborne)
            {
                if (crouch)
                {
                    if (_colliderToDisableOnCrouch != null)
                    {
                        _colliderToDisableOnCrouch.enabled = false;
                    }

                    if (!_wasCrouching)
                    {
                        _wasCrouching = true;
                        OnCrouchEvent?.Invoke(true);
                    }

                    movement *= _speedFractionWhenCrouched;
                }
                else
                {
                    if (_colliderToDisableOnCrouch != null)
                    {
                        _colliderToDisableOnCrouch.enabled = true;
                    }

                    if (_wasCrouching)
                    {
                        _wasCrouching = false;
                        OnCrouchEvent?.Invoke(false);
                    }
                }

                Vector3 targetVelocity = new Vector2(movement * 10.0f, _rigidbody.velocity.y);

                _rigidbody.velocity = Vector3.SmoothDamp(_rigidbody.velocity, targetVelocity, ref _velocity, _movementSmoothing);

                int movementSign = Math.Sign(movement);

                if (movementSign != 0 && movementSign != _playerDirection)
                {
                    Flip();
                }
            }

            if (_grounded && jump)
            {
                _grounded = false;
                _rigidbody.AddForce(new Vector2(0.0f, _jumpForce));
            }
        }
 public void ResendEvents()
 {
     musicMutedEvent?.Invoke(!musicEnabled);
     musicVolumeEvent?.Invoke(save.musicVolume);
     fxVolumeEvent?.Invoke(save.fxVolume);
     fxMutedEvent?.Invoke(!fxEnabled);
 }
    private void Move()
    {
        if (direction.magnitude >= 0.1f)
        {
            controller.Move(direction * movementSpeed * Time.deltaTime);
            onMovement?.Invoke(true);
            return;
        }

        onMovement?.Invoke(false);
    }
Ejemplo n.º 4
0
 public static void SwitchGameState(bool isPlaying)
 {
     if (!isPlaying)
     {
         pausedTime = Time.time;
     }
     onGameStateChanged?.Invoke(isPlaying);
     Debug.Log("is playing = " + isPlaying);
 }
Ejemplo n.º 5
0
    protected override bool AttackTarget(Collider[] colliders)
    {
        if (isPlayer)
        {
            Vector3 direction = playerController.GetLookingPosition() - firePoint.position;
            direction.y = 0;
            LaunchProjectile(direction.normalized);
            return(true);
        }

        if (colliders.Length == 0)
        {
            return(false);
        }

        foreach (var target in colliders)
        {
            if (target.gameObject == gameObject)
            {
                continue;
            }

            if ((targetRb == null) || targetRb.gameObject != target.gameObject)
            {
                targetRb = target.GetComponent <Rigidbody>();
            }

            Vector3 shootingDirection = GetInterceptCourseDirection(target.transform.position, targetRb.velocity, firePoint.position, projectileSpeed);
            if (shootingDirection == Vector3.zero)
            {
                continue;
            }

            RaycastHit hit;
            int        visibilityMask = ~(1 << gameObject.layer | 1 << (int)Layer.Interactable);
            if (Physics.Raycast(firePoint.position - firePoint.forward, shootingDirection, out hit, attackRange + 1f, visibilityMask))
            {
                bool oldVisibilty = targetIsVisible;
                targetIsVisible = hit.collider.gameObject.layer.IsInLayerMask(targetLayers);
                if (targetIsVisible != oldVisibilty)
                {
                    OnTargetVisibilityChange?.Invoke(targetIsVisible);
                }
            }

            if (!targetIsVisible)
            {
                continue;
            }

            LaunchProjectile(shootingDirection.normalized);
            return(true);
        }
        return(false);
    }
        /// <summary> Swaps the state of the pause menu. </summary>
        /// <param name="isActive"> Should the pause menu be active. </param>
        public void SwitchPauseState(bool isActive)
        {
            IsPaused = isActive;

            canvases.PauseCanvas.enabled     = IsPaused;
            canvases.HowToPlayCanvas.enabled = false;
            canvases.SettingsCanvas.enabled  = false;

            Time.timeScale = IsPaused ? 0f : 1f;

            PauseMenuStateChanged?.Invoke(IsPaused);
        }
Ejemplo n.º 7
0
 void Update()
 {
     if (Input.GetButton("Fire2") != usesShield)
     {
         if (usesShield || Time.time >= wm.GetLastWeaponUsageTime() + shieldUsageBlockTime)
         {
             usesShield = !usesShield;
             OnShieldingStateChanged?.Invoke(usesShield);
             wm.SetCanAttack(!usesShield);
             playerController.AddMovementSpeed(usesShield ? -shieldingMovementSpeedDecrease : shieldingMovementSpeedDecrease);
         }
     }
 }
Ejemplo n.º 8
0
        private void Invoke(bool isVisible)
        {
            _isVisible = isVisible;

            if (_isVisible)
            {
                eventsOnlyActive?.Invoke();
            }
            else
            {
                eventsOnlyDisactive?.Invoke();
            }

            events?.Invoke(_isVisible);
        }
Ejemplo n.º 9
0
    private void Update()
    {
        if (_changeSkillCheckPos)
        {
            _changeSkillCheckPos = false;
            RandomizePositionAndWidth();
        }
        if (Input.GetMouseButtonDown(0))
        {
            _canMove = false;

            var colls = _pointerToCheck.CheckIfFailed();

            if (colls == null || colls.Length == 0)
            {
                Debug.Log("Niente hai fallito");
            }

            bool giusto = colls.ToList().Exists(col => col.gameObject == _skillChecker.gameObject);
            OnSkillCheckDone?.Invoke(giusto);

            if (giusto)
            {
                tentativi++;
            }

            if (gameObject.activeInHierarchy == false)
            {
                return;
            }

            if (!_restartAfterInput)
            {
                return;
            }

            StopAllCoroutines();

            StartCoroutine(WaitAfterInput());
        }
    }
Ejemplo n.º 10
0
    public void Move(float movePercentage, bool crouch, bool jump)
    {
        //Debug.Log("added force to move the player0");
        if (GravitySystem.instance.isReverseGravity)
        {
            movePercentage *= -1;
        }
        if (m_Grounded && Mathf.Abs(movePercentage) > 0.2)
        {
            AudioManager.instance.play("playerRun");
        }

        // If crouching, check to see if the character can stand up
        if (!crouch)
        {
            // If the character has a ceiling preventing them from standing up, keep them crouching
            if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
            {
                crouch = true;
            }
        }
        //Debug.Log("added force to move the player1");
        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                movePercentage *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            //Debug.Log("added force to move the player1.1");
            //  Vector3 gravityUp = (transform.position - center.position).normalized * gravity;

            //  Quaternion targetRotatoion = Quaternion.FromToRotation(transform.up, gravityUp) * transform.rotation;
            //  transform.rotation = Quaternion.Slerp(transform.rotation, targetRotatoion, 50 * Time.deltaTime);
            // Move the character by finding the target velocity
            //Vector3 targetVelocity = (transform.right.normalized * movePercentage * 10f) +Vector3.Project(m_Rigidbody2D.velocity,transform.up);
            //new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
            // targetVelocity = Quaternion.Euler(0, 0, transform.rotation.z/Mathf.PI*360) * targetVelocity;
            //Debug.Log(transform.rotation.z / Mathf.PI * 360);
            //Debug.Log("added force to move the player2");
            float horizontalSpeed = Vector3.Dot(m_Rigidbody2D.velocity, transform.right);
            //Debug.Log("added force to move the player3");
            //Debug.Log("right:" +transform.right+"vel: "+ m_Rigidbody2D.velocity+"dor: " + horizontalSpeed);
            // m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
            // Debug.Log(horizontalSpeed);

            moveForce = GravitySystem.instance.runningSpeed;


            //Debug.Log("speed reached: " + horizontalSpeed.x);
            if (movePercentage > 0 && horizontalSpeed < maxMoveSpeed)
            {
                if (horizontalSpeed > maxMoveSpeed)
                {
                    Debug.Log("error maximum speed reached: " + horizontalSpeed);
                }
                if (Mathf.Abs(horizontalSpeed) > 0.1)
                {
                    // Debug.Log("player is trying to move sideways");
                }
                if (horizontalSpeed > 0)
                {
                    m_Rigidbody2D.AddForce(transform.right.normalized * movePercentage * moveForce);
                }
                else
                {
                    m_Rigidbody2D.AddForce(transform.right.normalized * movePercentage * moveForce * 3);
                }
            }
            else if (movePercentage < 0 && horizontalSpeed > -maxMoveSpeed)
            {
                if (horizontalSpeed < -maxMoveSpeed)
                {
                    Debug.Log("error maximum speed reached: " + horizontalSpeed);
                }
                if (horizontalSpeed < 0)
                {
                    m_Rigidbody2D.AddForce(transform.right.normalized * movePercentage * moveForce);
                }
                else
                {
                    m_Rigidbody2D.AddForce(transform.right.normalized * movePercentage * moveForce * 3);
                }
            }
            else  //add drag
            {
                m_Rigidbody2D.AddForce(transform.right.normalized * horizontalSpeed * -1f);
            }

            //Debug.Log("added force to move the player4");

            // If the input is moving the player right and the player is facing left...
            if (movePercentage > 0 && !m_FacingRight)
            {
                Flip();
            }
            else if (movePercentage < 0 && m_FacingRight)
            {
                Flip();
            }
        }
        // If the player should jump...
        if (m_Grounded && jump)
        {
            // Add a vertical force to the player.
            m_Grounded = false;
            float gravitySqrt = Mathf.Sqrt(GravitySystem.instance.gravityForce);
            float jumpHeight  = Mathf.Sqrt(GravitySystem.instance.jumpHeight);
            float jumpForce   = m_JumpForce * jumpHeight * gravitySqrt;

            m_Rigidbody2D.AddForce(transform.up.normalized * jumpForce);

            AudioManager.instance.play("playerJump");
            if (PC)
            {
                if (PC.PCO)
                {
                    PlayerData PD = PC.PCO.GetComponent <PlayerData>();
                    if (PD)
                    {
                        PD.CmdplayerJumped();
                    }
                }
            }
        }
    }
Ejemplo n.º 11
0
 //Input
 public void Invoke(AudioSystem.AudioConfig data)
 {
     loopOutput?.Invoke(data.loop);
     pitchOutput?.Invoke(data.pitch);
     volumeOutput?.Invoke(data.volume);
 }
    public void Move(float move, bool crouch, bool jump)
    {
        // If crouching, check to see if the character can stand up
        if (!crouch)
        {
            // If the character has a ceiling preventing them from standing up, keep them crouching
            if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
            {
                crouch = true;
            }
        }

        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent?.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent?.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);

            // If the input is moving the player right and the player is facing left...
            if (move > 0 && !m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move < 0 && m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
        }
        // If the player should jump...
        if (m_Grounded && jump)
        {
            // Add a vertical force to the player.
            m_Grounded = false;
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }
    }
Ejemplo n.º 13
0
    private void FixedUpdate()                               //Движение игрока
    {
        if (Character.velocity.y < 0f && !Grounded)
        {
            Animator.SetBool("IsFall", true);
        }

        HorizontalMove = Input.GetAxisRaw("HorizontalPlayer1") * Speed;

        bool WasGrounded = Grounded;

        Grounded = false;

        Collider2D[] colliders = Physics2D.OverlapCircleAll(GroundCheck.position, GroundRadius, WhatIsGround);

        for (int i = 0; i < colliders.Length; i++)
        {
            if (colliders[i].gameObject != gameObject)
            {
                Animator.SetBool("IsFall", false);
                Grounded = true;
                if (!WasGrounded)
                {
                    OnLandEvent.Invoke();
                }
            }
        }

        if (!Crouch)
        {
            if (Physics2D.OverlapCircle(CrouchCheck.position, CrouchRadius, WhatIsGround))
            {
                Crouch = true;
            }
        }

        if (Crouch)
        {
            if (!WasCrouching)
            {
                WasCrouching = true;
                OnCrouchEvent.Invoke(true);
            }

            HorizontalMove *= CrouchSpeed;

            if (CrouchDisableCollider != null)
            {
                BasicCollider.enabled         = false;
                CrouchDisableCollider.enabled = true;
            }
        }
        else
        {
            if (CrouchDisableCollider != null)
            {
                BasicCollider.enabled         = true;
                CrouchDisableCollider.enabled = false;
            }

            if (WasCrouching)
            {
                WasCrouching = false;
                OnCrouchEvent.Invoke(false);
            }
        }

        Animator.SetFloat("Speed", Mathf.Abs(HorizontalMove));

        if (!Climb)
        {
            Character.gravityScale = 3f;

            TargetVelocity = new Vector2(HorizontalMove * Time.fixedDeltaTime * 10f, Character.velocity.y);

            Character.velocity = Vector3.SmoothDamp(Character.velocity, TargetVelocity, ref Velocity, MovementSmoothing);
        }
        else if (Climb)
        {
            VerticalMove = Input.GetAxisRaw("Vertical") * Speed * Time.fixedDeltaTime;

            Character.gravityScale = 0f;

            TargetVelocity = new Vector2(HorizontalMove * Time.fixedDeltaTime * 10f, VerticalMove * 10f);

            Character.velocity = Vector3.SmoothDamp(Character.velocity, TargetVelocity, ref Velocity, MovementSmoothing);
        }
    }
Ejemplo n.º 14
0
 public void Raise()
 {
     BoolEvent?.Invoke(BoolReference);
 }
Ejemplo n.º 15
0
 void OpenLevelDoor()
 {
     // if (currentProgress.Level == currentLevel) currentProgress.Level++;
     onDoorOpened?.Invoke(currentProgress.Level >= SceneManager.sceneCountInBuildSettings);
 }
Ejemplo n.º 16
0
 void OnBecameVisible()
 {
     visibility.Invoke(true);
 }
Ejemplo n.º 17
0
 protected override void OnEventRaised()
 {
     _gameEventBool._condition = !_gameEventBool._condition;
     _eventResponse?.Invoke(_gameEventBool._condition);
 }
Ejemplo n.º 18
0
 public override void ExecuteServer(ConnectedPlayer subject)
 {
     ServerMethod?.Invoke(Element.isOn);
     ServerMethodWithSubject?.Invoke(Element.isOn, subject);
 }
Ejemplo n.º 19
0
 public virtual void OnEventRaised(bool argument)
 {
     Response?.Invoke(argument);
 }
Ejemplo n.º 20
0
    public void Move(float move, bool crouch, float vertical_move)
    {
        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(
                m_Rigidbody2D.velocity,
                targetVelocity,
                ref m_Velocity,
                m_MovementSmoothing
                );

            // If the input is moving the player right and the player is facing left...
            if (move > 0 && !m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move < 0 && m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
        }
        // If the player should jump...
        if (m_Grounded && vertical_move > 0)
        {
            // Add a vertical force to the player.
            m_Grounded = false;
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }

        //Stump down while in the air
        if (!m_Grounded && vertical_move < 0)
        {
            m_Rigidbody2D.AddForce(new Vector2(0f, -m_stumpForce));
        }

        //Faster Fall
        if (m_Rigidbody2D.velocity.y < 0)
        {
            m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime;
        }
        else if (m_Rigidbody2D.velocity.y > 0)
        {
        }
    }
    public void Move(float move, bool crouch, bool jump)
    {
        if (!crouch)
        {
            if (Physics2D.OverlapCircle(ceilingPosition.position, ceilingRadius, groundLayers))
            {
                // the player cannot currently stand up
                crouch = true;
            }
        }

        // only control the player if grounded or canAirControl is turned on
        if (isGrounded || canAirControl)
        {
            if (crouch)
            {
                if (!wasCrouching)
                {
                    // if we weren't crouching before, but now are, generate the crouch event
                    wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // move more slowly when crouched
                move *= crouchSpeedMultiplier;

                // when crouching, disable the upper collider
                if (colliderToDisableOnCrouch != null)
                {
                    colliderToDisableOnCrouch.enabled = false;
                }
            }
            else
            {
                // enable the collider when not crouching
                if (colliderToDisableOnCrouch != null)
                {
                    colliderToDisableOnCrouch.enabled = true;
                }

                if (wasCrouching)
                {
                    // if previously crouching, but are no longer, generate the (un)crouch event
                    wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // what speed do we want to travel?
            Vector3 targetVelocity = new Vector2(move * movementSpeed, GetComponent <Rigidbody2D>().velocity.y);

            // apply smoothing to the speed
            rigidBody.velocity = Vector3.SmoothDamp(rigidBody.velocity, targetVelocity, ref velocity, movementSmoothing);

            // export the speed
            speed = rigidBody.velocity.magnitude;

            if (move > 0 && !isFacingRight)
            {
                // flip the sprite horizontally when travelling left
                Flip();
            }
            else if (move < 0 && isFacingRight)
            {
                // flip the sprite horizontally when travelling left
                Flip();
            }
        }
        if (isGrounded && jump)
        {
            // add a vertical force to the player
            isGrounded = false;
            rigidBody.AddForce(new Vector2(0f, jumpForce));
        }
    }
Ejemplo n.º 22
0
    public void Move(Vector2 move, bool crouch, bool jump)
    {
        Debug.Log(m_Grounded);

        // If crouching, check to see if the character can stand up
        if (!crouch)
        {
            // If the character has a ceiling preventing them from standing up, keep them crouching
            if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_GroundedRadius, m_WhatIsGround))
            {
                crouch = true;
            }
        }

        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector2 targetVelocity = move;
            // And then smoothing it out and applying it to the character

            m_Rigidbody.velocity = Vector2.SmoothDamp(m_Rigidbody.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);



            // If the input is moving the player right and the player is facing left...
            if (move.x > 0 && !m_FacingRight)
            {
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move.x < 0 && m_FacingRight)
            {
            }
        }
        // If the player should jump, then turn off jump
        if (m_Grounded && jump)
        {
            //m_Animator.SetBool("Jump", true);
            Debug.Log("triggered");
            m_Rigidbody.velocity += Vector2.up * m_JumpSpeed;
            m_Grounded            = false;
        }
    }
Ejemplo n.º 23
0
 public void OnToggleClick()
 {
     toggleClick?.Invoke(flag);
     flag = !flag;
 }
Ejemplo n.º 24
0
    public void Move(float move, bool ducka, bool hoppa)
    {
        // Om spelaren duckar så kollar denna om spelaren kan stå upp
        if (!ducka)
        {
            // Spelaren kommer fortsätta ducka om det finns något ovanför
            if (Physics2D.OverlapCircle(CeilingCheck.position, CeilingRadius, WhatIsGround))
            {
                ducka = true;
            }
        }

        if (Grounded || AirControl)
        {
            // Om man duckar
            if (ducka)
            {
                if (!wasduckaing)
                {
                    wasduckaing = true;
                    OnduckaEvent.Invoke(true);
                }

                // Gör spelaren långsammare när han duckar
                move *= duckaSpeed;

                // Tar bort den översta collidern när han duckar
                if (duckaDisableCollider != null)
                {
                    duckaDisableCollider.enabled = false;
                }
            }
            else
            {
                // Sätter tillbaks collidern när han slutar duckar.
                if (duckaDisableCollider != null)
                {
                    duckaDisableCollider.enabled = true;
                }

                if (wasduckaing)
                {
                    wasduckaing = false;
                    OnduckaEvent.Invoke(false);
                }
            }

            // Flyttar spelaren
            Vector3 targetVelocity = new Vector2(move * 10f, Rigidbody2D.velocity.y);
            // Gör det smoooooth!
            Rigidbody2D.velocity = Vector3.SmoothDamp(Rigidbody2D.velocity, targetVelocity, ref Velocity, MovementSmoothing);

            // Om spelaren är åt höger men spelaren byter håll, då ska spelaren byta håll
            if (move > 0 && !FacingRight)
            {
                //Byter håll på spelaren
                Flip();
            }
            // Motsatsen till ovan
            else if (move < 0 && FacingRight)
            {
                Flip();
            }
        }
        //Om spelaren kan hoppa
        if (Grounded && hoppa)
        {
            // Lägger en kraft uppåt på spelaren
            Grounded = false;
            Rigidbody2D.AddForce(new Vector2(0f, hoppaForce));
        }
    }
Ejemplo n.º 25
0
 private void Start()
 {
     // Project is closed by default, so raising the Closed events upon Start.
     onProjectClosed?.Invoke();
     onProjectOpeningChanged?.Invoke(false);
 }
Ejemplo n.º 26
0
 public void SetValue(bool v)
 {
     this.value = v;
     OnValueChanged?.Invoke(v);
 }
Ejemplo n.º 27
0
 void HandleSwitchToggled(bool on)
 {
     On = on;
     Animator.SetBool(AnimatorStateParameterName, On);
     OnToggled?.Invoke(on);
 }
Ejemplo n.º 28
0
    public void Move(float dT, float move, bool crouch, int jump)
    {
        move *= 10 * dT;

        // If crouching, check to see if the character can stand up
        if (!crouch)
        {
            // If the character has a ceiling preventing them from standing up, keep them crouching
            if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
            {
                crouch = true;
            }
        }

        // Only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                // Got up
                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);

            // Instead of using regular gravity we gradually reduce the vertical velocity
            // dynamically, based on user input
            if (m_Rigidbody2D.velocity.y < 0)
            {
                m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * m_DownGravityMultiplier * dT;
            }
            else if ((m_Rigidbody2D.velocity.y > 0) && (jump == 0))
            {
                m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * m_LowJumpMultiplier * dT;
            }

            // Take off
            if (m_Grounded && (jump == 1))
            {
                m_Rigidbody2D.velocity = Vector2.up * m_JumpForce;
            }

            // If the input is moving the player right and the player is facing left
            // or vice versa, flip the sprite.
            if ((move > 0 && !m_FacingRight) || (move < 0 && m_FacingRight))
            {
                Flip();
            }
        }
    }
Ejemplo n.º 29
0
 private void Start()
 {
     currentlyOn = isOn;
     onValueChanged?.Invoke(currentlyOn);
 }
    public void Move(float move, bool crouch, bool jump)
    {
        // If crouching, check to see if the character can stand up
        if (!crouch)
        {
            // If the character has a ceiling preventing them from standing up, keep them crouching
            if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
            {
                crouch = true;
            }
        }

        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
        }
        // If the player should jump...
        if (jumps > 0 && jump)
        {
            // Add a vertical force to the player.
            jumps--;
            jumpParticle.Play();
            OnJumpEvent.Invoke();
            sfx.PlaySound(transform.position, SoundType.Jump);
            controller.setJumps(jumps);

            m_Rigidbody2D.velocity *= Vector2.right;
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }
    }