Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node
  2.  
  3. onready var planet = preload("res://Planet.tscn")
  4. var planet_sizes = [0.15, 0.25, 0.35]
  5. var created_planets = []
  6. var goodtoadd = true
  7.  
  8. func _ready():
  9.     randomize()
  10.     draw_planets()
  11.  
  12. func draw_planets():
  13.     while created_planets.size() < 3:
  14.         print("looping")
  15.         var planet_coords = Vector2(rand_range(50, 1870), rand_range(50, 1030))
  16.         if not planet_coords in created_planets:   #if there is not already a planet at those coordinates
  17.             print("not in")
  18.             if len(created_planets) == 0:           #if there are no planets
  19.                 goodtoadd = true
  20.             else:
  21.                 for existing in created_planets:                   # if planet is further than 35 pixels from all other planets
  22.                     if planet_coords.distance_to(existing) < 35:
  23.                         goodtoadd = false
  24.                     else:
  25.                         goodtoadd = true
  26.         if goodtoadd:
  27.             var s = planet.instance()
  28.             add_child(s)
  29.             s.position = planet_coords
  30.             var size = planet_sizes[int(rand_range(0, 3))]
  31.             s.set_scale(Vector2(size, size))
  32.             created_planets.append(planet_coords)
  33.             print(created_planets.size())
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement