Пример #1
0
    public override void _Draw()
    {
        /// TODO separate the mechanics out of the drawing
        if (isMouseDragging)
        {
            dragRectBounds.Position = mousePressOrigin;
            dragRectBounds.Size     = GetLocalMousePosition() - mousePressOrigin;
            DrawRect(dragRectBounds, DragRectColor, true);
        }
        else
        {
            query = new Physics2DShapeQueryParameters();
            dragRectSelect.Extents = (GetGlobalMousePosition() - mousePressOrigin) / 2;
            query.SetShape(dragRectSelect);
            query.Transform = new Transform2D(0, (GetGlobalMousePosition() + mousePressOrigin) / 2);

            var results = worldSpace.IntersectShape(query);
            List <PlayerCharacter> players = new List <PlayerCharacter>();

            foreach (Godot.Collections.Dictionary item in results)
            {
                if (item.Contains("collider"))
                {
                    object collider = item["collider"];
                    if (collider.GetType() == typeof(PlayerCharacter))
                    {
                        players.Add((PlayerCharacter)collider);
                    }
                }
            }

            LocalCharacterManager.SelectAllInRect(players, !Input.IsActionPressed("modify"));
        }
    }
Пример #2
0
    public void OnLeftMouseClick()
    {
        var SpaceState = GetWorld2d().DirectSpaceState;

        Vector2 MousePos = GetGlobalMousePosition();

        Physics2DShapeQueryParameters Parameters = new Physics2DShapeQueryParameters();
        RectangleShape2D Shape = new RectangleShape2D();

        Shape.Extents = new Vector2(16, 16);        // Don't hate me.
        Parameters.SetShape(Shape);
        Parameters.Transform = new Transform2D(0.0f, MousePos);

        //Need to trace up/down and left/right based on the size of the object we are placing aka pot
        var result = SpaceState.IntersectShape(Parameters);

        if (result.Count == 0)
        {
            Node   SunPotNode   = SunPotScene.Instance();
            Node2D SunPotNode2D = (Node2D)SunPotNode;
            SunPotNode2D.Position = MousePos;
            AddChild(SunPotNode2D);
        }
    }