Advertisement
Guest User

Untitled

a guest
Nov 27th, 2020
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.00 KB | None
  1. extends Node2D
  2.  
  3. onready var W_LIM = int($BackgroundPanel.rect_size.x)
  4. onready var H_LIM = int($BackgroundPanel.rect_size.y)
  5. onready var diagram
  6. onready var points = []
  7.  
  8. func _ready():
  9.     $TestToolNode.connect("map_generation_signal", self, "map_generation")
  10.  
  11.  
  12. func map_generation(points_cardinal, relax_cardinal):
  13.     #DIAGRAM GENERATION
  14.     var generator = Voronoi.new()
  15.     for i in range(points_cardinal):
  16.         point_generation()
  17.     generator.set_points(points)
  18.     generator.set_boundaries(Rect2(Vector2.ZERO, $BackgroundPanel.rect_size))
  19.     generator.relax_points(relax_cardinal)
  20.     diagram = generator.generate_diagram()
  21.     update()
  22.    
  23.     #CALL TO MAP DRAWING
  24.     draw_map()
  25.  
  26.  
  27. func draw_map():
  28.     var background_scene = load("res://Scenes/TestBackgroundPanelScene.tscn")
  29.     background_scene = background_scene.instance()
  30.     background_scene.set_name("background_scene")
  31.     self.add_child(background_scene)
  32.  
  33.  
  34. func point_generation():
  35.     randomize()
  36.     var rand_v = Vector2(randi()%W_LIM, randi()%H_LIM)
  37.     points.append(rand_v)
Advertisement
RAW Paste Data Copied
Advertisement