示例#1
0
    public override void _PhysicsProcess(float delta)
    {
        velocity.x  = 0;
        velocity.y += Overlord.STANDARD_GRAVITY;
        if (parent.TestMove(parent.Transform, velocity) &&
            !parent.TestMove(parent.Transform, new Vector2(speed * 5 * (int)direction, velocity.y))
            )
        {
            direction = direction == WalkingDirection.Left ? WalkingDirection.Right : WalkingDirection.Left;
            changeDirection((int)direction);
        }
        velocity.x = speed * (int)direction;

        var collision = parent.MoveAndSlide(velocity);

        if (Math.Abs(collision.x) < speed)
        {
            direction = direction == WalkingDirection.Left ? WalkingDirection.Right : WalkingDirection.Left;
            changeDirection((int)direction);
        }
        if (collision.y == 0)
        {
            velocity.y = 0;
        }
    }
示例#2
0
        private void UpdateVelocity()
        {
            var acceleration = Vector2.Zero;

            if (Curve.GetPointCount() == 0)
            {
                Decelerate();
            }
            else
            {
                var destinationPoint = Curve.InterpolateBaked(_currentT);
                if (_owner.GlobalPosition.DistanceSquaredTo(destinationPoint) < MAX_AHEAD * MAX_AHEAD)
                {
                    _currentT += MAX_AHEAD_DELTA * GetProcessDeltaTime();
                }

                if (_currentT < (Curve.GetBakedLength()))
                {
                    acceleration = (destinationPoint - _owner.GlobalPosition).Normalized() * _acceleration;
                }
                else
                {
                    if (!_pathEndReached)
                    {
                        _pathEndReached = true;
                        EmitSignal(nameof(PathEndReached));
                    }
                    Decelerate();
                }
            }

            Velocity += acceleration * GetProcessDeltaTime();
            Velocity  = Velocity.Clamped(_maxSpeed);
            Velocity  = _owner.MoveAndSlide(Velocity);
        }
示例#3
0
        public KinematicCollision2D MoveObject(KinematicBody2D host, Vector2 direction)
        {
            Vector2 velocity = direction.Normalized() * Speed;

            host.MoveAndSlide(velocity, Vector2.Zero);
            return(host.GetSlideCount() == 0 ? null : host.GetSlideCollision(0));
        }
示例#4
0
 public override void Update(KinematicBody2D host, float delta)
 {
     if (_canChase)
     {
         ChaseTarget(host);
     }
     host.MoveAndSlide(_direction * Speed);
 }
示例#5
0
 public override void Update(KinematicBody2D host, float delta)
 {
     Speed += Acceleration * delta;
     if (Speed > MaxSpeed)
     {
         Speed = MaxSpeed;
     }
     host.MoveAndSlide((_player.GlobalPosition - host.GlobalPosition).Normalized() * Speed);
 }
示例#6
0
        public override void Update(KinematicBody2D host, float delta)
        {
            Speed += Acceleration * delta;
            if (Speed > MaxSpeed)
            {
                Speed = MaxSpeed;
            }

            host.MoveAndSlide(_direction.Normalized() * Speed);
        }
示例#7
0
        public override void _PhysicsProcess(float delta)
        {
            var distance = GlobalPosition.DistanceTo(target.GlobalPosition);

            if (distance > activeDistance + 100)
            {
                return;
            }

            var direction = GlobalPosition.DirectionTo(target.GlobalPosition);

            if (distance > 300)
            {
                parent.MoveAndSlide(direction * speed);
            }
            else if (distance < 250)
            {
                parent.MoveAndSlide(-direction * speed);
            }
        }
