示例#1
0
    public override PlayerState FixedUpdate(float delta)
    {
        player.Velocity.y += 100 * delta;
        player.MoveAndSlide(player.Velocity);

        Rope.RemovePoint(Rope.GetPointCount() - 1);
        Rope.AddPoint(Hook.GetCastTo());

        if (Hook.IsColliding())
        {
            DestroyHook = false;
            Hook.SetCastTo(Hook.GetCollisionPoint() - Hook.GetGlobalPosition());
            Rope.RemovePoint(Rope.GetPointCount() - 1);
            Rope.AddPoint(Hook.GetCastTo());
            RotationPoints.Push(Hook.GetCollisionPoint());

            HookState h = new HookWalkState();
            h.Init(Slack, RotationPoints);
            return(h);
        }
        if (Hook.GetCastTo().Length() > 8 * 32)
        {
            DestroyHook = true; return(new OnGroundState());
        }

        Hook.SetCastTo(Hook.GetCastTo() + delta * 1000 * Hook.GetCastTo().Normalized());

        return(null);
    }
示例#2
0
    public override PlayerState FixedUpdate(float delta)
    {
        //Update RotationPoints on the rope
        RopeRotationPointUpdate();
        Vector2 oldPos = Hook.GetGlobalPosition();
        float   radius = GetLocalRotationPoint().Length();

        //Apply forces (gravity and centripital accleration) in a rope like fashion (faking tension)
        float   ang     = Mathf.Atan2(Hook.GetCastTo().x, Hook.GetCastTo().y);
        Vector2 gravity = new Vector2(0, 150);
        Vector2 centripitalAcceleration = new Vector2(0, 0);

        if ((vel.Length() >= Mathf.Sqrt(150 * Hook.GetCastTo().Length()) || RotationPoints.Peek().y < Hook.GetGlobalPosition().y) &&
            Mathf.Abs(Slack - TotalRopeLength()) < 1)
        {
            float c = vel.LengthSquared() / Hook.GetCastTo().Length();
            centripitalAcceleration = new Vector2(c * Mathf.Sin(ang), c * Mathf.Cos(ang));
        }

        Vector2 acceleration = gravity + centripitalAcceleration;

        if (vel.Length() > 10 * radius)
        {
            vel = vel.Normalized() * 10 * radius; GD.Print("Angular Speed Limit");
        }
        player.MoveAndCollide((acceleration * delta * delta) + (vel * delta));

        //Manage Player Inputs
        if (Input.IsActionJustPressed("CommandJump"))
        {
            DestroyHook = true;
            return(new InAirState());
        }
//		if (player.IsColliding())
//		{
//			DestroyHook = false;
//			HookState next = new HookWalkState();
//			next.Init(Slack, RotationPoints, RopeNorms)
//			return next;
//		}

        float t = TotalRopeLength();

        if (Slack - t < 0)
        {
            player.MoveAndCollide(-GetLocalRotationPoint().Normalized() * (Slack - t));
        }

        vel = (Hook.GetGlobalPosition() - oldPos) / delta;
        //GD.Print(-GetLocalRotationPoint().x);

        if (Slack - TotalRopeLength() < 1)
        {
            if ((Input.IsActionPressed("CommandLeft") || Input.IsActionPressed("CommandRight")) &&
                !Input.IsActionPressed("CommandHook") && RotationPoints.Peek().y < Hook.GetGlobalPosition().y)
            {
                Vector2 swingDir = -GetLocalRotationPoint().Normalized();
                if (Input.IsActionPressed("CommandLeft") && !Input.IsActionPressed("CommandRight"))
                {
                    swingDir = new Vector2(-swingDir.y, swingDir.x);
                    if ((swingDir + vel).Length() < 10 * radius)
                    {
                        player.MoveAndSlide(swingDir);
                    }
                }
                if (Input.IsActionPressed("CommandRight") && !Input.IsActionPressed("CommandLeft"))
                {
                    swingDir = new Vector2(swingDir.y, -swingDir.x);
                    if ((swingDir + vel).Length() < 100)
                    {
                        player.MoveAndSlide(swingDir);
                    }
                }
            }
            else
            {
                //GD.Print(Mathf.Abs(GetLocalRotationPoint().x));
                if (Input.IsActionPressed("CommandHook") && Math.Abs(GetLocalRotationPoint().x) < 1 && !stopPass)
                {
                    //I should base this off of position rather than speed, otherwise I'll stop the player in weird spots
                    //Vector2 stop = -GetLocalRotationPoint().Normalized();
                    //if (vel.x < 0) { stop = new Vector2(stop.y, -stop.x); }
                    //else if (vel.x > 0) { stop = new Vector2(-stop.y, stop.x); }
                    //else { stop *= 0; }
                    //stop *= vel.Length() * 0.25f;

                    Random rand = new Random();
                    GD.Print("Stop; ", vel.Length());
                    Vector2 stop = -vel * 0.75f * Math.Abs(100 - vel.Length()) / 100;
                    player.MoveAndSlide(stop);
                    stopPass = true;
                }
                else if (Mathf.Abs(GetLocalRotationPoint().x) > 1 && stopPass)
                {
                    stopPass = false;
                }

                if (vel.Length() < 20 && vel.x != 0 && Mathf.Abs(GetLocalRotationPoint().x) < 1)
                {
                    player.MoveAndSlide(-vel);
                }

                if (Mathf.Abs(vel.x) < 1)
                {
                    if (Input.IsActionPressed("CommandUp") && !Input.IsActionPressed("CommandDown"))
                    {
                        Slack -= 25 * delta;
                    }
                    if (Input.IsActionPressed("CommandDown") && !Input.IsActionPressed("CommandUp"))
                    {
                        Slack += 25 * delta;
                    }
                }
            }
        }
        vel = (Hook.GetGlobalPosition() - oldPos) / delta;
        return(null);
    }