コード例 #1
0
ファイル: Player.cs プロジェクト: nick-warfield/Reso-Fork
    protected void RopeRotationPointUpdate()
    {
        Hook.SetCastTo(GetLocalRotationPoint());
        Hook.ForceRaycastUpdate();

        if (Hook.IsColliding())
        {
            //add a rotation point
            float difference = (Hook.GetCollisionPoint() - RotationPoints.Peek()).Length();
            if (difference > 1)
            {
                Vector2 norm = (Hook.GetGlobalPosition() - Hook.GetCollisionPoint()).Normalized();
                norm = new Vector2(norm.y, -norm.x);
                if (norm.Dot(Hook.GetCollisionNormal()) < 0)
                {
                    norm *= -1;
                }

                RopeNorms.Push(norm);
                RotationPoints.Push(Hook.GetCollisionPoint());
            }
        }

        if (RotationPoints.Count > 1 && RopeNorms.Count > 0)
        {
            //remove a rotation point
            if (RopeNorms.Peek().Dot(GetLocalRotationPoint()) < 0)
            {
                RotationPoints.Pop(); RopeNorms.Pop();
            }
        }

        //Update rotation point and rope feedback
        Hook.SetCastTo(GetLocalRotationPoint());
        Hook.ForceRaycastUpdate();

        for (int i = 0; i < RotationPoints.Count; i++)
        {
            Vector2[] temp = new Vector2[RotationPoints.Count];
            RotationPoints.CopyTo(temp, 0);
            if (Rope.GetPointCount() <= i + 1)
            {
                Rope.AddPoint(temp[i] - Hook.GetGlobalPosition());
            }
            else
            {
                Rope.SetPointPosition(i + 1, temp[i] - Hook.GetGlobalPosition());
            }
        }
        for (int i = RotationPoints.Count + 1; i < Rope.GetPointCount(); i++)
        {
            Rope.RemovePoint(i);
        }
    }
コード例 #2
0
    public void SetGenericPointer(Vector2 point)
    {
        genericPointer = point;
        while (genericPointerLine.GetPointCount() != 0)
        {
            genericPointerLine.RemovePoint(genericPointerLine.GetPointCount() - 1);
        }
        float n = 1.3f;

        genericPointerLine.SetDefaultColor(new Color(nationColor.r / n, nationColor.g / n, nationColor.b / n, 1));
        genericPointerLine.AddPoint(new Vector2(0, 0));
        genericPointerLine.AddPoint(genericPointer);
    }
コード例 #3
0
    public override void _PhysicsProcess(float delta)
    {
        Vector2 _point = ((Node2D)(GetParent())).GlobalPosition;

        _line.AddPoint(_point);
        while (_line.GetPointCount() > _length)
        {
            _line.RemovePoint(0);
        }
    }
コード例 #4
0
    // Bug: Den tegner strek UANSETT om den treffer en av sine egne linjer. Tenker ikke noe på om det finnes en strek som er nærmere eller om den går igjennom en annen sitt land.
    internal void SuggestConquest(InputEventMouseButton key)
    {
        double d1;

        differ = 0.025;

        d1 = Math.Tan(Map.mousePointingDegree * Math.PI / 180);

        Nation    targetNation = (Nation)(nations[Map.mousePointingNation]);
        ArrayList points       = targetNation.GetPoints();
        Vector2   mp           = GetGlobalMousePosition();

        suggestedPoints = new ArrayList();
        ArrayList tempLineSuggestions = new ArrayList();
        int       previous            = -1;
        int       next = -1;



        for (int i = 0; i < points.Count; i++)
        {
            // GD.Print("------------" + points.Count);
            Vector2 p1 = (Vector2)points[i];
            Vector2 p2 = (Vector2)points[(i + 1) % points.Count];
            double  a  = (p2.y + size) - (p1.y + size);
            double  b  = (p2.x + size) - (p1.x + size);
            double  d2 = a / b;

            double x;
            double y;

            if (!(d1 > d2 - differ && d1 < d2 + differ))
            {
                //TODO flytt dette til en generell sjekk hvor kuttes metode - Da kan jeg lett(ere) få til NATIONTEXT yalll!

                if (p1.x == p2.x)
                {
                    // Få til spesial tilfelle der x = 0 eller y = inf
                    x = p1.x;
                    y = (mp.y + (d1 * (x - mp.x)));
                }
                else
                {
                    double y1 = (mp.y + (d1 * -mp.x));
                    double y2 = (p1.y + (d2 * -p1.x));
                    x = ((y2 - y1) / (d1 - d2));
                    y = (d1 * x + y1);
                }

                // GD.Print("X: " + x + ", Y: " + y + " I mellom punkt: (" + p1.x + ", " + p1.y + ") og (" + p2.x + ", " + p2.y + ")");
                if (CheckX(p1, p2, x))
                {
                    if (CheckY(p1, p2, y))
                    {
                        tempLineSuggestions.Add(new LineSuggestion(new Vector2((float)(x), (float)(y)), i, tempLineSuggestions.Count));
                    }
                }
            }
        }

        if (tempLineSuggestions.Count < 2)
        {
            return;
        }

        LineSuggestion suggestionPoint1 = FindSmallestDistance(tempLineSuggestions.ToArray(typeof(LineSuggestion)) as LineSuggestion[], mp, null);

        tempLineSuggestions.RemoveAt(suggestionPoint1.tempindex);
        LineSuggestion suggestionPoint2 = FindSmallestDistance(tempLineSuggestions.ToArray(typeof(LineSuggestion)) as LineSuggestion[], mp, suggestionPoint1);

        if (suggestionPoint1.index < suggestionPoint2.index)
        {
            previous = suggestionPoint1.index;
            suggestedPoints.Add(suggestionPoint1.line);

            next = suggestionPoint2.index + 1;
            suggestedPoints.Add(suggestionPoint2.line);
        }
        else
        {
            previous = suggestionPoint2.index;
            suggestedPoints.Add(suggestionPoint2.line);

            next = suggestionPoint1.index + 1;
            suggestedPoints.Add(suggestionPoint1.line);
        }

        while (suggestedConquestLine2D.GetPointCount() != 0)
        {
            suggestedConquestLine2D.RemovePoint(suggestedConquestLine2D.GetPointCount() - 1);
        }
        for (int i = 0; i < suggestedPoints.Count; i++)
        {
            suggestedConquestLine2D.AddPoint(mp);
            suggestedConquestLine2D.AddPoint((Vector2)suggestedPoints[i]);
        }

        if (key != null && key.IsPressed() && key.ButtonIndex == 2)
        {
            TryConquest(previous, next, targetNation, key.Shift);
        }
    }