Example #1
0
        void IUpdatable.Update()
        {
            // handle movement and animations
            var    moveDir   = new Vector2(_xAxisInput.Value, 0);
            string animation = null;

            if (moveDir.X < 0)
            {
                if (_collisionState.Below)
                {
                    animation = "Run";
                }
                _animator.FlipX = true;
                _velocity.X     = -MoveSpeed;
            }
            else if (moveDir.X > 0)
            {
                if (_collisionState.Below)
                {
                    animation = "Run";
                }
                _animator.FlipX = false;
                _velocity.X     = MoveSpeed;
            }
            else
            {
                _velocity.X = 0;
                if (_collisionState.Below)
                {
                    animation = "Idle";
                }
            }

            if (_collisionState.Below && _jumpInput.IsPressed)
            {
                animation   = "Jumping";
                _velocity.Y = -Mathf.Sqrt(2f * JumpHeight * Gravity);
            }

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

            // apply gravity
            _velocity.Y += Gravity * Time.DeltaTime;

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

            if (_collisionState.Below)
            {
                _velocity.Y = 0;
            }

            if (animation != null && !_animator.IsAnimationActive(animation))
            {
                _animator.Play(animation);
            }
        }
Example #2
0
        protected virtual void UpdateMovement()
        {
            // falling motion
            Velocity.Y += Stats.Gravity * Time.DeltaTime;

            Mover.Move(Velocity * Time.DeltaTime, TiledCollider, TiledCollisionState);

            if (TiledCollisionState.Below || TiledCollisionState.Above)
            {
                Velocity.Y = 0;
            }
        }
Example #3
0
        void IUpdatable.Update()
        {
            var moveDir = new Vector2(_xAxisInput, 0);

            animation = "playerIdle";

            if (moveDir.X != 0 && _collisionState.Below) // moving to the left and right
            {
                animation = "playerRun";
                StateMachine.ChangeState <Running>();
            }
            else
            {
                animation = "playerIdle";
                StateMachine.ChangeState <Idle>();
            }

            if (_collisionState.Below && _jumpInput.IsPressed)
            {
                _velocity.Y = -Mathf.Sqrt(2f * jumpHeight * gravity);
                animation   = "playerJump";
                StateMachine.ChangeState <Jumping>();
            }

            if (_velocity.Y > 0)
            {
                animation = "playerFall";
                StateMachine.ChangeState <Falling>();
            }
            if (_velocity.Y < 0)
            {
                StateMachine.ChangeState <Jumping>();
            }

            _velocity.Y += gravity * Time.DeltaTime;

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

            //_velocity.X += allomanticForce;
            _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState);

            StateMachine.Update(Time.DeltaTime);
            if (Input.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.X))
            {
                _velocity.Y = 0;
                thisScene.Camera.ZoomIn(0.1f);
            }
        }
Example #4
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;
        }
Example #5
0
        public void Update()
        {
            Player player = thisScene.FindEntity("player").GetComponent <Player>();

            hmm.X = (player.Transform.Position.X - Transform.Position.X);
            hmm.Y = (player.Transform.Position.Y - Transform.Position.Y);
            //length = hmm.Length();

            _velocity.Y += gravity * Time.DeltaTime;
            if (_collisionState.Below || _collisionState.Above || _collisionState.Right || _collisionState.Left)
            {
                _velocity = Vector2.Zero;
            }



            if (Physics.OverlapRectangle(new RectangleF(this.Transform.Position, this.Transform.Scale)) == thisScene.FindEntity("player").GetComponent <Player>()._boxCollider)
            {
                test = true;
            }
            else
            {
                test = false;
            }

            var distance = Vector2.Distance(this.Transform.Position, player.Transform.Position);

            if (Input.IsKeyPressed(Keys.F) || Input.IsKeyPressed(Keys.E)) // Lock the angle you push from
            {
                angle = (float)Math.Atan2(hmm.Y, hmm.X);
            }

            if (Input.LeftMouseButtonDown || Input.IsKeyDown(Keys.F))
            {
                mousePos = thisScene.Camera.ScreenToWorldPoint(Input.ScaledMousePosition);
                //if (Physics.OverlapRectangle(new RectangleF(mousePos, new Vector2(2, 2))) == _boxCollider)
                //{


                var ratio = player.mass / (mass + player.mass);
                var other = 1 - ratio;


                allomanticForce        = (float)(player.burnRate * (Math.Sqrt(mass * player.mass)) / (Math.Pow(distance / 32, 2)));
                player.allomanticForce = (float)(player.burnRate * (Math.Sqrt(mass * player.mass)) / (Math.Pow(Math.E, -distance / 16)));



                if (allomanticForce > 100)
                {
                    allomanticForce = 100;
                }

                newAng            = (allomanticForce * 5) * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                player._velocity += newAng;
                _velocity        += -newAng;

                //Debug.DrawLine(newAng, player.Transform.Position, Color.Red);
                Debug.DrawLine(this.Transform.Position, player.Transform.Position, Color.Red);

                //if (hmm.X < 0)
                //{
                //player._velocity = new Vector2(other * allomanticForce, other * allomanticForce);
                //_velocity = new Vector2(ratio * -allomanticForce, ratio * -allomanticForce);

                //}
                //else
                //{
                //player._velocity += newAng;
                //player._velocity = new Vector2(other * -allomanticForce, other * -allomanticForce);
                //_velocity = new Vector2(ratio * allomanticForce, ratio * allomanticForce);
                //}

                //}
            }

            if (Input.IsKeyDown(Keys.E))
            {
                var ratio = player.mass / (mass + player.mass);
                var other = 1 - ratio;


                allomanticForce        = (float)(player.burnRate * (Math.Sqrt(mass * player.mass)) / (Math.Pow(distance / 32, 2)));
                player.allomanticForce = (float)(player.burnRate * (Math.Sqrt(mass * player.mass)) / (Math.Pow(Math.E, -distance / 16)));



                if (allomanticForce > 100)
                {
                    allomanticForce = 100;
                }

                newAng            = (allomanticForce * 5) * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                player._velocity += -newAng;
                _velocity        += newAng;
            }
            //length = MathHelper.ToDegrees((float)Math.Atan2(hmm.Y, -hmm.X));
            //_velocity.X += allomanticForce;
            _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState);
        }