コード例 #1
0
    public override void _Input(InputEvent e)
    {
        if (e is InputEventMouseButton iemb)
        {
            Vector2 pos = ToLocal(iemb.GetPosition());
            if (InputUtil.IsLeftPress(iemb) && rect.HasPoint(pos))
            {
                OnLeftPress();
            }
        }

        if (e is InputEventMouseMotion iemm)
        {
            Vector2 pos = ToLocal(iemm.GetPosition());
            if (rect.HasPoint(pos))
            {
                hovered = true;
                OnHover();
            }
            else
            {
                if (hovered)
                {
                    hovered = false;
                    OnHoverOff();
                }
            }
        }
    }
コード例 #2
0
        protected List <BaseEntity> GetCurrentEntitiesOnScreen()
        {
            var rect     = new Rect2(GlobalPosition, 72, 48);
            var entities = GetTree().GetNodesInGroup("entity").Cast <BaseEntity>();

            return(entities.Where(entity => rect.HasPoint(entity.GlobalPosition)).ToList());
        }
コード例 #3
0
    public override void _Process(float delta)
    {
        if (Engine.EditorHint)
        {
            if (edgeColor.a != 0)
            {
                GetNode <TextureRect>("Edge").Modulate = edgeColor;
            }
            return;
        }

        // check if the mouse is over the button; ie, if we're being hovered
        hovered = origRect.HasPoint(GetLocalMousePosition());

        if (hovered)
        {
            this.RectScale = origScale * enlargeFactor;

            var parent    = GetParent();
            var bigParent = GetParent().GetParent();

            // move this node and parent node to bottom of the respective trees they are in
            // this ensures they are drawn on top of everything else
            // and the buttonRect thing we do ensures the hover detection is still accurate
            parent.MoveChild(this, parent.GetChildCount() - 1);
            bigParent.MoveChild(parent, bigParent.GetChildCount() - 1);
        }
        else
        {
            this.RectScale = origScale;
        }
    }
コード例 #4
0
ファイル: AdjacencyHelper.cs プロジェクト: Nosrick/JoyGodot
        public static bool IsInRange(Vector2Int left, Vector2Int right, int range)
        {
            Rect2 rangeRect = new Rect2(left.ToVec2(), new Vector2(1, 1));

            rangeRect = rangeRect.Grow(range);
            return(rangeRect.HasPoint(right.ToVec2()));
        }
コード例 #5
0
ファイル: Bullet.cs プロジェクト: exts/ld44
        public override void _Process(float delta)
        {
            DeleteSelf();

            if (!_hideUntil.HasPoint(Position))
            {
                Visible = true;
            }

            Position += _direction * delta;
        }
コード例 #6
0
 public override void _Process(float delta)
 {
     if (rect.HasPoint(GetGlobalMousePosition()))
     {
         Input.SetDefaultCursorShape(Input.CursorShape.PointingHand);
     }
     else
     {
         Input.SetDefaultCursorShape();
     }
 }
