示例#1
0
    public override void _Process(float delta)
    {
        float ropeNotUsed = ropeLength - p1.Position.DistanceTo(p2.Position);


        base._Process(delta);
        ropeDraw.ClearPoints();
        ropeDraw.AddPoint(p1.Position);

        for (int i = 1; i < ropePoints; i++)
        {
            float lerpVal = (float)i / (float)ropePoints;

            //	GD.Print("Lerp val : " + lerpVal);
            //	GD.Print("From " + i + " /" + ropePoints);
            Vector2 tempPoint = vec2Lerp(p2.Position, p1.Position, lerpVal);
            if (lerpVal >= 0.5f)
            {
                tempPoint.y += ropeNotUsed * -(lerpVal - 1) * lerpVal;
                //GD.Print("Adjusted Lerp val : " + (-(lerpVal - 1)));
            }
            else
            {
                tempPoint.y += ropeNotUsed * lerpVal * -(lerpVal - 1);
            }
            ////GD.Print("Temp point loc : " + tempPoint);
            ropeDraw.AddPoint(tempPoint);
        }

        ropeDraw.AddPoint(p2.Position);
    }
示例#2
0
 public override void _Process(float delta)
 {
     //clear old lines
     foreach (Line2D l in lines)
     {
         l.ClearPoints();
         l.QueueFree();
     }
     lines.Clear();
     //calculate and draw all lines.
     for (int x = 0; x < leaves.Count; x++)
     {
         for (int y = x; y < leaves.Count; y++)
         {
             if (leaves[x].Position.DistanceTo(leaves[y].Position) < seperationDistance)
             {
                 //draw line
                 Line2D newLine = new Line2D();
                 newLine.AddPoint(leaves[x].Position);
                 newLine.AddPoint(leaves[y].Position);
                 newLine.SetWidth(2);
                 AddChild(newLine);
                 lines.Add(newLine);
             }
         }
     }
     //update all particles
     foreach (IndividualParticle i in leaves)
     {
         i.update(delta);
     }
 }
示例#3
0
 public void shoot(Vector2 end)
 {
     bulletPath.ClearPoints();
     bulletPath.AddPoint(ZERO);
     bulletPath.AddPoint(end);
     particles2D.Position = end;
     bulletAnimationPlayer.Play("Shoot");
 }
示例#4
0
 private void DrawLine(Building b, Color color)
 {
     line2d = new Line2D();
     line2d.DefaultColor = color;
     Game.root.AddChild(line2d);
     line2d.Width = 2;
     line2d.AddPoint(PlayerMouvements.instance.Position);
     line2d.AddPoint(b.Position);
 }
示例#5
0
    private void UpdateLine()
    {
        protonLine.ClearPoints();

        if (closest != null)
        {
            protonLine.AddPoint(GlobalPosition);
            protonLine.AddPoint(closest.GlobalPosition);
        }
    }
示例#6
0
    void AddNewLine(Vector2 start, Vector2 finish, int width)
    {
        Line2D newLine = new Line2D();

        newLine.AddPoint(start);
        newLine.AddPoint(finish);
        newLine.DefaultColor = lineColor;
        newLine.Width        = width;

        ConnectionGroup.AddChild(newLine);
    }
示例#7
0
        /// <summary>
        ///   Creates a line.
        /// </summary>
        /// <param name="start">The start point of the line.</param>
        /// <param name="end">The end point of the line.</param>
        /// <param name="color">The color of the line.</param>
        /// <returns>The created line.</returns>
        public static Line2D CreateLine(Vector2 start, Vector2 end, Color color)
        {
            var line = new Line2D {
                Width = 0.5f, DefaultColor = color
            };

            line.AddPoint(start);
            line.AddPoint(end);

            return(line);
        }
示例#8
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);
    }
