-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
82 lines (65 loc) · 2.22 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
extends Node
var lane_scene = load("res://lane.tscn")
var sidewalk_scene = load("res://sidewalk.tscn")
var lane_holders
var sidewalk
# Called when the node enters the scene tree for the first time.
func _ready():
lane_holders = [
$ColorRect/LaneHolder3,
$ColorRect/LaneHolder2,
$ColorRect/LaneHolder4,
$ColorRect/LaneHolder1,
$ColorRect/LaneHolder5,
$ColorRect/LaneHolder6
]
new_lane(0)
new_sidewalk(2)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_controls_lane_count_changed():
var index = $ColorRect/Controls.lane_count - 1
if lane_holders[index].lane == null:
new_lane(index)
else:
lane_holders[index + 1].lane.queue_free()
lane_holders[index + 1].lane = null
if $ColorRect/Controls.sidewalk_enable:
if $ColorRect/Controls.lane_count == 1 or $ColorRect/Controls.lane_count == 2:
sidewalk.reparent(lane_holders[2])
sidewalk.position = Vector2.ZERO
elif $ColorRect/Controls.lane_count == 3 or $ColorRect/Controls.lane_count == 4:
sidewalk.reparent(lane_holders[4])
sidewalk.position = Vector2.ZERO
else:
sidewalk.reparent(lane_holders[5])
sidewalk.position = Vector2.ZERO
func new_lane(index):
var lane = lane_scene.instantiate()
lane.density = $ColorRect/Controls.traffic_density
lane_holders[index].add_child(lane)
lane_holders[index].lane = lane
func new_sidewalk(index):
sidewalk = sidewalk_scene.instantiate()
sidewalk.density = $ColorRect/Controls.traffic_density
lane_holders[index].add_child(sidewalk)
func _on_controls_sidewalk_enabled_changed():
if $ColorRect/Controls.sidewalk_enable:
if $ColorRect/Controls.lane_count == 1 or $ColorRect/Controls.lane_count == 2:
new_sidewalk(2)
elif $ColorRect/Controls.lane_count == 3 or $ColorRect/Controls.lane_count == 4:
new_sidewalk(4)
else:
new_sidewalk(5)
else:
sidewalk.queue_free()
sidewalk = null
func _on_controls_traffic_density_changed():
for lane_holder in lane_holders:
if lane_holder.lane != null:
lane_holder.lane.density = $ColorRect/Controls.traffic_density
if sidewalk != null:
sidewalk.density = $ColorRect/Controls.traffic_density
func _on_controls_background_colour_changed():
$ColorRect.color = $ColorRect/Controls.background_color