Beispiel #1
0
 public DrawableNodeConnection(PathfindingNodeConnection conn)
 {
     this.conn = conn;
     this.drawColor = TRANSPARENT;
     /*PathfindingNode closestNode = null;
     if (Util.GetHypoteneuseLength(node1.GetLocation(), new Point(0, 0)) < Util.GetHypoteneuseLength(node2.GetLocation(), new Point(0, 0)))
     {
         closestNode = node1;
     } else closestNode = node2;
     lengthDrawOffset = new Point(closestNode.x + (int)Math.Abs(node1.x - node2.x), closestNode.y + (int)Math.Abs(node1.y - node2.y));*/
 }
Beispiel #2
0
 public DrawableNodeConnection(PathfindingNodeConnection conn, Color c)
 {
     this.conn = conn;
     this.drawColor = c;
 }
Beispiel #3
0
 /// <summary>
 /// Creates the connections between this node and other nodes!
 /// </summary>
 public void CreateConnections()
 {
     PathfindingNodeManager manager = PathfindingNodeManager.GetInstance();
     foreach (PathfindingNode node in manager.nodeList)
     {
         // No connection with itsself
         if (node == this) continue;
         if (PathfindingUtil.GetHypoteneuseLength(node.GetLocation(), this.GetLocation()) > MAX_CONNECT_RANGE) continue;
         if (!collisionMap.IsCollisionBetween(this.GetLocation(), node.GetLocation()))
         {
             // Console.Out.WriteLine("Adding a new connection between " + this + " and " + node);
             PathfindingNodeConnection conn = new PathfindingNodeConnection(this, node);
             this.connections.AddLast(conn);
             if (node.IsConnected(this) == null) node.connections.AddLast(conn);
         }
     }
 }
Beispiel #4
0
 void MouseClickListener.OnMouseRelease(MouseEvent e)
 {
     KeyboardState keyboardState = Keyboard.GetState();
     if (e.button == MouseEvent.MOUSE_BUTTON_1)
     {
         if (CURRENT_PLAYER.selectBox != null)
         {
             Boolean selectedANode = false;
             PathfindingNodeManager manager = PathfindingNodeManager.GetInstance();
             // We need to capture it, because it will be reset after this most probably
             PathfindingNode selectedNode = manager.selectedNode;
             foreach (Node node in manager.nodeList)
             {
                 if (!selectedANode && node.drawRect.Contains(e.location))
                 {
                     // Update connections
                     Boolean controlDown = (keyboardState.IsKeyDown(Keys.RightControl) || keyboardState.IsKeyDown(Keys.LeftControl));
                     if (controlDown && selectedNode != null && selectedNode != node)
                     {
                         if (selectedNode.IsConnected(node) != null)
                         {
                             selectedNode.RemoveConnection(node);
                         }
                         else
                         {
                             PathfindingNodeConnection conn = new PathfindingNodeConnection(node, selectedNode);
                             selectedNode.connections.AddLast(conn);
                             node.connections.AddLast(conn);
                         }
                     }
                     //if (!controlDown) {
                     node.selected = true;
                     selectedANode = true;
                     //}
                 }
                 else node.selected = false;
             }
             // Console.Out.WriteLine("Left mouse button clicked!");
             //if (!selectedANode)
             //{
             //    Texture2D nodeTexture = this.Content.Load<Texture2D>("Misc/node");
             //    new Node(e.location.X, e.location.Y);
             //}
         }
     }
 }