Esempio n. 1
0
        /// <summary>
        /// Waits a specified number of seconds in real time, can be skipped with skip button
        /// </summary>
        /// <remarks>Can only be used from the main thread</remarks>
        public static async Task DelayRealtime(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime)
            {
                if (!LockPauseModule.IsInputLocked())
                {
                    if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                    {
                        break;
                    }
                }

                await Task.Yield();
            }

            await Task.Yield();
        }
Esempio n. 2
0
        /// <summary>
        /// Waits for specified time (in real time), can be skipped with skip button
        /// </summary>
        public static IEnumerator WaitForSecondsRealtime(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime)
            {
                if (!LockPauseModule.IsInputLocked())
                {
                    if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                    {
                        break;
                    }
                }

                yield return(null);
            }

            yield return(null); //necessary for debouncing
        }
        private bool GetSkipKeyDown()
        {
            if (LockPauseModule.IsInputLocked())
            {
                return(false);
            }

            if (UseUnityInput && (UnityEngine.Input.GetButtonDown("Submit") || UnityEngine.Input.GetKeyDown(KeyCode.Space)))
            {
                return(true);
            }

            if (UseMappedInput && (MappedInput.GetButtonDown(DefaultControls.Confirm) || MappedInput.GetButtonDown(DefaultControls.Fire) || MappedInput.GetButtonDown(DefaultControls.Use)))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        private void HandleGrenadeThrow()
        {
            if (LockPauseModule.IsInputLocked() || !PlayerInControl || PlayerIsDead || !PlayerCanShoot)
            {
                return;
            }

            if (GetButtonDown("Fire2") && Bombs > 0)
            {
                Vector2    fireVector     = (Quaternion.AngleAxis(GrenadeAngle, Vector3.forward) * Vector3.right) * new Vector2(Mathf.Sign(transform.localScale.x), 1);
                Quaternion bulletRotation = Quaternion.FromToRotation(Vector3.right, fireVector);

                var go = Instantiate(GrenadePrefab, GrenadeThrowPoint.position, bulletRotation, CoreUtils.GetWorldRoot());
                var rb = go.GetComponent <Rigidbody2D>();
                rb.velocity = (fireVector * GrenadeVelocity);// + Rigidbody.velocity;

                Bombs--;
            }
        }
Esempio n. 5
0
        //should be fixedupdate, probably
        public override void Update()
        {
            HandleMessages();

            if (Time.timeScale == 0 || LockPauseModule.IsPaused())
            {
                return;
            }

            if (HandleDeath)
            {
                HandleDying();
            }

            if (PlayerInControl && !LockPauseModule.IsInputLocked())
            {
                HandleView();
                HandleInteraction();
                //HandleWeapons();
            }
        }
Esempio n. 6
0
        private void HandleShooting()
        {
            DidJustFire = false;

            if (LockPauseModule.IsInputLocked() || !PlayerController.PlayerInControl || PlayerController.PlayerIsDead || !PlayerController.PlayerCanShoot)
            {
                return;
            }

            if (PlayerController.GetButtonDown(DefaultControls.Fire) && TimeUntilNextShot <= 0)
            {
                var gunPivot = PlayerController.IsCrouched ? GunPivotCrouched : GunPivot;

                //aiming!
                Vector2 fireVector    = (Vector2)transform.right * Mathf.Sign(PlayerController.transform.localScale.x);
                float   spawnDistance = ((Vector2)transform.position - (Vector2)GunPivot.position).magnitude;
                float   aimY          = PlayerController.GetAxis("Vertical");
                if (aimY > AimDeadzone || (!PlayerController.IsTouchingGround && aimY < -AimDownDeadzone))
                {
                    float aimX = PlayerController.GetAxis("Horizontal");
                    fireVector = new Vector2(aimX, aimY).normalized;
                }
                Vector2 spawnPosition = (Vector2)gunPivot.position + fireVector * spawnDistance; //this technique misaligns the bullet if the muzzle isn't aligned with the pivot. Can you fix it?
                LastFireVector = fireVector;

                Quaternion bulletRotation = Quaternion.FromToRotation(Vector3.right, fireVector);

                var go = Instantiate(BulletPrefab, spawnPosition, bulletRotation, CoreUtils.GetWorldRoot());
                var rb = go.GetComponent <Rigidbody2D>();
                rb.velocity = (fireVector * BulletVelocity);// + (Vector2.right * PlayerController.Rbody.velocity.x);
                var bs = go.GetComponent <BulletScript>();
                bs.Damage          = BulletDamage;
                TimeUntilNextShot += FireInterval;
                DidJustFire        = true;

                //play effect, anim
                AttackSound.Ref()?.Play();
                GunAnimator.Play("Fire"); //we rely on the Animator to return to idle state
            }
        }
Esempio n. 7
0
        //we may rework this to use an explicit update from PlayerController
        void Update()
        {
            if (Time.timeScale == 0 || LockPauseModule.IsPaused())
            {
                return;
            }

            //HandleDynamicMovement();

            //reset these
            IsMoving        = false;
            IsRunning       = false;
            DidJump         = false;
            DidChangeCrouch = false;

            if (PlayerController.PlayerInControl && !LockPauseModule.IsInputLocked())
            {
                HandleLook();
                if (Clipping)
                {
                    HandleMovement();
                }
            }

            if (Clipping)
            {
                HandleDynamicMovement();
                HandleOutOfBounds();
            }

            HandleNoclip();
            HandleCrouchAnimation();

            HandleAnimation();
            HandleSounds();
        }
Esempio n. 8
0
        /// <summary>
        /// Handle noclip state and movement
        /// </summary>
        protected void HandleNoclip()
        {
            if (!Clipping && !(MetaState.Instance.SessionFlags.Contains("NoClip") || GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoClip)))
            {
                exitNoclipMode();
                return;
            }
            else if (Clipping && (MetaState.Instance.SessionFlags.Contains("NoClip") || GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoClip)))
            {
                enterNoclipMode();
                return;
            }

            if (!Clipping)
            {
                doNoclipMovement();
            }

            void enterNoclipMode()
            {
                Clipping = false;

                IsMoving   = false;
                IsRunning  = false;
                IsGrounded = false;
                IsOnSlope  = false;

                IsCrouching = false;
                SetCrouchState();

                CharController.enabled          = false;
                CharController.detectCollisions = false;
            }

            void exitNoclipMode()
            {
                Clipping = true;

                CharController.enabled          = true;
                CharController.detectCollisions = true;
            }

            void doNoclipMovement()
            {
                if (!PlayerController.PlayerInControl || LockPauseModule.IsInputLocked() || GameState.Instance.PlayerFlags.Contains(PlayerFlags.Frozen) || GameState.Instance.PlayerFlags.Contains(PlayerFlags.TotallyFrozen))
                {
                    return;
                }

                Vector3 moveVector = Vector3.zero;
                Vector3 velocity   = MappedInput.GetButton(DefaultControls.Sprint) ? NoclipFastVelocity : NoclipVelocity;

                if (Mathf.Abs(MappedInput.GetAxis(DefaultControls.MoveY)) > InputDeadzone)
                {
                    moveVector += (PlayerController.CameraRoot.transform.forward * MappedInput.GetAxis(DefaultControls.MoveY) * velocity.z * Time.deltaTime);
                }

                if (Mathf.Abs(MappedInput.GetAxis(DefaultControls.MoveX)) > InputDeadzone)
                {
                    moveVector += (transform.right * MappedInput.GetAxis(DefaultControls.MoveX) * velocity.x * Time.deltaTime);
                }

                float moveY = MappedInput.GetAxis(DefaultControls.Jump) - MappedInput.GetAxis(DefaultControls.Crouch);

                if (Mathf.Abs(moveY) > InputDeadzone)
                {
                    moveVector += (Vector3.up * moveY * velocity.y * Time.deltaTime);
                }

                if (moveVector.magnitude > 0)
                {
                    transform.Translate(moveVector, Space.World);
                }
            }
        }
