Skip to content

Commit 0bac4dc

Browse files
committed
Add moods (times of day) to Truck Town demo
Four moods are available: sunrise, day, sunset, night. Sunset and night also feature artificial point lights placed in the town scene. The mood can be set on the main menu before playing. It can also be cycled during gameplay by pressing M or D-Pad Down.
1 parent 0fb1b4e commit 0bac4dc

15 files changed

+289
-9
lines changed

3d/truck_town/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Controls:
1111
- <kbd>Right Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>, <kbd>Gamepad D-Pad Right</kbd>: Steer right
1212
- <kbd>U</kbd>, <kbd>Gamepad Select</kbd>, left-click speedometer: Change speedometer unit (m/s, km/h, mph)
1313
- <kbd>C</kbd>, <kbd>Gamepad Y/Triangle</kbd>: Change camera (exterior, interior, top-down)
14+
- <kbd>M</kbd>, <kbd>Gamepad D-Pad Down</kbd>: Change mood (sunrise, day, sunset, night)
1415
- <kbd>Escape</kbd>, <kbd>Gamepad D-Pad Up</kbd>: Go back to menu (press again to exit)
1516

1617
On mobile platforms, the vehicle automatically accelerates. Touch the left and

3d/truck_town/car_select/car_select.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ func _load_scene(car_scene: PackedScene) -> void:
1616
var car: Node3D = car_scene.instantiate()
1717
car.name = "car"
1818
town = preload("res://town/town_scene.tscn").instantiate()
19+
if $PanelContainer/MarginContainer/HBoxContainer/Sunrise.button_pressed:
20+
town.mood = town.Mood.SUNRISE
21+
elif $PanelContainer/MarginContainer/HBoxContainer/Day.button_pressed:
22+
town.mood = town.Mood.DAY
23+
elif $PanelContainer/MarginContainer/HBoxContainer/Sunset.button_pressed:
24+
town.mood = town.Mood.SUNSET
25+
elif $PanelContainer/MarginContainer/HBoxContainer/Night.button_pressed:
26+
town.mood = town.Mood.NIGHT
1927
town.get_node(^"InstancePos").add_child(car)
2028
town.get_node(^"Spedometer").car_body = car.get_child(0)
2129
town.get_node(^"Back").pressed.connect(_on_back_pressed)

3d/truck_town/car_select/car_select.tscn

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=6 format=3 uid="uid://ckvqraq6j1okh"]
1+
[gd_scene load_steps=7 format=3 uid="uid://ckvqraq6j1okh"]
22

33
[ext_resource type="Script" path="res://car_select/car_select.gd" id="1"]
44
[ext_resource type="Texture2D" uid="uid://bh7b4n4lg1uqt" path="res://car_select/choose_van.png" id="2"]
@@ -11,6 +11,8 @@ variation_transform = Transform2D(1, 0.2, 0, 1, 0, 0)
1111
spacing_glyph = -1
1212
spacing_space = 4
1313

14+
[sub_resource type="ButtonGroup" id="ButtonGroup_lcrm3"]
15+
1416
[node name="CarSelect" type="Control"]
1517
layout_mode = 3
1618
anchors_preset = 8
@@ -75,6 +77,60 @@ theme_override_fonts/font = SubResource("FontVariation_hqcvw")
7577
theme_override_font_sizes/font_size = 64
7678
text = "Truck Town"
7779