示例#9
0
    public void FireWeapon(Destroyable target, Weapon weapon)
    {
        if (weapon == Weapon.Missile && CanMissileFire)
        {
            Missile missile1 = (Missile)MissileScene.Instance();
            missile1.Homing         = MissileHoming;
            missile1.Target         = target;
            missile1.GlobalRotation = GlobalRotation;
            missile1.Position       = GlobalPosition;
            missile1.Position      += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90));
            missile1.Velocity       = Velocity;
            missile1.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)), ProjectileEjectionForce);
            GetParent().AddChild(missile1);

            Missile missile2 = (Missile)MissileScene.Instance();
            missile2.Homing         = MissileHoming;
            missile2.Target         = target;
            missile2.GlobalRotation = GlobalRotation;
            missile2.Position       = GlobalPosition;
            missile2.Position      += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90));
            missile2.Velocity       = Velocity;
            missile2.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)), ProjectileEjectionForce);
            GetParent().AddChild(missile2);

            CanMissileFire = false;
            missileCooldownTimer.Start(MissileCooldown);
        }
        else if (weapon == Weapon.Laser && CanLaserFire)
        {
            if (target is SpaceDamagable damagable)
            {
                beam.AddPoint(target.GlobalPosition - GlobalPosition);
                damagable.Hit();
                CanLaserFire = false;
                laserCooldownTimer.Start(LaserCooldown);
            }
        }
        else if (weapon == Weapon.Railgun && CanRailgunFire)
        {
            Rail rail = (Rail)RailScene.Instance();
            rail.PartialHoming = RailHoming;
            rail.Velocity      = Velocity;
            if (target != null)
            {
                rail.Target         = target;
                rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition());
                rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce);
            }
            else
            {
                rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition());
                rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce);
            }
            rail.Position = GlobalPosition;
            GetParent().AddChild(rail);

            CanRailgunFire = false;
            railgunCooldownTimer.Start(RailgunCooldown);
        }
    }
示例#10
0
    public override void Enter()
    {
        Hook = (RayCast2D)player.FindNode("Hook");
        Rope = (Line2D)player.FindNode("Rope");

        if (Hook == null)
        {
            Hook = new RayCast2D();
            Hook.SetName("Hook");
            Hook.SetPosition(new Vector2(0, 0));
            Hook.SetEnabled(false);

            Rope = new Line2D();
            Rope.SetName("Rope");
            Rope.SetWidth(1);
            Rope.SetDefaultColor(new Color(1, 1, 1));
            //Rope.SetTexture(ResourceLoader.Load("res://Player/HookReticule.png"));
            Rope.AddPoint(new Vector2(0, 0));
            //Rope.SetVisible(false);
            Rope.SetBeginCapMode(2);
            Rope.SetEndCapMode(2);
            Rope.SetJointMode(2);

            player.AddChild(Hook);
            Hook.AddChild(Rope);

            Hook.SetOwner(player);
            Rope.SetOwner(player);
        }
    }
示例#11
0
    //PAINT LINE
    public void paintLine()
    {
        //coords
        int     center       = subNav.cuadros.GetLength(0) / 2;
        float   cellHalf     = tmZone.CellSize.x / 2;
        Vector2 centerOffSet = new Vector2(-center, -center) * tmZone.CellSize.x;

        Vector2 mworld       = GetGlobalMousePosition() - Position + new Vector2(cellHalf, cellHalf);
        Vector2 mouseCellPos = tmZone.WorldToMap(mworld);

        subNav.createPath(
            center, center,                                             //s
            (int)mouseCellPos.x + center, (int)mouseCellPos.y + center, //f
            navAgentType);

        subNav.createActualPath();//exec

        //init paint
        Vector3[] path = subNav.path;
        if (path.Length < 2)
        {
            return;               //no nulo
        }
        if (subNav.totalPathWeight > movePoints)
        {
            return;                                   //no tiene puntos de movimiento
        }
        line2D.ClearPoints();

        //next
        Vector2 lastPw = centerOffSet + (new Vector2(path[0].x, path[0].y) * tmZone.CellSize);

        foreach (Vector3 pw in path)
        {
            Vector2 pw2 = centerOffSet + (new Vector2(pw.x, pw.y) * tmZone.CellSize);
            line2D.AddPoint(lastPw);
            lastPw = pw2;
        }

        //finaly
        if (path.Length > 0)
        {
            Vector2 pwFinal = new Vector2(path[path.Length - 1].x, path[path.Length - 1].y);
            lastPw = centerOffSet + (new Vector2(pwFinal.x, pwFinal.y) * tmZone.CellSize);
            line2D.AddPoint(lastPw);
        }
    }
