Пример #1
0
    public static void SetDisplay()
    {
        viewGrid.Visible        = false;
        mainDisplayRoot.Visible = true;

        topViewPlane.Visible   = false;
        frontViewPlane.Visible = false;
        sideViewPlane.Visible  = false;

        if (selectedView == 0)
        {
            viewGrid.Visible        = true;
            mainDisplayRoot.Visible = false;
            topViewPlane.Call("SetDisplayNode", topViewRoot.GetPath());
            frontViewPlane.Call("SetDisplayNode", frontViewRoot.GetPath());
            sideViewPlane.Call("SetDisplayNode", sideViewRoot.GetPath());

            topViewPlane.Visible   = true;
            frontViewPlane.Visible = true;
            sideViewPlane.Visible  = true;
        }
        else if (selectedView == 1)
        {
            topViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            topViewPlane.Visible = true;
        }
        else if (selectedView == 2)
        {
            frontViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            frontViewPlane.Visible = true;
        }
        else if (selectedView == 3)
        {
            sideViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            sideViewPlane.Visible = true;
        }
    }
Пример #2
0
    private async void UpdateRect()
    {
        edgeBodies = new Array <JellyAtom>();
        if (jellyAtomPacked == null)
        {
            return;
        }
        Vector2 atomSeparation = new Vector2(atomW > 1 ? rect.Size.x / (atomW - 1) : 0, atomH > 1 ? rect.Size.y / (atomH - 1) : 0);
        Vector2 origin         = rect.Position;

        foreach (Node n in GetChildren())
        {
            n.QueueFree();
        }
        mapAtoms = new Dictionary <Vector2, JellyAtom>();
        for (int j = atomH - 1; j >= 0; j--)
        {
            for (int i = atomW - 1; i >= 0; i--)
            {
                JellyAtom jellyAtom = (JellyAtom)jellyAtomPacked.Instance();

                Vector2 gridPos = new Vector2(i, j);
                jellyAtom.Position     = origin + atomSeparation * gridPos;
                jellyAtom.jelly        = this;
                jellyAtom.GravityScale = gravityScale;
                AddChild(jellyAtom);
                mapAtoms.Add(gridPos, jellyAtom);
                Vector2[] neighbours = new Vector2[] {
                    new Vector2(i + 1, j),
                    new Vector2(i, j + 1),
                    new Vector2(i + 1, j + 1),
                    new Vector2(i - 1, j + 1)
                };
                if (i == 3 && j == 3)
                {
                    foreach (Node n in GetTree().GetNodesInGroup("CameraOffset"))
                    {
                        Node2D            cameraOffset = (Node2D)n;
                        RemoteTransform2D rt           = new RemoteTransform2D();
                        rt.UpdateRotation = false;
                        rt.UpdateRotation = false;
                        rt.RemotePath     = cameraOffset.GetPath();
                        jellyAtom.AddChild(rt);
                    }
                }
                foreach (Vector2 neighbour in neighbours)
                {
                    JellyAtom neighbourBody;

                    if (!mapAtoms.TryGetValue(neighbour, out neighbourBody))
                    {
                        continue;
                    }

                    float dist = (neighbourBody.Position - jellyAtom.Position).Length();
                    neighbourBody.AddNeighbour(new Neighbour(jellyAtom, dist));
                    jellyAtom.AddNeighbour(new Neighbour(neighbourBody, dist));
                }
                //await ToSignal(GetTree(), "idle_frame");
            }
        }

        for (int i = 0; i < atomW; i++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, 0)]);
        }

        for (int j = 1; j < atomH; j++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(atomW - 1, j)]);
        }

        for (int i = atomW - 2; i >= 0; i--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, atomH - 1)]);
        }

        for (int j = atomH - 2; j >= 1; j--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(0, j)]);
        }
    }