80+
[node name="PanelContainer" type="PanelContainer" parent="."]
81+
layout_mode = 1
82+
anchors_preset = 8
83+
anchor_left = 0.5
84+
anchor_top = 0.5
85+
anchor_right = 0.5
86+
anchor_bottom = 0.5
87+
offset_left = -325.0
88+
offset_top = 164.0
89+
offset_right = 325.0
90+
offset_bottom = 205.0
91+
grow_horizontal = 2
92+
grow_vertical = 2
93+
94+
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
95+
layout_mode = 2
96+
theme_override_constants/margin_left = 20
97+
theme_override_constants/margin_top = 5
98+
theme_override_constants/margin_right = 20
99+
theme_override_constants/margin_bottom = 5
100+
101+
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"]
102+
layout_mode = 2
103+
104+
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
105+
custom_minimum_size = Vector2(70, 0)
106+
layout_mode = 2
107+
text = "Mood"
108+
109+
[node name="Sunrise" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
110+
layout_mode = 2
111+
size_flags_horizontal = 3
112+
button_group = SubResource("ButtonGroup_lcrm3")
113+
text = "Sunrise"
114+
115+
[node name="Day" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
116+
layout_mode = 2
117+
size_flags_horizontal = 3
118+
button_pressed = true
119+
button_group = SubResource("ButtonGroup_lcrm3")
120+
text = "Day"
121+
122+
[node name="Sunset" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
123+
layout_mode = 2
124+
size_flags_horizontal = 3
125+
button_group = SubResource("ButtonGroup_lcrm3")
126+
text = "Sunset"
127+
128+
[node name="Night" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
129+
layout_mode = 2
130+
size_flags_horizontal = 3
131+
button_group = SubResource("ButtonGroup_lcrm3")
132+
text = "Night"
133+
78134
[connection signal="pressed" from="HBoxContainer/MiniVan" to="." method="_on_mini_van_pressed"]
79135
[connection signal="pressed" from="HBoxContainer/TrailerTruck" to="." method="_on_trailer_truck_pressed"]
80136
[connection signal="pressed" from="HBoxContainer/TowTruck" to="." method="_on_tow_truck_pressed"]

3d/truck_town/project.godot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ cycle_camera={
148148
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
149149
]
150150
}
151+
cycle_mood={
152+
"deadzone": 0.5,
153+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":77,"physical_keycode":0,"key_label":0,"unicode":109,"location":0,"echo":false,"script":null)
154+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
155+
]
156+
}
151157

152158
[physics]
153159

@@ -159,11 +165,15 @@ textures/vram_compression/import_etc2_astc=true
159165
lights_and_shadows/directional_shadow/size=8192
160166
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=3
161167
lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile=1
168+
lights_and_shadows/positional_shadow/soft_shadow_filter_quality=3
169+
lights_and_shadows/positional_shadow/soft_shadow_filter_quality.mobile=1
162170
textures/default_filters/anisotropic_filtering_level=4
163171
textures/default_filters/texture_mipmap_bias=-0.5
164172
textures/decals/filter=1
165173
environment/defaults/default_clear_color=Color(0.133333, 0.133333, 0.133333, 1)
166174
anti_aliasing/quality/msaa_3d=2
167175
anti_aliasing/quality/use_debanding=true
176+
lights_and_shadows/positional_shadow/atlas_size=2048
177+
lights_and_shadows/positional_shadow/atlas_size.mobile=1024
168178
anti_aliasing/quality/msaa_3d.mobile=0
169179
scaling_3d/scale.mobile=0.67

3d/truck_town/town/sky_day.tres

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://bpms6jemjgt36"]
2+
3+
[resource]
4+
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
5+
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)

3d/truck_town/town/sky_morning.tres

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://drtvj2ilm4c7h"]
2+
3+
[resource]
4+
sky_top_color = Color(0.164732, 0.303048, 0.411552, 1)
5+
sky_horizon_color = Color(0.686775, 0.600323, 0.467043, 1)
6+
ground_horizon_color = Color(0.686275, 0.6, 0.466667, 1)

3d/truck_town/town/sky_night.tres

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://c2w5t0j2rkiuu"]
2+
3+
[resource]
4+
sky_top_color = Color(0.0964875, 0.114707, 0.155705, 1)
5+
sky_horizon_color = Color(0.201247, 0.148966, 0.125881, 1)
6+
ground_horizon_color = Color(0.2, 0.14902, 0.12549, 1)

3d/truck_town/town/sky_sunset.tres

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://dbs05x6h8miq2"]
2+
3+
[resource]
4+
sky_top_color = Color(0.252654, 0.288234, 0.368141, 1)
5+
sky_horizon_color = Color(0.77459, 0.550361, 0.50128, 1)
6+
ground_horizon_color = Color(0.776471, 0.54902, 0.501961, 1)

3d/truck_town/town/town_scene.gd

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
extends Node3D
2+
3+
enum Mood {
4+
SUNRISE,
5+
DAY,
6+
SUNSET,
7+
NIGHT,
8+
MAX,
9+
}
10+
11+
var mood := Mood.DAY: set = set_mood
12+
13+
14+
func _input(event: InputEvent) -> void:
15+
if event.is_action_pressed(&"cycle_mood"):
16+
mood = wrapi(mood + 1, 0, Mood.MAX) as Mood
17+
18+
19+
func set_mood(p_mood: Mood) -> void:
20+
mood = p_mood
21+
22+
match p_mood:
23+
Mood.SUNRISE:
24+
$DirectionalLight3D.rotation_degrees = Vector3(-20, -150, -137)
25+
$DirectionalLight3D.light_color = Color(0.414, 0.377, 0.25)
26+
$DirectionalLight3D.light_energy = 4.0
27+
$WorldEnvironment.environment.fog_light_color = Color(0.686, 0.6, 0.467)
28+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_morning.tres")
29+
$ArtificialLights.visible = false
30+
Mood.DAY:
31+
$DirectionalLight3D.rotation_degrees = Vector3(-55, -120, -31)
32+
$DirectionalLight3D.light_color = Color.WHITE
33+
$DirectionalLight3D.light_energy = 1.45
34+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_day.tres")
35+
$WorldEnvironment.environment.fog_light_color = Color(0.62, 0.601, 0.601)
36+
$ArtificialLights.visible = false
37+
Mood.SUNSET:
38+
$DirectionalLight3D.rotation_degrees = Vector3(-19, -31, 62)
39+
$DirectionalLight3D.light_color = Color(0.488, 0.3, 0.1)
40+
$DirectionalLight3D.light_energy = 4.0
41+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_sunset.tres")
42+
$WorldEnvironment.environment.fog_light_color = Color(0.776, 0.549, 0.502)
43+
$ArtificialLights.visible = true
44+
Mood.NIGHT:
45+
$DirectionalLight3D.rotation_degrees = Vector3(-49, 116, -46)
46+
$DirectionalLight3D.light_color = Color(0.232, 0.415, 0.413)
47+
$DirectionalLight3D.light_energy = 0.7
48+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_night.tres")
49+
$WorldEnvironment.environment.fog_light_color = Color(0.2, 0.149, 0.125)
50+
$ArtificialLights.visible = true

3d/truck_town/town/town_scene.tscn

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
[gd_scene load_steps=38 format=3 uid="uid://d0ygmqpylq0wy"]
1+
[gd_scene load_steps=39 format=3 uid="uid://d0ygmqpylq0wy"]
22

3+
[ext_resource type="Script" path="res://town/town_scene.gd" id="1_lr47o"]
34
[ext_resource type="PackedScene" uid="uid://dfdgytsvtqxwv" path="res://town/truck_town.glb" id="1_x0dmm"]
4-
[ext_resource type="Script" path="res://spedometer.gd" id="2"]
5+
[ext_resource type="Script" uid="uid://ikqivupl66lr" path="res://spedometer.gd" id="2"]
6+
[ext_resource type="Material" uid="uid://bpms6jemjgt36" path="res://town/sky_day.tres" id="2_1df3w"]
57
[ext_resource type="Texture2D" uid="uid://b2g4dq0w72e68" path="res://town/materials/grass.webp" id="4_cymw0"]
68
[ext_resource type="Material" uid="uid://bdjiubscxkdn6" path="res://town/materials/cement.tres" id="5_83ty7"]
79

8-
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_2k12y"]
9-
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
10-
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
11-
1210
[sub_resource type="Sky" id="Sky_1gf0c"]
13-
sky_material = SubResource("ProceduralSkyMaterial_2k12y")
11+
sky_material = ExtResource("2_1df3w")
1412

1513
[sub_resource type="Environment" id="Environment_dauhq"]
1614
background_mode = 2
@@ -134,12 +132,13 @@ data = PackedVector3Array(-2, 0.5, 2, 2, -0.5, 2, -2, -0.5, 2, -2, 0.5, -2, -2,
134132
data = PackedVector3Array(-2, 1, 2, 2, -1, 2, -2, -1, 2, -2, 1, -2, -2, -1, -2, 2, -1, -2, -2, 1, 2, -2, 1, -2, 2, -1, 2, -2, 1, -2, 2, -1, -2, 2, -1, 2, -2, 1, -2, -2, 1, 2, -2, -1, -2, -2, 1, 2, -2, -1, 2, -2, -1, -2, -2, -1, 2, 2, -1, 2, -2, -1, -2, 2, -1, 2, 2, -1, -2, -2, -1, -2)
135133

136134
[node name="TownScene" type="Node3D"]
135+
script = ExtResource("1_lr47o")
137136

138137
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
139138
environment = SubResource("Environment_dauhq")
140139

141140
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
142-
transform = Transform3D(0.506501, -0.706305, -0.494561, -4.63342e-08, -0.573577, 0.819152, -0.862239, -0.414901, -0.290517, 11.0084, 12.3453, -31.3148)
141+
transform = Transform3D(-0.793955, 0.350561, -0.496732, -0.295414, 0.491651, 0.819152, 0.531381, 0.797111, -0.286788, 11.0084, 12.3453, -31.3148)
143142
light_energy = 1.45
144143
shadow_enabled = true
145144
shadow_bias = 0.015
@@ -149,6 +148,139 @@ directional_shadow_max_distance = 80.0
149148

150149
[node name="TruckTown" parent="." instance=ExtResource("1_x0dmm")]
151150

151+
[node name="ArtificialLights" type="Node3D" parent="."]
152+
visible = false
153+
154+
[node name="OmniLight3D" type="OmniLight3D" parent="ArtificialLights"]
155+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 11.1028, 5.58679, -15.1748)
156+
light_color = Color(1, 0.941176, 0.705882, 1)
157+
light_energy = 2.0
158+
shadow_enabled = true
159+
shadow_bias = 0.06
160+
shadow_blur = 2.0
161+
distance_fade_enabled = true
162+
distance_fade_begin = 100.0
163+
distance_fade_shadow = 35.0
164+
distance_fade_length = 15.0
165+
omni_range = 15.0
166+
167+
[node name="OmniLight3D2" type="OmniLight3D" parent="ArtificialLights"]
168+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -13.8972, 6.58679, -9.17481)
169+
light_color = Color(1, 0.941176, 0.705882, 1)
170+
light_energy = 2.0
171+
shadow_enabled = true
172+
shadow_bias = 0.06
173+
shadow_blur = 2.0
174+
distance_fade_enabled = true
175+
distance_fade_begin = 100.0
176+
distance_fade_shadow = 35.0
177+
distance_fade_length = 15.0
178+
omni_range = 15.0
179+
180+
[node name="OmniLight3D3" type="OmniLight3D" parent="ArtificialLights"]
181+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -12.8972, 6.58679, -36.1748)
182+
light_color = Color(1, 0.941176, 0.705882, 1)
183+
light_energy = 2.0
184+
shadow_enabled = true
185+
shadow_bias = 0.06
186+
shadow_blur = 2.0
187+
distance_fade_enabled = true
188+
distance_fade_begin = 100.0
189+
distance_fade_shadow = 35.0
190+
distance_fade_length = 15.0
191+
omni_range = 15.0
192+
193+
[node name="OmniLight3D4" type="OmniLight3D" parent="ArtificialLights"]
194+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 9.10282, 8.58679, -37.1748)
195+
light_color = Color(1, 0.941176, 0.705882, 1)
196+
light_energy = 2.0
197+
shadow_enabled = true
198+
shadow_bias = 0.06
199+
shadow_blur = 2.0
200+
distance_fade_enabled = true
201+
distance_fade_begin = 100.0
202+
distance_fade_shadow = 35.0
203+
distance_fade_length = 15.0
204+
omni_range = 15.0
205+
206+
[node name="OmniLight3D5" type="OmniLight3D" parent="ArtificialLights"]
207+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 18.1028, 8.58679, -47.1748)
208+
light_color = Color(1, 0.941176, 0.705882, 1)
209+
light_energy = 2.0
210+
shadow_enabled = true
211+
shadow_bias = 0.06
212+
shadow_blur = 2.0
213+
distance_fade_enabled = true
214+
distance_fade_begin = 100.0
215+
distance_fade_shadow = 35.0
216+
distance_fade_length = 15.0
217+
omni_range = 15.0
218+
219+
[node name="OmniLight3D6" type="OmniLight3D" parent="ArtificialLights"]
220+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -47.8972, 2.58679, -25.1748)
221+
light_color = Color(1, 0.941176, 0.705882, 1)
222+
light_energy = 2.0
223+
shadow_enabled = true
224+
shadow_bias = 0.06
225+
shadow_blur = 2.0
226+
distance_fade_enabled = true
227+
distance_fade_begin = 100.0
228+
distance_fade_shadow = 35.0
229+
distance_fade_length = 15.0
230+
omni_range = 15.0
231+
232+
[node name="OmniLight3D7" type="OmniLight3D" parent="ArtificialLights"]
233+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -42.8972, 2.58679, -9.17481)
234+
light_color = Color(1, 0.941176, 0.705882, 1)
235+
light_energy = 2.0
236+
shadow_enabled = true
237+
shadow_bias = 0.06
238+
shadow_blur = 2.0
239+
distance_fade_enabled = true
240+
distance_fade_begin = 100.0
241+
distance_fade_shadow = 35.0
242+
distance_fade_length = 15.0
243+
omni_range = 15.0
244+
245+
[node name="OmniLight3D8" type="OmniLight3D" parent="ArtificialLights"]
246+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -71.8972, 5.58679, -25.1748)
247+
light_color = Color(1, 0.941176, 0.705882, 1)
248+
light_energy = 2.0
249+
shadow_enabled = true
250+
shadow_bias = 0.06
251+
shadow_blur = 2.0
252+
distance_fade_enabled = true
253+
distance_fade_begin = 100.0
254+
distance_fade_shadow = 35.0
255+
distance_fade_length = 15.0
256+
omni_range = 15.0
257+
258+
[node name="OmniLight3D9" type="OmniLight3D" parent="ArtificialLights"]
259+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -70.8972, 5.58679, -45.1748)
260+
light_color = Color(1, 0.941176, 0.705882, 1)
261+
light_energy = 2.0
262+
shadow_enabled = true
263+
shadow_bias = 0.06
264+
shadow_blur = 2.0
265+
distance_fade_enabled = true
266+
distance_fade_begin = 100.0
267+
distance_fade_shadow = 35.0
268+
distance_fade_length = 15.0
269+
omni_range = 15.0
270+
271+
[node name="OmniLight3D10" type="OmniLight3D" parent="ArtificialLights"]
272+
transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -42.7972, -1.41321, -101.175)
273+
light_color = Color(1, 0.941176, 0.705882, 1)
274+
light_energy = 2.0
275+
shadow_enabled = true
276+
shadow_bias = 0.06
277+
shadow_blur = 2.0
278+
distance_fade_enabled = true
279+
distance_fade_begin = 100.0
280+
distance_fade_shadow = 35.0
281+
distance_fade_length = 15.0
282+
omni_range = 15.0
283+
152284
[node name="InstancePos" type="Marker3D" parent="."]
153285
transform = Transform3D(1.31134e-07, 0, -1, 0, 1, 0, 1, 0, 1.31134e-07, 8, 3.36405, -16)
154286

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)