示例#8
0
    public override void _PhysicsProcess(float delta)
    {
        if (introFinished == false || canMove == false)
        {
            return;
        }

        velocity = new Vector2();
        if (Input.IsActionPressed("ui_right"))
        {
            velocity.x -= 1;
            Owner.GetNode <Panel>("Control/Panel").Visible = false;
            Owner.GetNode <Panel>("Control/Panel").Visible = false;
        }

        if (Input.IsActionPressed("ui_left"))
        {
            velocity.x += 1;
        }

        velocity = velocity.Normalized() * speed;

        if (run)
        {
            velocity *= 3f;
        }

        if (canMoveForward == false && velocity.x > 0)
        {
            velocity.x = 0;
        }

        if (canMoveBackWards == false && velocity.x < 0)
        {
            velocity.x = 0;
        }


        if (velocity.x > 0)
        {
            Owner.GetNode <Panel>("Control/Panel").Visible = false;
            GD.Print("test");
        }

        if (velocity.x < 0)
        {
            Owner.GetNode <Panel>("Control/Panel").Visible = false;
            GD.Print("test");
        }
        MoveAndSlide(velocity * delta);
        upperlayer.MoveAndSlide(velocity * delta);
    }
    public void ProcessPhysics(float delta)
    {
        // Applying horizontal motion
        _velocity.x = _currentDirection * _moveSpeed;

        if (_bufferedJumpAcceleration > 0f)
        {
            _velocity.y = -_bufferedJumpAcceleration / delta;
        }

        _velocity.y += _gravity;
        _bufferedJumpAcceleration = 0f;
        _currentDirection         = 0;

        _kb.MoveAndSlide(_velocity, Vector2.Up);
    }
    public void Move(KinematicBody2D character, float delta)
    {
        inputVelocity.y += GravityScale * Gravity * delta;
        inputVelocity    = character.MoveAndSlide(inputVelocity, UP, true, 4, 0.785398f, false);

        if (UseHorizontalDamp)
        {
            float damp = AirDamp;

            if (character.IsOnFloor())
            {
                damp = FloorDamp;
            }

            inputVelocity.x *= damp;
        }
    }
示例#11
0
        public virtual void _ApplySlidingSteering(Vector3 accel, float delta)
        {
            KinematicBody2D _body = (KinematicBody2D)_body_ref.GetRef();

            if (_body == null)
            {
                return;
            }

            var velocity = Utils.ToVector2(linear_velocity + accel * delta).Clamped(linear_speed_max);

            if (apply_linear_drag)
            {
                velocity = velocity.LinearInterpolate(Vector2.Zero, linear_drag_percentage);
            }
            velocity = _body.MoveAndSlide(velocity);
            if (calculate_velocities)
            {
                linear_velocity = Utils.ToVector3(velocity);
            }
        }
示例#12
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        moveDirection.y = Mathf.Min(moveDirection.y + moveGravity, moveTerminalVelocity);
        moveDirection.x = Mathf.Lerp(moveDirection.x, 0.0f, moveAirResistance);

        if (IsOnWall())
        {
            moveDirection.x *= -1.0f;
        }

        if (IsOnCeiling())
        {
            moveDirection.y *= -1.0f;
        }

        body2D.MoveAndSlide
        (
            moveDirection, // Linear velocity
            Vector2.Up     // Floor normal
        );
    }