Пример #3
0
    public void FireHook(Vector2 StartPosition, Vector2 EndPosition)
    {
        RigidBody2D Link     = (RigidBody2D)ChainLink.Duplicate();
        RigidBody2D NextLink = null;

        Link.Position       = StartPosition;
        Link.LinearVelocity = Vector2.Zero;
        Link.Visible        = true;
        AddChild(Link);

        Vector2 Direction = (EndPosition - StartPosition).Normalized();
        int     length    = CheckCollisions(StartPosition, EndPosition);

        PinJoint2D Joint = new PinJoint2D();

        Joint.Position = StartPosition - (Direction * LengthOfChainLink * (2f / 3f));
        AddChild(Joint);
        Joint.NodeA = _Player.GetPath();
        Joint.NodeB = Link.GetPath();

        Chain.Add(Joint);

        Joint          = new PinJoint2D();
        Joint.Softness = JointSoftness;
        Joint.Position = StartPosition - (Direction * LengthOfChainLink * (2f / 3f));

        for (int i = 0; i < length; i++)
        {
            NextLink           = (RigidBody2D)Link.Duplicate();
            NextLink.Position += (Direction * LengthOfChainLink);
            AddChild(NextLink);

            Chain.Add(NextLink);
            Chain.Add(Link);
            Chain.Add(Joint);

            Joint.NodeA = Link.GetPath();
            Joint.NodeB = NextLink.GetPath();

            Link = NextLink;

            AddChild(Joint);

            Vector2 OldPosition = Joint.Position;
            Joint          = new PinJoint2D();
            Joint.Softness = JointSoftness;
            Joint.Position = (OldPosition + (Direction * LengthOfChainLink));
        }

        Node2D hitNode = GetCollidingNode(StartPosition, EndPosition, NextLink.Position);

        if (hitNode != null)
        {
            GD.Print(hitNode.GetPath());
            PinJoint2D FinalJoint = new PinJoint2D();
            AddChild(FinalJoint);

            FinalJoint.Position = (NextLink.Position + (Direction * LengthOfChainLink * (2f / 3f)));
            FinalJoint.NodeA    = NextLink.GetPath();
            FinalJoint.NodeB    = hitNode.GetPath();

            Chain.Add(FinalJoint);
        }

        IsFired = true;
    }
Пример #4
0
    // This function sets which viewport/display to display to, as well as which view(s) is (are) visible
    public static void SetDisplay()
    {
        // Set grid view as invisible and main view as visible
        viewGrid.Visible        = false;
        mainDisplayRoot.Visible = true;

        // Set planeControl objects (in 3D view) as invisible
        topViewPlane.Visible       = false;
        frontViewPlane.Visible     = false;
        sideViewPlane.Visible      = false;
        auxiliaryViewPlane.Visible = false;

        // Set the display size to the main viewport size
        PlaneControl.SetScreenSize(LARGE_PLANE_X_SCALE, LARGE_PLANE_Y_SCALE, MAX_FOCUS);

        if (selectedView == (int)Views.ALL_VIEWS)
        {
            // If all views are visible, set the grid view to visible and main view to invisible
            viewGrid.Visible        = true;
            mainDisplayRoot.Visible = false;

            // Set the individual view display ndoes
            topViewPlane.Call("SetDisplayNode", topViewRoot.GetPath());
            frontViewPlane.Call("SetDisplayNode", frontViewRoot.GetPath());
            sideViewPlane.Call("SetDisplayNode", sideViewRoot.GetPath());
            auxiliaryViewPlane.Call("SetDisplayNode", auxiliaryViewRoot.GetPath());

            // Set all planeControl objects (in 3D view) as visible
            topViewPlane.Visible   = true;
            frontViewPlane.Visible = true;
            sideViewPlane.Visible  = true;

            // If auxiliary view is enabled for this object, make the auxiliary planeControl object visible
            if (isAuxEnabled)
            {
                auxiliaryViewPlane.Visible = true;
            }

            // If all views are selected, change the display size to the small viewport size
            PlaneControl.SetScreenSize(SMALL_PLANE_X_SCALE, SMALL_PLANE_Y_SCALE, MAX_FOCUS);
        }
        else if (selectedView == (int)Views.TOP_VIEW)
        {
            // If top view is selected, set top view display node and set 3D planeControl object as visible
            topViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            topViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.FRONT_VIEW)
        {
            // If front view is selected, set front view display node and set 3D planeControl object as visible
            frontViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            frontViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.SIDE_VIEW)
        {
            // If side view is selected, set side view display node and set 3D planeControl object as visible
            sideViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            sideViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.AUX_VIEW && isAuxEnabled)
        {
            // If auxiliary view is selected, set auxiliary view display node and set 3D planeControl object as visible
            auxiliaryViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            auxiliaryViewPlane.Visible = true;
        }
    }
