コード例 #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 override void _Ready()
    {
        //Setup
        worldSpace      = GetWorld2d().DirectSpaceState;
        query           = new Physics2DShapeQueryParameters();
        inputDelayTimer = (Timer)GetNode("InputDelayTimer");

        mouseClickMoveTolerance = GM.MouseClickMoveTolerance;

        inputDelayTimer.Start();
    }
コード例 #3
0
        public static (float?furthestMove, float?collisionPoint) CastMotionTuple(
            this Physics2DDirectSpaceState state,
            Physics2DShapeQueryParameters param)
        {
            var motion = state.CastMotion(param);

            if (motion.Count == 0)
            {
                return(null, null);
            }
            return((float)motion[0], (float)motion[1]);
        }
コード例 #4
0
ファイル: SunPotManager.cs プロジェクト: MegaRGJ/Star
    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);
        }
    }
コード例 #5
0
 public static Array <Vector2> CollideShapeGeneric(
     this Physics2DDirectSpaceState state,
     Physics2DShapeQueryParameters param,
     int maxResults = 32)
 => new Array <Vector2>(state.CollideShape(param, maxResults));