-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidewalk.gd
60 lines (40 loc) · 1.34 KB
/
sidewalk.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
extends Node2D
var people = [
load("res://man.tscn"),
load("res://woman.tscn")
]
var vehicles = [
load("res://CarsScenes/cycle_low.tscn"),
load("res://CarsScenes/scooter.tscn")
]
var wait: bool = false
@export var density = 5
# Called when the node enters the scene tree for the first time.
func _ready():
# new_vehicle()
new_person()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func new_vehicle():
var vehicle = vehicles.pick_random().instantiate()
$Temp/Path2D/PathFollow2D.progress_ratio = randf()
vehicle.position = $Temp/Path2D/PathFollow2D.position
vehicle.z_index = $Temp/Path2D/PathFollow2D.progress_ratio * 1000
vehicle.speed = randfn(1, 0.6)
$Temp.add_child(vehicle)
wait = true
$Temp/DelayTimerVehicle.wait_time = (1 + (11 - density) * 0.5 + randf()) * 5
$Temp/DelayTimerVehicle.start()
func new_person():
var person = people.pick_random().instantiate()
$Temp/Path2D/PathFollow2D.progress_ratio = randf()
person.position = $Temp/Path2D/PathFollow2D.position
person.z_index = $Temp/Path2D/PathFollow2D.progress_ratio * 1000
$Temp.add_child(person)
$Temp/DelayTimerPerson.wait_time = 0.5 + (11 - density) * 0.5 + randf()
$Temp/DelayTimerPerson.start()
func _on_delay_timer_person_timeout():
new_person()
func _on_delay_timer_vehicle_timeout():
new_vehicle()