Esempio n. 9
0
        private void HandleMovement()
        {
            if (LockPauseModule.IsInputLocked() || !PlayerInControl || PlayerIsDead)
            {
                return;
            }

            float h = GetAxis(DefaultControls.MoveX);

            IsTouchingGround = Physics2D.OverlapPoint(GroundCheckTransform.position, GroundLayerMask); //move outside of PlayerIsDead check?

            if (DidRequestJump && TimeUntilNextJump <= 0)
            {
                if (IsTouchingGround)
                {
                    Rigidbody.AddForce(new Vector2(0, JumpSpeed * Rigidbody.mass), ForceMode2D.Impulse);
                    IsTouchingGround  = false;
                    TimeUntilNextJump = TimeBetweenJumps;
                    PlayerAnimator.Play("Jump");
                }
                DidRequestJump = false;
            }

            if (h > 0)
            {
                transform.localScale = new Vector2(ScaleX, ScaleY);
            }
            else if (h < 0)
            {
                transform.localScale = new Vector2(-ScaleX, ScaleY);
            }
            Rigidbody.velocity = new Vector2(h * (IsCrouched ? CrouchSpeed : Speed), Rigidbody.velocity.y); //this is going to be f*****g horrible

            //handle animation
            if (Mathf.Abs(h) > MoveAnimateDeadzone)
            {
                if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
                {
                    PlayerAnimator.Play("Walk");
                }
                else if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("CrouchIdle"))
                {
                    PlayerAnimator.Play("CrouchWalk");
                }
            }
            else
            {
                if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("Walk"))
                {
                    PlayerAnimator.Play("Idle");
                }
                else if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("CrouchWalk"))
                {
                    PlayerAnimator.Play("CrouchIdle");
                }
            }

            //handle crouch
            float moveY = GetAxis(DefaultControls.MoveY);

            if (moveY < -CrouchDeadzone && IsTouchingGround)
            {
                if (!IsCrouched)
                {
                    EnterCrouch();
                    IsCrouched = true;
                }
            }
            else
            {
                if (IsCrouched)
                {
                    ExitCrouch();
                    IsCrouched = false;
                }
            }
        }