Beispiel #1
0
        private IEnumerator ParticleSnowDash(float angle, float secs)
        {
            yield return(Coroutine.WaitForSeconds(.25f));

            Particles.LoadParticleSystem(1, Entity, -angle, 75);
            _camera.SetZoom(0.01f);
            yield return(Coroutine.WaitForSeconds(secs));

            Debug.Log("coroutine finished?");
            _camera.SetZoom(0f);
        }
Beispiel #2
0
        void IUpdatable.Update()
        {
            // handle movement and animations
            var    moveDir   = new Vector2(_xAxisInput.Value, 0);
            string animation = null;

            if (IsRunning == true && _collisionState.Below && !_runInput.IsDown)
            {
                IsRunning = false;
            }

            if (CanMove == false)
            {
                return;
            }

            if (CanInput == false)
            {
                if (!_collisionState.Below && _velocity.Y > 0)
                {
                    animation = "Falling";
                }

                // apply gravity
                if (CanGravity)
                {
                    _velocity.Y += Gravity * Time.DeltaTime;
                }

                // move
                _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState);


                if (animation != null && !_animator.IsAnimationActive(animation))
                {
                    _animator.Play(animation);
                }

                return;
            }

            // moving right
            if (moveDir.X < 0 && Math.Abs(_velocity.X) < RunSpeed)
            {
                if (_collisionState.Below)
                {
                    // running
                    if (_runInput.IsDown)
                    {
                        animation   = "Run";
                        _velocity.X = -RunSpeed;
                        IsRunning   = true;
                    }
                    // walking
                    else
                    {
                        animation   = "Walk";
                        _velocity.X = (MoveSpeed / moveDir.X);
                        Debug.Log(moveDir.X);
                    }
                }
                //moving when jumping
                else
                {
                    if (_velocity.X <= MoveSpeed)
                    {
                        if (IsRunning && (_velocity.X <= RunSpeed))
                        {
                            _velocity.X = -RunSpeed;
                        }
                        else
                        {
                            _velocity.X = (MoveSpeed / moveDir.X);
                        }
                    }
                    else
                    {
                        _velocity.X = _velocity.X + -FallSpeed;
                    }
                }
                _animator.FlipX = true;
            }
            // moving left
            else if (moveDir.X > 0 && Math.Abs(_velocity.X) < RunSpeed)
            {
                if (_collisionState.Below)
                {
                    if (_runInput.IsDown)
                    {
                        animation   = "Run";
                        _velocity.X = RunSpeed;
                        IsRunning   = true;
                    }
                    else
                    {
                        animation   = "Walk";
                        _velocity.X = (MoveSpeed / moveDir.X);
                    }
                }
                else
                {
                    if (_velocity.X >= MoveSpeed)
                    {
                        if (IsRunning && (_velocity.X <= RunSpeed))
                        {
                            _velocity.X = RunSpeed;
                        }
                        else
                        {
                            _velocity.X = (MoveSpeed / moveDir.X);
                        }
                    }
                    else
                    {
                        _velocity.X = _velocity.X + FallSpeed;
                    }
                }
                _animator.FlipX = false;
            }
            //slowing down
            else
            {
                if (_velocity.X >= 15)
                {
                    _velocity.X = _velocity.X - 15;
                    Debug.Log(_velocity.X);
                }
                else if (_velocity.X <= -15)
                {
                    _velocity.X = _velocity.X + 15;
                }
                else
                {
                    _velocity.X = 0;
                }

                if (Math.Abs(_velocity.X) >= 15 && Math.Abs(_velocity.X) <= MoveSpeed)
                {
                    animation = "Hurt";
                }

                if (_collisionState.Below && animation != "Hurt" && Math.Abs(_velocity.X) <= MoveSpeed)
                {
                    animation = "Idle";
                }
            }

            if (_collisionState.Right || _collisionState.Left)
            {
                Debug.Log(Stamina);
                Stamina -= 1;
                if (Stamina < 0)
                {
                    Stamina     = 140;
                    _velocity.X = -1200;
                }
            }

            // jump when on ground
            if ((_collisionState.Below || CanJump != 0) && _jumpInput.IsPressed)
            {
                animation   = "Jumping";
                _velocity.Y = -Mathf.Sqrt(2f * JumpHeight * Gravity);
                Debug.Log(_velocity.Y);
                CanJump = 0;
            }

            //dash
            if (_dashInput.IsPressed && CanDash)
            {
                CanDash = false;

                Debug.Log(Math.Abs(_xAxisInput.Value) * DashSpeed);
                Debug.Log(Math.Abs(_yAxisInput.Value) * DashSpeed);

                float VeloX;
                float VeloY;

                // not moving horizontally
                if (_yAxisInput.Value == 0)
                {
                    Debug.Log("hello");
                    VeloX = Mathf.Sqrt(2f * DashSpeed * Gravity);
                    VeloY = 0;                                 //-Mathf.Sqrt(1.5f * DashSpeed * GravityWhileDashing);
                    Core.StartCoroutine(DisableGravity(.50f)); //disable gravity for a bit
                    Core.StartCoroutine(DisableInputs(.50f));  //dash should last ~.75sec
                }
                else
                {
                    VeloX = Mathf.Sqrt(2f * (Math.Abs(_xAxisInput.Value) * DashSpeed) * Gravity);
                    VeloY = -Mathf.Sqrt(2f * (Math.Abs(_yAxisInput.Value) * DashSpeed) * Gravity);
                    Core.StartCoroutine(DisableGravity(.25f)); //disable gravity for a bit
                }
                if (_xAxisInput.Value < 0 || _animator.FlipX == true)
                {
                    VeloX = -VeloX;
                }
                if (_yAxisInput.Value > 0)
                {
                    VeloY = -VeloY;
                }
                _velocity.X = VeloX;
                _velocity.Y = VeloY;

                if (_yAxisInput.Value < -.02f)
                {
                    animation = "Death";
                }

                //shake camera cause we can :sunglasses:
                Entity.GetComponent <CameraShake>().Shake(15, .75f, new Vector2(-VeloX, -VeloY));
                //emit particles (i dont know how to do shaders)
                Core.StartCoroutine(ParticleSnowDash(new Vector2().AngleBetween(new Vector2(1, 0), new Vector2(-VeloX, -VeloY)), 0.3f));
                Core.StartCoroutine(DisableMovement(.15f));
            }

            if (!_collisionState.Below && _velocity.Y > 0)
            {
                animation = "Falling";
            }

            // apply gravity
            if (CanGravity)
            {
                _velocity.Y += Gravity * Time.DeltaTime;
            }

            // move
            _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState);

            //reset dashes and stamina and jump grace thingy
            if (_collisionState.Below)
            {
                _velocity.Y = 0;
                CanJump     = 5;
                CanDash     = true;
                Stamina     = 140;
            }

            // snow particles when land
            if (_collisionState.BecameGroundedThisFrame && !_collisionState.IsGroundedOnOneWayPlatform)
            {
                Particles.LoadParticleSystem(1, Entity, 90, 100);
            }

            if (LatestAnimation != animation)
            {
                Debug.Log(animation);
            }

            if (animation != null && !_animator.IsAnimationActive(animation))
            {
                _animator.Play(animation);
            }

            // jump grace countdown (-1 per frame)
            if (CanJump > 0 && !_collisionState.Below)
            {
                CanJump--;
                Debug.Log($"CanJump {CanJump}");
            }

            LatestAnimation = animation;
        }