示例#13
0
    public override void _Process(float delta)
    {
        if (!IsCPU)
        {
            Camera.GlobalPosition = KinematicBody.GlobalPosition;
            Vector2 vector = Vector2.Zero;

            if (Input.IsActionPressed("ui_up"))
            {
                vector.y -= 1;
            }
            if (Input.IsActionPressed("ui_down"))
            {
                vector.y += 1;
            }
            if (Input.IsActionPressed("ui_left"))
            {
                vector.x -= 1;
            }
            if (Input.IsActionPressed("ui_right"))
            {
                vector.x += 1;
            }

            vector = vector.Normalized();
            if (vector.Length() > 0)
            {
                DirectionFacing  = new Vector2(vector);
                IsAutoNavigating = false;
                AnimatedSprite.Play();
            }
            else if (!IsAutoNavigating)
            {
                AnimatedSprite.Stop();
            }
            KinematicBody.MoveAndSlide(vector * MovementSpeed);
        }

        if (IsAutoNavigating)
        {
            Vector2 vector = DestinationPosition - KinematicBody.GlobalPosition;
            if (vector.Length() > 50)
            {
                vector = vector.Normalized();
                KinematicBody.MoveAndSlide(vector * MovementSpeed);
                AnimatedSprite.Play();
            }
            else
            {
                IsAutoNavigating = false;
                AnimatedSprite.Stop();
            }
        }

        if (CurrentState != State.Borrow)
        {
            foreach (Unit unit in Units.ToArray())
            {
                unit.SetLeaderPosition(KinematicBody.GlobalPosition);
                unit.SetFollowing();
            }
        }

        switch (CurrentState)
        {
        case State.Idle:
            Highlight.Hide();
            DebugLabel.Hide();
            break;

        case State.Hover:
            Highlight.Show();
            DebugLabel.Hide();
            break;

        case State.Defeated:
            DebugLabel.Show();
            break;
        }

        Duration += delta;
        if (Name == "EnemyLeader1")
        {
            if (TutorialStep == 0 && Duration > 0.5)
            {
                DialogLabel.Text = "Prince, is that really you?";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && CurrentState == State.Borrow && Duration > 0.2)
            {
                DialogLabel.Text = "Borrow at ease!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 2 && CurrentState == State.Borrow && Duration > 3)
            {
                DialogLabel.Text = "Pick my units, then press done.";
            }
            else if (TutorialStep == 2 && CurrentState == State.Idle && Duration > 0.2 && GetUnits().Count == 0)
            {
                DialogLabel.Text = "Excellent!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 2 && CurrentState == State.Idle && Duration > 0.2 && GetUnits().Count > 0)
            {
                DialogLabel.Text = "Borrow my units, you'll need them.";
                Duration         = 0;
            }
            else if (TutorialStep == 3 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 4 && Duration > 0.5)
            {
                DialogLabel.Text = "Be wise borrowing units...";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 5 && Duration > 3)
            {
                DialogLabel.Text = "... or you'll be deep in debt!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 6 && Duration > 3)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 7 && Duration > 0.5)
            {
                DialogLabel.Text = "Interest rates are high around here...";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 8 && Duration > 4)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }
        else if (Name == "EnemyLeader2")
        {
            if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300)
            {
                DialogLabel.Text = "Hey, look it's the prince!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (CurrentState == State.Hover && Debt > 0)
            {
                DialogLabel.Text = "Repay my debt, to fight with honor!";
                TutorialStep     = 20;
                Duration         = 0;
            }
            else if (TutorialStep == 20 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }
        else if (Name == "EnemyLeader3")
        {
            if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300)
            {
                DialogLabel.Text = "If you borrow my men...";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && Duration > 2)
            {
                DialogLabel.Text = "... then you better pay me back";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 2 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (CurrentState == State.Borrow && TutorialStep < 10)
            {
                DialogLabel.Text = "Take what you need.";
                TutorialStep     = 10;
                Duration         = 0;
            }
            else if (TutorialStep == 10 && Duration > 3)
            {
                DialogLabel.Text = "I expect them back later.";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 11 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (CurrentState == State.Hover && Debt > 0)
            {
                DialogLabel.Text = "Repay my debt, to fight with honor!";
                TutorialStep     = 20;
                Duration         = 0;
            }
            else if (TutorialStep == 20 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }
        else if (Name == "EnemyLeader4")
        {
            if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300)
            {
                DialogLabel.Text = "This isn't amateur hour!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }
        else if (Name == "EnemyLeader5")
        {
            if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300 && PlayerLeader.GetUnits().Count <= 4)
            {
                DialogLabel.Text = "That's all you got?";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300 && PlayerLeader.GetUnits().Count > 4)
            {
                DialogLabel.Text = "You seem like a worthy opponent!";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }

        else if (Name == "EnemyLeader6")
        {
            if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300 && PlayerLeader.GetUnits().Count <= 4)
            {
                DialogLabel.Text = "I'll lend you some.";
                TutorialStep    += 1;
                Duration         = 0;
            }
            else if (TutorialStep == 0 && PlayerLeader.GetKinematicGlobalPosition().DistanceTo(GetKinematicGlobalPosition()) < 300 && PlayerLeader.GetUnits().Count > 4)
            {
                DialogLabel.Text = "I've been waiting to fight you!";
                TutorialStep     = 1;
                Duration         = 0;
            }
            else if (TutorialStep == 1 && Duration > 2)
            {
                DialogLabel.Text = "";
                TutorialStep    += 1;
                Duration         = 0;
            }
        }
    }
示例#14
0
 public override void Update(KinematicBody2D host, float delta)
 {
     _sprite.FlipH = _direction.x >= 0;
     host.MoveAndSlide(_direction.Normalized() * Speed);
 }
    public void ProcessPhysics(float delta)
    {
        _elapsedTime += delta;

        if (_kb.IsOnFloor())
        {
            _groundedTimestamp = _elapsedTime;
        }

        // Acceleration
        if (_accelerateThisFrame)
        {
            int velocityDir = Mathf.Sign(_currentVelocity.x);

            if (velocityDir != 0 && velocityDir != _accelerationDir)
            {
                Decelerate(ref _currentVelocity.x, _accelerationDir, delta);
            }
            else
            {
                Accelerate(ref _currentVelocity.x, _accelerationDir, delta);
            }
        }

        // If the player isn't accelerating, apply friction.
        if (!_accelerateThisFrame)
        {
            _currentVelocity.x += CalculateCounterAcceleration(_previousVelocity.x, _frictionConstant, delta) * delta;
        }

        // Execute a jump if a jump has been buffered.
        if (CanJump())
        {
            _currentVelocity.y = -_jumpVelocity;
            _jumpBuffered      = false;
        }

        // Determine which gravity to apply.
        float gravityThisFrame     = _currentVelocity.y < 0f ? _jumpGravity : _fallGravity;
        float verticalAcceleration = gravityThisFrame;

        // INTEGRATE NEW VELOCITY
        _currentVelocity.y += verticalAcceleration * delta;
        _currentVelocity.x  = Mathf.Clamp(_currentVelocity.x, -_maxSpeed, _maxSpeed);

        // Applying computated velocity to KinematicBody.
        bool airborne = !_kb.IsOnFloor();

        _currentVelocity = _kb.MoveAndSlide(_currentVelocity, Vector2.Up);

        #region Debug logs
        // HORIZONTAL MOVEMENT RELATED DEBUG MESSAGES.
        //if (_previousVelocity.x == 0f && _bufferedHorizontalAccleration != 0f)
        //    GD.Print($"Started accelerating: {debugTime}");

        //if (_previousVelocity.x != 0f &&_bufferedHorizontalAccleration == 0f)
        //    GD.Print($"Stopped accelerating: {debugTime}");

        //if (Mathf.Abs(_previousVelocity.x) > 0f && _currentVelocity.x == 0f)
        //    GD.Print($"Stopped moving: {debugTime}");

        // JUMP RELATED DEBUG MESSAGES.
        //if (_jumpThisTick)
        //    GD.Print($"Jumped: {debugTime}");

        //if (_previousVelocity.y < 0f && _currentVelocity.y >= 0f)
        //    GD.Print($"Reached apex of jump: {debugTime}");

        //if (_kb.IsOnFloor() && airborne)
        //    GD.Print($"Landed: {debugTime}");
        #endregion

        _previousVelocity = _currentVelocity;

        // Resetting buffered values for next frame.
        _accelerateThisFrame = false;
        _accelerationDir     = 0;
    }
示例#16
0
 public void Move()
 {
     ClampVelocity();
     _velocity = _owner.MoveAndSlide(_velocity / GetTimeScale(), Vector2.Up) * GetTimeScale();
 }
示例#17
0
 public override void Update(KinematicBody2D host, float delta)
 {
     host.MoveAndSlide(Vector2.Zero);
 }
示例#18
0
 public override void Update(KinematicBody2D host, float delta)
 {
     host.MoveAndSlide(_dir.Normalized() * Speed);
 }
示例#19
0
 public override void Update(KinematicBody2D host, float delta)
 {
     host.MoveAndSlide(_inputDirection.Normalized() * _dashSpeed, Vector2.Zero);
 }