From 749d2a8d5d61e4939b8040ba3174da62d7cfaeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20G=C3=A1lffy?= Date: Mon, 13 Nov 2023 23:28:31 +0100 Subject: [PATCH] feat(game): Scrolling clouds in the background --- examples/forest-brawl/maps/three-peaks.tscn | 26 ++++++- .../forest-brawl/models/forest-blocks.meshlib | Bin 259846 -> 259847 bytes examples/forest-brawl/scripts/cloud-area3d.gd | 65 ++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 examples/forest-brawl/scripts/cloud-area3d.gd diff --git a/examples/forest-brawl/maps/three-peaks.tscn b/examples/forest-brawl/maps/three-peaks.tscn index 1211ef2..15a1a8a 100644 --- a/examples/forest-brawl/maps/three-peaks.tscn +++ b/examples/forest-brawl/maps/three-peaks.tscn @@ -1,12 +1,15 @@ -[gd_scene load_steps=9 format=3 uid="uid://d1544gxqaoptc"] +[gd_scene load_steps=11 format=3 uid="uid://d1544gxqaoptc"] [ext_resource type="MeshLibrary" uid="uid://do0y7f0sy12jg" path="res://examples/forest-brawl/models/forest-blocks.meshlib" id="1_124j6"] [ext_resource type="PackedScene" uid="uid://ijqx6kjl3qf4" path="res://examples/forest-brawl/scenes/powerup.tscn" id="2_4e2nk"] [ext_resource type="PackedScene" uid="uid://c12hb5btenkcy" path="res://examples/forest-brawl/scenes/doodads/clouds-1.tscn" id="3_ucvrj"] [ext_resource type="PackedScene" uid="uid://c5l8x303sjqhs" path="res://examples/forest-brawl/scenes/doodads/clouds-2.tscn" id="4_dfl7h"] [ext_resource type="PackedScene" uid="uid://dq14vitb32x5p" path="res://examples/forest-brawl/scenes/doodads/clouds-3.tscn" id="5_doyli"] +[ext_resource type="Script" path="res://examples/forest-brawl/scripts/cloud-area3d.gd" id="6_ymimw"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_xjsj7"] +sky_top_color = Color(0.384314, 0.454902, 0.54902, 1) +ground_bottom_color = Color(0.3136, 0.420373, 0.56, 1) [sub_resource type="Sky" id="Sky_g0uhm"] sky_material = SubResource("ProceduralSkyMaterial_xjsj7") @@ -16,6 +19,9 @@ background_mode = 2 sky = SubResource("Sky_g0uhm") tonemap_mode = 2 +[sub_resource type="BoxShape3D" id="BoxShape3D_4u8tk"] +size = Vector3(240, 48, 120) + [node name="Three Peaks Map" type="Node3D"] [node name="GridMap" type="GridMap" parent="."] @@ -28,6 +34,9 @@ data = { } metadata/_editor_floor_ = Vector3(0, 0, 0) +[node name="Mountain Clouds" parent="." instance=ExtResource("3_ucvrj")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 17.8236, -4.03231, 11.082) + [node name="Powerups" type="Node" parent="."] [node name="Powerup" parent="Powerups" instance=ExtResource("2_4e2nk")] @@ -73,6 +82,7 @@ environment = SubResource("Environment_c7ydc") [node name="Clouds" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -20, 0) +visible = false [node name="Clouds 1" parent="Clouds" instance=ExtResource("3_ucvrj")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -20.6817, 0, -3.66238) @@ -122,5 +132,15 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 79.7221, 0, 4.68955) [node name="Clouds 16" parent="Clouds" instance=ExtResource("5_doyli")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -71.8085, 0, 21.5426) -[node name="Clouds 17" parent="Clouds" instance=ExtResource("3_ucvrj")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 17.8236, 15.8221, 11.082) +[node name="Area3D" type="Area3D" parent="."] +monitoring = false +monitorable = false +script = ExtResource("6_ymimw") +clouds = Array[PackedScene]([ExtResource("3_ucvrj"), ExtResource("4_dfl7h"), ExtResource("5_doyli")]) +count = 24 +float_speed_min = 0.25 +float_speed_max = 2.0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -34, 0) +shape = SubResource("BoxShape3D_4u8tk") diff --git a/examples/forest-brawl/models/forest-blocks.meshlib b/examples/forest-brawl/models/forest-blocks.meshlib index 3b17de2c78a76cfe43b48db4c33881d4b0e661ea..f132912fea96f153117f2781a75ce151a6081f2e 100644 GIT binary patch delta 2137 zcmV-f2&VUj?hl9V50DfAbg>oX2nAIW02bSm{|Fg>ylid6{+pTI=r393m}_#GN|Nrb z?cQ9#M+2!0c7&cq{G`cW22TJw08;?(J@*74SO9Tvg2KIrdyiUct+iH4DMeq`veCuR z00#PEOEDBcXIHx1Y)$l)?`Ee1jdS%}l+BnET^Bo4C1DnlE|y{@gD)m^cST3n#R32S z|NsA!mkBk05vJI=ki`-R^p&A2nw6Pj0V7leZBs?zUhIUbATWrap)D1P7F9jHCtDYr z&G`YOO7tVqh|vv=VU$6R1)QvuFJ>Qxd5kk zGLd!THv3o7=8??&dv0LzY z04dVn^TSx`J9SXYndVP~2ogAlJAeOw(*p>16CHVeequ)C;WY??n8?AOX%11F6pJTO znFeh-0QpJ{w<{y_TZQ!~<+bqAZvV@s_p*Ud`U=f^w0V%_cP_=x3(#v;Oay5-| zi0{TipD#<~bo6{U;wvlpw%hH_$=K~8Gql)>y|i2(maULZG|&bWw zyD1^$&GeGv&Ckwr6twsakM?M}tyU5CyD4J*M$e;ATc-d2FWDgQ9e>I!v!NibvU!t3 zCO%Zx7MDVFd6rZ!u@uDPRnx3aB?jrIU8Tbkf(GBab@L>zStv36@E6FYW$6HfN4bY_ zS6;l;TAM~nQspzJjV+0#@@U3BkaPq5Mz6ekyjqRm3FyzSgBOY0d27|9MM^N@$828d zm>)l?8>{IIsrag8EiYAvMCvWf%VE)9@`O1V&z_j6>Wl~T+b#`56C(NrW z+O15S{Kjov3zM7<@PGgRYyXE}z{pr?!c~S-Q)Kb{92gJ?c|ubjYa`gxL`jlpQ~Ln) z0OSB=PS~PoHmg6_uZ7|d@?V#_Dq$ETe+Z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<)Y($Y ze{AW0dhxR!@SqfFZL99&;ibro!O9ouY7M#EQnYx{=HlkD#bcM3!zLFmCnta1TAaLf zYu7}Jx5SBdndqU1PA_<6Wd#c*I0(T&2mXQCXR+r63yH5Rw1R^cT3qO$6AX0F;z0wA z;GcmO2m0p&`~0)`&ptl;+%wEBr^Q_!NqJ^r*}$v4Y=XPpV0v(Do>=RDxmIgjVOTD=-)nFV}PW3vjtDVkBIXC6nzEFgnV6NgU| O0f$c$0=G{S1GwYyzAcLY diff --git a/examples/forest-brawl/scripts/cloud-area3d.gd b/examples/forest-brawl/scripts/cloud-area3d.gd new file mode 100644 index 0000000..f4501bc --- /dev/null +++ b/examples/forest-brawl/scripts/cloud-area3d.gd @@ -0,0 +1,65 @@ +extends Area3D + +@export var clouds: Array[PackedScene] = [] +@export var count: int = 16 + +@export var float_direction: Vector3 = Vector3.RIGHT +@export var float_speed_min: float = 4.0 +@export var float_speed_max: float = 8.0 + +var _clouds: Array[Node3D] = [] +var _speeds: Array[float] = [] +var _aabb: AABB + +func _ready(): + _aabb = _find_aabb() + if not _aabb.has_volume(): + push_error("CloudArea required a box shape!") + queue_free() + return + + for i in range(count): + var cloud = _spawn_cloud() + cloud.position = _aabb.position + _aabb.size * Vector3(randf(), randf(), randf()) + + _clouds.push_back(cloud) + _speeds.push_back(randf_range(float_speed_min, float_speed_max)) + +func _process(delta): + for i in range(count): + var cloud = _clouds[i] + var speed = _speeds[i] + + cloud.position += float_direction * speed * delta + + if not _aabb.has_point(cloud.position): + cloud.queue_free() + + cloud = _spawn_cloud() + cloud.position = _aabb.position + _aabb.size * \ + Vector3(randf(), randf(), randf()) * \ + (Vector3.ONE * 0.5 - float_direction * 0.5) + + _clouds[i] = cloud + _speeds[i] = randf_range(float_speed_min, float_speed_max) + +func _spawn_cloud() -> Node3D: + var cloud_template = clouds.pick_random() as PackedScene + var cloud = cloud_template.instantiate() as Node3D + add_child(cloud) + cloud.owner = self + + return cloud + +func _find_aabb() -> AABB: + var shape_owners = get_shape_owners() + for shape_owner in shape_owners: + for i in range(shape_owner_get_shape_count(shape_owner)): + var shape = shape_owner_get_shape(shape_owner, i) + + if shape is BoxShape3D: + var pos = shape_owner_get_transform(shape_owner).origin + var size = shape.size + return AABB(pos - size / 2, size) + + return AABB(Vector3.ZERO, Vector3.ZERO)