Пример #5
0
    private void UpdateRect()
    {
        edgeBodies = new Array <RigidBody2D>();
        if (jellyAtomPacked == null)
        {
            return;
        }
        Vector2 atomSeparation = new Vector2(atomW > 1 ? rect.Size.x / (atomW - 1) : 0, atomH > 1 ? rect.Size.y / (atomH - 1) : 0);
        Vector2 origin         = rect.Position;

        foreach (Node n in mapAtoms.Values)
        {
            n.QueueFree();
        }
        mapAtoms = new Dictionary <Vector2, RigidBody2D>();
        for (int j = atomH - 1; j >= 0; j--)
        {
            for (int i = atomW - 1; i >= 0; i--)
            {
                JellyAtomJoints jellyAtom = (JellyAtomJoints)jellyAtomPacked.Instance();
                Vector2         gridPos   = new Vector2(i, j);
                jellyAtom.Position     = origin + atomSeparation * gridPos;
                jellyAtom.GravityScale = gravityScale;
                jellyAtom.Radius       = atomRadius;
                jellyAtom.SetDraggable(draggable);
                AddChild(jellyAtom);
                mapAtoms.Add(gridPos, jellyAtom);
                int mX = (int)(atomW / 2);
                int mY = (int)(atomH / 2);
                if (i == mX && j == mY)
                {
                    center   = jellyAtom;
                    rayCasts = (Node2D)GD.Load <PackedScene>("res://tests/thibault/RayCasts.tscn").Instance();
                    AddChild(rayCasts);
                    RemoteTransform2D rt = new RemoteTransform2D();
                    rt.UpdateRotation = false;
                    rt.UpdateScale    = false;
                    rt.RemotePath     = rayCasts.GetPath();
                    jellyAtom.AddChild(rt);
                    foreach (Node n in GetTree().GetNodesInGroup("CameraOffset"))
                    {
                        Node2D cameraOffset = (Node2D)n;
                        rt = new RemoteTransform2D();
                        rt.UpdateRotation = false;
                        rt.UpdateScale    = false;
                        rt.RemotePath     = cameraOffset.GetPath();
                        jellyAtom.AddChild(rt);
                    }
                }
                else if (j == mY && i == atomW - 1)
                {
                    east = jellyAtom;
                }
                Vector2[] neighbours = new Vector2[] {
                    new Vector2(i + 1, j),
                    new Vector2(i, j + 1),
                    new Vector2(i + 1, j + 1),
                    new Vector2(i - 1, j + 1)
                };
                foreach (Vector2 neighbour in neighbours)
                {
                    RigidBody2D neighbourBody;

                    if (!mapAtoms.TryGetValue(neighbour, out neighbourBody))
                    {
                        continue;
                    }

                    JellyJoint joint      = new JellyJoint();
                    Vector2    separation = new Vector2(neighbourBody.Position - jellyAtom.Position);
                    joint.Position         = jellyAtom.Position;
                    joint.RestLength       = separation.Length();
                    joint.Rotation         = separation.Angle() - Mathf.Pi / 2;
                    joint.Length           = separation.Length();
                    joint.NodeA            = jellyAtom.GetPath();
                    joint.NodeB            = neighbourBody.GetPath();
                    joint.DisableCollision = false;
                    joint.Stiffness        = stiffness;
                    joint.Damping          = damping;
                    joints.Add(joint);
                    // RemoteTransform2D rt = new RemoteTransform2D();
                    // rt.UpdateRotation = false;
                    // rt.UpdateScale = false;
                    // joint.Scale = new Vector2(0.1f, 0.1f);
                    AddChild(joint);
                    // rt.RemotePath = joint.GetPath();
                    // jellyAtom.AddChild(rt);
                }
            }
        }

        for (int i = 0; i < atomW; i++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, 0)]);
        }

        for (int j = 1; j < atomH; j++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(atomW - 1, j)]);
        }

        for (int i = atomW - 2; i >= 0; i--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, atomH - 1)]);
        }

        for (int j = atomH - 2; j >= 1; j--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(0, j)]);
        }
    }