コード例 #7
0
        public static bool IsPointOnGUI(this Node parent, Vector2 point)
        {
            List <Control> panels = GetAllControls(parent);

            foreach (Control panel in panels)
            {
                Rect2 rect = new Rect2(panel.RectGlobalPosition, panel.RectSize);
                if (rect.HasPoint(point))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Lookup direction from flow.
        /// </summary>
        /// <param name="position">Position</param>
        /// <returns>Direction vector</returns>
        public Vector2 Lookup(Vector2 position)
        {
            var rect = new Rect2(GlobalPosition, size);

            if (rect.HasPoint(position))
            {
                var x = (int)Mathf.Clamp((position.x - GlobalPosition.x) / Resolution, 0, cols - 1);
                var y = (int)Mathf.Clamp((position.y - GlobalPosition.y) / Resolution, 0, rows - 1);
                return(field[x + (y * cols)].Direction);
            }
            else
            {
                return(Vector2.Zero);
            }
        }
コード例 #9
0
    private Stage GetStageAt(Vector2 globalPosition)
    {
        for (int i = 0; i < stages.GetChildCount(); i++)
        {
            Stage stage  = stages.GetChildOrNull <Stage>(i);
            Rect2 global = stage.GetGlobalRect();

            if (global.HasPoint(globalPosition))
            {
                return(stage);
            }
        }

        return(null);
    }
コード例 #10
0
ファイル: ZoomArea.cs プロジェクト: danb10/godot-scripts
 public override void _Process(float delta)
 {
     if (!Enabled)
     {
         return;
     }
     if (_rect.HasPoint(_player.GlobalPosition))
     {
         float zoomFactor;
         if (ZoomY)
         {
             if (Magnification < 1)
             {
                 zoomFactor = 1 - Magnification * Mathf.Abs(_rect.Position.y - _player.GlobalPosition.y) / Mathf.Abs(_rect.Position.y - _rect.End.y);
             }
             else
             {
                 zoomFactor = Mathf.Clamp(Magnification * Mathf.Abs(_rect.Position.y - _player.GlobalPosition.y) / Mathf.Abs(_rect.Position.y - _rect.End.y), DefaultZoom, Magnification);
             }
         }
         else
         {
             if (Magnification < 1)
             {
                 zoomFactor = 1 - Magnification * Mathf.Abs(_rect.Position.x - _player.GlobalPosition.x) / Mathf.Abs(_rect.Position.x - _rect.End.x);
             }
             else
             {
                 zoomFactor = Mathf.Clamp(Magnification * Mathf.Abs(_rect.Position.x - _player.GlobalPosition.x) / Mathf.Abs(_rect.Position.x - _rect.End.x), DefaultZoom, Magnification);
             }
         }
         zoomFactor = (float)Math.Round(zoomFactor, 2, MidpointRounding.AwayFromZero);
         if (Mathf.Abs(1 - zoomFactor - Magnification) <= 0.05)
         {
             zoomFactor = 1 - Magnification;
         }
         if (Mathf.Abs(zoomFactor - DefaultZoom) <= 0.05)
         {
             zoomFactor = DefaultZoom;
         }
         _currentZoomFactor = zoomFactor;
         if (_camera.Zoom == new Vector2(_currentZoomFactor, _currentZoomFactor))
         {
             return;
         }
         _camera.Zoom = new Vector2(zoomFactor, zoomFactor);
     }
 }
コード例 #11
0
    public void activate()
    {
        var rect = new Rect2(GlobalPosition, GDKnyttAssetManager.TILE_WIDTH, GDKnyttAssetManager.TILE_HEIGHT);

        foreach (var layer in GDArea.Objects.Layers)
        {
            foreach (GDKnyttBaseObject knytt_object in layer.GetChildren())
            {
                // TODO: delete by collision shape
                if (knytt_object != this && rect.HasPoint(knytt_object.Center))
                {
                    knytt_object.QueueFree();
                }
            }
        }
    }
コード例 #12
0
    public FSM.State OnFollowing(float delta)
    {
        if (LockTarget)
        {
            Rect2 limits = GetLimits();
            if (!limits.HasPoint(Target.Position))
            {
                Target.Position = ClampToLimits(Target.Position);
            }
        }
        if (Target != null)
        {
            Position = Target.Position;
        }



        return(STATE_FOLLOWING);
    }
コード例 #13
0
    public override void _Process(float delta)
    {
        var rect          = new Rect2(_animatee.RectGlobalPosition, _animatee.RectSize);
        var mousePosition = _animatee.GetGlobalMousePosition();

        var entered = rect.HasPoint(mousePosition);

        if (entered == _entered)
        {
            return;
        }

        _entered = entered;
        if (_entered)
        {
            _tween.InterpolateProperty(this, "offset", Offset, new Vector2(), AnimationTime, Tween.TransitionType.Quad, Tween.EaseType.In);
        }
        else
        {
            _tween.InterpolateProperty(this, "offset", Offset, GetSlideInOffset(), AnimationTime, Tween.TransitionType.Quad, Tween.EaseType.In);
        }
        _tween.Start();
    }
コード例 #14
0
        public override void _GuiInput(InputEvent ev)
        {
            if (!(ev is InputEventMouse))
            {
                return;
            }

            InputEventMouse evM = (InputEventMouse)ev;

            Vector2 mousePos    = evM.Position;
            Vector2 relCurvePos = mousePos;

            relCurvePos.x = Mathf.InverseLerp(MARGIN, RectSize.x - MARGIN, relCurvePos.x);
            relCurvePos.y = Mathf.InverseLerp(RectSize.y - MARGIN, MARGIN, relCurvePos.y);

            relCurvePos.x = Mathf.Clamp(relCurvePos.x, 0, 1);
            relCurvePos.y = Mathf.Clamp(relCurvePos.y, 0, 1);

            int handleIdx        = -1;
            int handleTangentIdx = 0;

            int pointCount = curve.GetPointCount();

            for (int i = 0; i < pointCount; i++)
            {
                Vector2 handlePos = GetHandlePos(i);
                Rect2   r         = new Rect2();

                r.Position = handlePos - Vector2.One * (HANDLE_SIZE / 2f);
                r.Size     = Vector2.One * HANDLE_SIZE;

                if (r.HasPoint(mousePos))
                {
                    handleIdx = i;
                }

                if (i > 0)
                {
                    Vector2 tangentPos = GetHandleLeftTangent(i);
                    r.Position = tangentPos - Vector2.One * (TANGENT_HANDLE_SIZE / 2f);
                    r.Size     = Vector2.One * TANGENT_HANDLE_SIZE;

                    if (r.HasPoint(mousePos))
                    {
                        handleTangentIdx = -1;
                    }
                }
                if (i < pointCount - 1)
                {
                    Vector2 tangentPos = GetHandleRightTangent(i);
                    r.Position = tangentPos - Vector2.One * (TANGENT_HANDLE_SIZE / 2f);
                    r.Size     = Vector2.One * TANGENT_HANDLE_SIZE;

                    if (r.HasPoint(mousePos))
                    {
                        handleTangentIdx = 1;
                    }
                }
            }

            if (ev is InputEventMouseButton)
            {
                InputEventMouseButton evMB = ev as InputEventMouseButton;

                if (evMB.ButtonIndex == (int)ButtonList.Left)
                {
                    if (evMB.Pressed)
                    {
                        if (handleTangentIdx != 0)
                        {
                            dragTangentIdx = handleTangentIdx;
                        }
                        else
                        {
                            if (handleIdx == -1)
                            {
                                handleIdx   = curve.AddPoint(relCurvePos);
                                selectedIdx = handleIdx;
                                dragIdx     = handleIdx;
                            }
                            else
                            {
                                selectedIdx = handleIdx;
                                dragIdx     = handleIdx;
                            }
                        }
                    }
                    else
                    {
                        dragTangentIdx = 0;
                        dragIdx        = -1;
                    }
                }
                if (evMB.ButtonIndex == (int)ButtonList.Right)
                {
                    if (evMB.Pressed)
                    {
                        if (handleIdx != -1)
                        {
                            curve.RemovePoint(handleIdx);
                            if (selectedIdx == handleIdx)
                            {
                                selectedIdx = -1;
                            }
                            handleIdx = -1;
                        }
                    }
                }
            }
            if (ev is InputEventMouseMotion)
            {
                if (dragIdx != -1)
                {
                    curve.SetPointOffset(dragIdx, relCurvePos.x);
                    curve.SetPointValue(dragIdx, relCurvePos.y);
                }
                if (dragTangentIdx != 0)
                {
                    Vector2 handlePos = GetHandlePos(selectedIdx);
                    Vector2 dir       = (mousePos - handlePos).Normalized();

                    float tangent;
                    if (!Mathf.IsZeroApprox(dir.x))
                    {
                        tangent = dir.y / dir.x;
                    }
                    else
                    {
                        tangent = 9999f * (dir.y >= 0 ? 1 : -1);
                    }

                    bool link = !Input.IsKeyPressed((int)KeyList.Shift);

                    if (dragTangentIdx == 1)
                    {
                        curve.SetPointRightTangent(selectedIdx, -tangent);
                        link &= selectedIdx > 0 && curve.GetPointLeftMode(selectedIdx) != Curve.TangentMode.Linear;
                        if (link)
                        {
                            curve.SetPointLeftTangent(selectedIdx, -tangent);
                        }
                    }
                    else
                    {
                        curve.SetPointLeftTangent(selectedIdx, -tangent);
                        link &= selectedIdx < pointCount - 1 && curve.GetPointRightMode(selectedIdx) != Curve.TangentMode.Linear;
                        if (link)
                        {
                            curve.SetPointRightTangent(selectedIdx, -tangent);
                        }
                    }
                }
            }

            if (dragIdx != -1)
            {
                hoverIdx = dragIdx;
            }

            hoverIdx        = handleIdx;
            hoverTangentIdx = handleTangentIdx;
            Update();
        }
コード例 #15
0
ファイル: SpawnZones.cs プロジェクト: Cevantime/IceBravery
    public override void _Process(float delta)
    {
        float   spawnZoneExtends = 640;
        Vector2 globalPosition   = ((Node2D)Referer).GlobalPosition;
        Rect2   spawnZone        = new Rect2(globalPosition, spawnZoneExtends, spawnZoneExtends);

        foreach (Node n in GetTree().GetNodesInGroup("EndPositions"))
        {
            Position2D pos = (Position2D)n;
            LavaBlock  lb  = (LavaBlock)pos.GetParent();
            if (spawnZone.HasPoint(pos.GlobalPosition) && !lb.loadedNext)
            {
                PackedScene nextToSpawn = GD.Load <PackedScene>("tests/thibault/lava_blocks/" + lb.nexts[(int)(GD.Randi() % lb.nexts.Count)] + ".tscn");
                LavaBlock   nextBlock   = (LavaBlock)nextToSpawn.Instance();
                nextBlock.camera         = lb.camera;
                nextBlock.GlobalPosition = pos.GlobalPosition;
                Referer.GetParent().AddChild(nextBlock);
                lb.loadedNext = true;
                Array <LavaSurfaceBurn> nextLavas = new Array <LavaSurfaceBurn>();
                foreach (Node n2 in GetTree().GetNodesInGroup("LavaBurn"))
                {
                    LavaSurfaceBurn l = (LavaSurfaceBurn)n2;
                    if (l.GetParent() == nextBlock)
                    {
                        nextLavas.Add(l);
                    }
                }

                for (int i = 0; i < nextLavas.Count; i++)
                {
                    if (i != 0 || lavaSurface.isInterrupted)
                    {
                        surfaces.Add(lavaSurface);
                        lavaSurface = (LavaSurfaceBurn)lavaPacked.Instance();
                        GetTree().CurrentScene.AddChild(lavaSurface);
                    }

                    LavaSurfaceBurn nextLava = nextLavas[i];
                    Vector2         offset   = nextLava.GlobalPosition;
                    foreach (Vector2 p in nextLava.Points)
                    {
                        lavaSurface.AddPoint(p + offset);
                    }

                    lavaSurface.isInterrupted = nextLava.isInterrupted;
                    nextLava.QueueFree();
                }
            }
            else if ((pos.GlobalPosition.x - globalPosition.x) < -spawnZoneExtends)
            {
                lb.QueueFree();
                while (surfaces.Count > 0)
                {
                    LavaSurfaceBurn ls   = surfaces[0];
                    float           maxX = 0;
                    for (int i = 0; i < ls.Points.Length; i++)
                    {
                        maxX = Mathf.Max(maxX, ls.GetPointPosition(i).x);
                    }
                    if (maxX - globalPosition.x < -spawnZoneExtends)
                    {
                        surfaces.RemoveAt(0);
                        ls.QueueFree();
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }
コード例 #16
0
ファイル: TouchPanel.cs プロジェクト: akien-mga/yknytt
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventScreenTouch || @event is InputEventScreenDrag)
        {
            Vector2 position = @event is InputEventScreenTouch ?
                               (@event as InputEventScreenTouch).Position :
                               (@event as InputEventScreenDrag).Position;

            bool released = @event is InputEventScreenTouch && !(@event as InputEventScreenTouch).Pressed;

            if (released)
            {
                foreach (var p in allRectangles.Zip(actionNames, (a, b) => new { Rect = a, Name = b }))
                {
                    if (p.Rect.HasPoint(position))
                    {
                        Input.ActionRelease(p.Name);
                    }
                }

                if (leftRect.HasPoint(position))
                {
                    Input.ActionRelease("right");
                }
                if (rightRect.HasPoint(position))
                {
                    Input.ActionRelease("left");
                }
            }
            else if (@event is InputEventScreenDrag drag_event)
            {
                var speed        = drag_event.Speed;
                var rel          = drag_event.Relative;
                var old_position = drag_event.Position - drag_event.Relative;

                // Release action if the user lefts the button
                if ((leftRect.HasPoint(old_position) && !leftRect.HasPoint(position)) ||
                    (rightRect.HasPoint(old_position) && !rightRect.HasPoint(position)))
                {
                    Input.ActionRelease(Input.IsActionPressed("left") ? "left" : "right");
                }

                foreach (var p in allRectangles.Zip(actionNames, (a, b) => new { Rect = a, Name = b }))
                {
                    if (p.Rect.HasPoint(old_position) && !p.Rect.HasPoint(position))
                    {
                        Input.ActionRelease(p.Name);
                    }
                }

                // If user swipes left/right too fast, left/right action can be pressed in advance
                if (leftRect.HasPoint(position) || rightRect.HasPoint(position))
                {
                    if (speed.x > SPEED_TOO_FAST || rel.x > REL_TOO_FAST)
                    {
                        Input.ActionRelease("left");
                        Input.ActionPress("right");
                    }
                    if (speed.x < -SPEED_TOO_FAST || rel.x < -REL_TOO_FAST)
                    {
                        Input.ActionRelease("right");
                        Input.ActionPress("left");
                    }
                }

                // If user swipes back after this, original direction should be restored
                // Swiping up/down (too slow on X) should not affect this
                if (leftRect.HasPoint(position) && !(Input.IsActionPressed("right") && rel.x >= -REL_TOO_SLOW))
                {
                    Input.ActionRelease("right");
                    Input.ActionPress("left");
                }
                if (rightRect.HasPoint(position) && !(Input.IsActionPressed("left") && rel.x <= REL_TOO_SLOW))
                {
                    Input.ActionRelease("left");
                    Input.ActionPress("right");
                }

                if (downRect.HasPoint(position))
                {
                    Input.ActionPress("down");
                }
                if (upRect.HasPoint(position))
                {
                    Input.ActionPress("up");
                }
            }
            else
            {
                foreach (var p in allRectangles.Zip(actionNames, (a, b) => new { Rect = a, Name = b }))
                {
                    if (p.Rect.HasPoint(position))
                    {
                        Input.ActionPress(p.Name);
                    }
                }
            }

            ChangeOpacity(leftUpPanel, Input.IsActionPressed("left") && Input.IsActionPressed("up"));
            ChangeOpacity(rightUpPanel, Input.IsActionPressed("right") && Input.IsActionPressed("up"));
            ChangeOpacity(leftPanel, Input.IsActionPressed("left") && !Input.IsActionPressed("up"));
            ChangeOpacity(rightPanel, Input.IsActionPressed("right") && !Input.IsActionPressed("up"));
            ChangeOpacity(downPanel, Input.IsActionPressed("down"));
            foreach (var p in jumpPanels.Zip(jumpActionNames, (a, b) => new { Pan = a, Name = b }))
            {
                if (p.Name == "pause")
                {
                    continue;
                }
                ChangeOpacity(p.Pan, Input.IsActionPressed(p.Name));
            }
        }
    }
コード例 #17
0
ファイル: AdjacencyHelper.cs プロジェクト: Nosrick/JoyGodot
        public static bool IsAdjacent(Vector2Int left, Vector2Int right)
        {
            Rect2 adjacency = new Rect2(left.x - 1, left.y - 1, 3, 3);

            return(adjacency.HasPoint(right.ToVec2()));
        }