Advertisement
Guest User

gd script lines thing

a guest
Nov 2nd, 2021
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node2D
  2. var rng = RandomNumberGenerator.new()
  3. export (int) var line_amount
  4. var window_width = ProjectSettings.get("display/window/size/width")
  5. var window_height = ProjectSettings.get("display/window/size/height")
  6.  
  7. func get_intersections(line1,line2):
  8.    
  9.     return Geometry.line_intersects_line_2d(line1.get_points()[0],line1.get_points()[1],line2.get_points()[0],line2.get_points()[1])
  10.  
  11. func _ready():
  12.     var intersections = 1
  13.     var points = []
  14.     var nodes = []
  15.     for line in line_amount:
  16.         var line2d = Line2D.new()
  17.         nodes.append(line2d)
  18.     for node in nodes:
  19.         rng.randomize()
  20.         var rng_x = Vector2(rng.randf_range(0,window_width),rng.randf_range(0,window_height))
  21.         var rng_y = Vector2(rng.randf_range(0,window_width),rng.randf_range(0,window_height))
  22.         node.width = 5
  23.         add_child(node)
  24.         node.add_point(rng_x)
  25.         node.add_point(rng_y)
  26.     for line in nodes:
  27.         if intersections >= nodes.size()-1:
  28.             break
  29.         if get_intersections(line,nodes[intersections]):
  30.             intersections += 1
  31.             var int_sprite = Sprite.new()
  32.        
  33.             int_sprite.texture = load("res://icon.png")
  34.             int_sprite.position.x = get_intersections(line,nodes[intersections]).x
  35.        
  36.             int_sprite.position.y = get_intersections(line,nodes[intersections]).y
  37.             int_sprite.scale.x = .350
  38.             int_sprite.scale.y = .350
  39.             add_child(int_sprite)
  40.         print(get_intersections(line,nodes[intersections]))
  41.     pass
  42. #func _process(delta):
  43.    
  44.  
Advertisement
RAW Paste Data Copied
Advertisement