Level.gd (1435B)
1 extends Node2D 2 3 export var lvl = 1 4 5 var safe_radius = 40.0 6 7 var public_scn = preload("res://Public.tscn") 8 var evil_scn = preload("res://Evil.tscn") 9 var hidden_scn = preload("res://Hidden.tscn") 10 11 var lampadaire_scn = preload("res://Lampadaire.tscn") 12 13 var poubelle_scn = preload("res://Poubelle.tscn") 14 15 #func _ready(): 16 # $President.position = Vector2(safe_radius, get_viewport_rect().size.y/2) 17 # $Guard.position = Vector2(safe_radius, get_viewport_rect().size.y/2 - safe_radius*2) 18 # $Guard.target = $Guard.position 19 20 func _ready(): 21 $LvlLabel.text = "lvl: " + String(lvl) 22 for _i in range(int(10+lvl*2)): 23 $YSort.add_child(public_scn.instance()) 24 for _i in range(int((lvl-1)*2)): 25 if randi()%2 == 0: 26 $YSort.add_child(evil_scn.instance()) 27 else: 28 $YSort.add_child(hidden_scn.instance()) 29 30 $RoadBG.frame = randi()%3 31 32 for _i in range(randi()%5): 33 var lampadaire = lampadaire_scn.instance() 34 lampadaire.position.x = rand_range(0, get_viewport_rect().size.x) 35 lampadaire.position.y = rand_range(0, get_viewport_rect().size.y) 36 $YSort.add_child(lampadaire) 37 38 for _i in range(randi()%5): 39 var poubelle = poubelle_scn.instance() 40 poubelle.position.x = rand_range(0, get_viewport_rect().size.x) 41 poubelle.position.y = rand_range(0, get_viewport_rect().size.y) 42 $YSort.add_child(poubelle) 43 44 45 46 func _physics_process(_delta): 47 if $YSort/President.position.x + safe_radius > get_viewport_rect().size.x: 48 get_parent().next_lvl()