示例#12
0
    public override void _PhysicsProcess(float delta)
    {
        Vector2 _point = ((Node2D)(GetParent())).GlobalPosition;

        _line.AddPoint(_point);
        while (_line.GetPointCount() > _length)
        {
            _line.RemovePoint(0);
        }
    }
示例#13
0
    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);
        }
    }
 private void DrawGraph(Godot.Collections.Array dataArray, Line2D line, int speciesCreationTime)
 {
     if (line.Visible)
     {
         line.ClearPoints();
         for (int i = 0; i < dataArray.Count; i++)
         {
             Vector2 NewPoint;
             if (i == speciesCreationTime + 1)
             {
                 Vector2 creationPoint = (Vector2) new Vector2((i + 1) * 1350 / dataArray.Count, 520);
                 line.AddPoint(creationPoint);
             }
             if (i == 0)
             {
                 if (MaxYvalue != 0)
                 {
                     NewPoint = (Vector2) new Vector2(10, 520 - (float)dataArray[i] * 520f / MaxYvalue);
                 }
                 else
                 {
                     NewPoint = (Vector2) new Vector2(10, 520);
                 }
             }
             else
             {
                 if (MaxYvalue != 0)
                 {
                     NewPoint = (Vector2) new Vector2((i + 1) * 1350 / dataArray.Count, 520 - (float)dataArray[i] * 520f / MaxYvalue);
                 }
                 else
                 {
                     NewPoint = (Vector2) new Vector2((i + 1) * 1350 / dataArray.Count, 520);
                 }
             }
             line.AddPoint(NewPoint);
         }
     }
 }
示例#15
0
    public override void _PhysicsProcess(float delta)
    {
        if (_trail.Points.Length > _trailLenght)
        {
            _trail.RemovePoint(0);
        }
        _trail.AddPoint(Position);

        if (_target != null)
        {
            Transform = _target.OrbitPosition.GlobalTransform;
        }
        else
        {
            Position += velocity * delta;
        }
    }
示例#16
0
 public override void _Ready()
 {
     surface_1 = GetNode <Line2D>("Water_Surface_1");
     surface_2 = GetNode <Line2D>("Water_Surface_2");
     collider  = (ConvexPolygonShape2D)GetNode <CollisionShape2D>("Collider/CollisionShape2D").Shape;
     Vector2[] polygon_body = new Vector2[length + 2];
     segment_spread = Math.Abs(bounds[1].x - bounds[0].x) / (length - 1);
     for (int i = 0; i < length; i++)
     {
         water_surface[i] = new Water_Segment_Poly(new Vector2((i * segment_spread) + bounds[0].x, bounds[0].y));
         polygon_body[i]  = water_surface[i].position;
         surface_1.AddPoint(water_surface[i].position);
         surface_2.AddPoint(new Vector2(water_surface[i].position.x, water_surface[i].position.y + 1));
         left_deltas[i]  = 0;
         right_deltas[i] = 0;
     }
     polygon_body[length]     = bounds[1];
     polygon_body[length + 1] = new Vector2(bounds[0].x, bounds[1].y);
     Polygon         = polygon_body;
     collider.Points = polygon_body;
 }
示例#17
0
 public override void Add(Vector2 point)
 {
     line.AddPoint(point);
     _normalizedPoints.Add(Painter.Normalize(point));
 }
示例#18
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);
        }
    }
示例#19
0
    public void FollowEdgeNewBorder(Vector2 from, Vector2 to)
    {
        //Dobbeltsjekk:
        //FIXME

        //Først lag en strek som følger x aksen og så en som følger y aksen.
        Line2D line  = new Line2D();
        float  thing = r.Next(100) / 100f;

        GD.Print("Color: " + thing);
        // line.SetDefaultColor(new Color(thing, thing, thing, 1));
        line.SetWidth(1);
        line.SetName("Border" + borders.Count);
        borders.Add(line);

        /*
         * Hvis genericPointer er (0,0) så har du alt av banen!!! Du har vunnet!
         */

        // kjør igjennom en kø med punkter. Finn nærmeste hjørnet og så legg til neste nærmeste hjørnet og så 'to'
        Queue <Vector2> dest = new Queue <Vector2>();

        dest.Enqueue(from);

        //Opposite point of map
        if ((from.y == BorderHandler.size && to.y == -BorderHandler.size) || (from.y == -BorderHandler.size && to.y == BorderHandler.size) ||
            (from.x == BorderHandler.size && to.x == -BorderHandler.size) || (from.x == -BorderHandler.size && to.x == BorderHandler.size))
        {
            dest.Enqueue(NearestCorner(from));
            dest.Enqueue(NearestCorner(to));
            dest.Enqueue(to);
        }
        else
        {
            //Hva om du har et 'to' point som ikke er opposite - legg til et tredje punkt i mellom som er den neste etter den landet ditt peker i mot. Altså gjør det som står under etter at du finner ut av hvordan man kan få landet til å peke.
            //hvis genericPointer peker mot from og to så kan du ta nærmeste vei mot de ellers ta lengste vei.


            if (from.y == -BorderHandler.size)
            {
                //X first (Står helt oppe)
                if (to.x > from.x)
                {
                    //Til høyre
                    if (genericPointer.x >= from.x && genericPointer.y <= to.y)
                    {
                        ShortRoadFirstX(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstX(from, to, dest);
                    }
                }
                else
                {
                    //Til venstre
                    if (genericPointer.x <= from.x && genericPointer.y <= to.y)
                    {
                        ShortRoadFirstX(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstX(from, to, dest);
                    }
                }
            }
            else if (from.y == BorderHandler.size)
            {
                //X first (Står helt nede)
                if (to.x > from.x)
                {
                    //Til høyre
                    if (genericPointer.x >= from.x && genericPointer.y >= to.y)
                    {
                        ShortRoadFirstX(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstX(from, to, dest);
                    }
                }
                else
                {
                    //Til venstre
                    if (genericPointer.x <= from.x && genericPointer.y >= to.y)
                    {
                        ShortRoadFirstX(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstX(from, to, dest);
                    }
                }
            }
            else if (from.x == BorderHandler.size)
            {
                //Y first (Står helt til høyre)

                if (to.y > from.y)
                {
                    //Ned
                    Vector2 g = genericPointer;
                    if (genericPointer.y >= from.y && genericPointer.x >= to.x)
                    {
                        ShortRoadFirstY(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstY(from, to, dest);
                    }
                }
                else
                {
                    //Opp
                    if (genericPointer.y <= from.y && genericPointer.x >= to.x)
                    {
                        ShortRoadFirstY(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstY(from, to, dest);
                    }
                }
            }
            else
            {
                //Y first (Står helt til venstre)
                if (to.y > from.y)
                {
                    //Ned
                    if (genericPointer.y >= from.y && genericPointer.x <= to.x)
                    {
                        ShortRoadFirstY(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstY(from, to, dest);
                    }
                }
                else
                {
                    //Opp
                    if (genericPointer.y <= from.y && genericPointer.x <= to.x)
                    {
                        ShortRoadFirstY(from, to, dest);
                    }
                    else
                    {
                        //Lang vei
                        LongRoadFirstY(from, to, dest);
                    }
                }
            }
        }

        while (dest.Count != 0)
        {
            Vector2 point = dest.Dequeue();
            line.AddPoint(point);
            if (!points.Contains(point))
            {
                points.Add(point);
            }
        }
    }