commit f52b63b753a3d35a98d97e9496794e059777fac5 Author: Jonas Braus Date: Tue Aug 6 04:49:41 2024 +0200 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/Icon.png b/Icon.png new file mode 100644 index 0000000..31d409a Binary files /dev/null and b/Icon.png differ diff --git a/Icon.png.import b/Icon.png.import new file mode 100644 index 0000000..39b8a09 --- /dev/null +++ b/Icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b5oukegnirc4m" +path="res://.godot/imported/Icon.png-33e63688031d53466d4d656c73cf10ca.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Icon.png" +dest_files=["res://.godot/imported/Icon.png-33e63688031d53466d4d656c73cf10ca.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/PlatformData.gd b/PlatformData.gd new file mode 100644 index 0000000..8ed305b --- /dev/null +++ b/PlatformData.gd @@ -0,0 +1,60 @@ +class_name PlatformData + +const vertices = [ + Vector3(-1, 0, -1), + Vector3(1, 0, -1), + Vector3(1, 0.2, -1), + Vector3(-1, 0.2, -1), + Vector3(-1, 0, 1), + Vector3(1, 0, 1), + Vector3(1, 0.2, 1), + Vector3(-1, 0.2, 1) +] + + +const triangles = [ + [3, 7, 2, 6], + [0, 3, 1, 2], + [5, 6, 4, 7], + [1, 5, 0, 4], + [4, 7, 0, 3], + [1, 2, 5, 6] +] + +const normals = [ + Vector3(0, 0, 1), + Vector3(0, -1, 0), + Vector3(0, 1, 0), + Vector3(0, 0, -1), + Vector3(-1, 0, 0), + Vector3(1, 0, 0) +] + +const color = [ + Color(0.8705, 0.7254, 0.5254), + Color(0.9294, 0.3019, 0.4313), + Color(0.8588, 0.4235, 0.8666) +] + +static func defaultMat(): + var tempMaterial = StandardMaterial3D.new() + tempMaterial.roughness = 1 + tempMaterial.specular_mode = BaseMaterial3D.SPECULAR_DISABLED + tempMaterial.metallic = 0 + tempMaterial.metallic_specular = 0 + return tempMaterial + +static func material1(): + var tempMaterial = defaultMat() + tempMaterial.albedo_color = color[0] + return tempMaterial + +static func material2(): + var tempMaterial = defaultMat() + tempMaterial.albedo_color = color[1] + return tempMaterial + +static func material3(): + var tempMaterial = defaultMat() + tempMaterial.albedo_color = color[2] + return tempMaterial diff --git a/Sky.png b/Sky.png new file mode 100644 index 0000000..32e13ce Binary files /dev/null and b/Sky.png differ diff --git a/Sky.png.import b/Sky.png.import new file mode 100644 index 0000000..f75c731 --- /dev/null +++ b/Sky.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bj5w0ki1au4jr" +path.s3tc="res://.godot/imported/Sky.png-8c43aacd3d620d81964b518cb41623f6.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://Sky.png" +dest_files=["res://.godot/imported/Sky.png-8c43aacd3d620d81964b518cb41623f6.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..3fe4f4a --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..e04240c --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://kqmcbc0qwii1" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/platform.gd b/platform.gd new file mode 100644 index 0000000..9236766 --- /dev/null +++ b/platform.gd @@ -0,0 +1,172 @@ +extends MeshInstance3D + +var isActive = false +var inMenu = false + +var randomMaterial : int +var randomAxis : int +var last : Node3D +var vertices : Array +var newVerts : Array +var speed = 2.0 +var score = 1 + +const maxMoveDistance = 3.0 +var velocity : Vector3 +var cam : Camera3D + +var labelScore : Label +var rng = RandomNumberGenerator.new() + +func calculate_randoms(): + randomMaterial = rng.randi_range(0, 2) + randomAxis = rng.randi_range(0, 1) + + if last != null: + while randomMaterial == last.randomMaterial: + randomMaterial = rng.randi_range(0, 2) + while randomAxis == last.randomAxis: + randomAxis = rng.randi_range(0, 1) + if randomAxis == 0: + velocity.z = 0 + velocity.x = speed + else: + velocity.z = speed + velocity.x = 0 + +func rebuild_mesh(vertTemplate): + var tempVertices = [] + + var st = SurfaceTool.new() + st.begin(Mesh.PRIMITIVE_TRIANGLES) + match randomMaterial: + 0: + st.set_material(PlatformData.material1()) + 1: + st.set_material(PlatformData.material2()) + 2: + st.set_material(PlatformData.material3()) + + var index = 0 + for i in range(0, 6): + st.set_uv(Vector2(0, 0)) + st.set_normal(PlatformData.normals[i]) + st.add_vertex(vertTemplate[PlatformData.triangles[i][0]]) + st.set_uv(Vector2(0, 1)) + st.set_normal(PlatformData.normals[i]) + st.add_vertex(vertTemplate[PlatformData.triangles[i][1]]) + st.set_uv(Vector2(1, 1)) + st.set_normal(PlatformData.normals[i]) + st.add_vertex(vertTemplate[PlatformData.triangles[i][2]]) + st.set_uv(Vector2(1, 0)) + st.set_normal(PlatformData.normals[i]) + st.add_vertex(vertTemplate[PlatformData.triangles[i][3]]) + + tempVertices.append(vertTemplate[PlatformData.triangles[i][0]]) + tempVertices.append(vertTemplate[PlatformData.triangles[i][1]]) + tempVertices.append(vertTemplate[PlatformData.triangles[i][2]]) + tempVertices.append(vertTemplate[PlatformData.triangles[i][3]]) + + st.add_index(index + 2) + st.add_index(index + 3) + st.add_index(index + 1) + st.add_index(index + 2) + st.add_index(index + 1) + st.add_index(index + 0) + + index += 4 + + mesh = st.commit() + vertices = tempVertices + +func _ready(): + if name == "Platform1": + isActive = true + if isActive: + last = %Base + if not inMenu and name == "Platform1": + cam = %Camera3D + labelScore = %Score + + calculate_randoms() + rebuild_mesh(PlatformData.vertices) + +func _physics_process(delta): + if not isActive: + return + + if abs(position.x) >= maxMoveDistance || abs(position.z) >= maxMoveDistance: + velocity.x *= -1 + velocity.z *= -1 + + translate(velocity * delta) + + if Input.is_action_just_pressed("Click") and not inMenu: + isActive = false + cam.translate(Vector3(0, 0.1, 0)) + + var otherVerts = last.vertices + var _newVerts = [] + + if len(last.newVerts) == 0: + _newVerts = PlatformData.vertices.duplicate() + else: + _newVerts = last.newVerts.duplicate() + + if randomAxis == 0: + var currentX = position.x + var lastX = last.position.x + + if vertices[0].x + currentX < otherVerts[0].x + lastX: + _newVerts[0].x = otherVerts[0].x - currentX + lastX + _newVerts[3].x = otherVerts[0].x - currentX + lastX + _newVerts[7].x = otherVerts[0].x - currentX + lastX + _newVerts[4].x = otherVerts[0].x - currentX + lastX + + if vertices[3].x + currentX > otherVerts[3].x + lastX: + _newVerts[1].x = otherVerts[3].x - currentX + lastX + _newVerts[2].x = otherVerts[3].x - currentX + lastX + _newVerts[5].x = otherVerts[3].x - currentX + lastX + _newVerts[6].x = otherVerts[3].x - currentX + lastX + + if vertices[3].x + currentX < otherVerts[0].x + lastX or vertices[0].x + currentX > otherVerts[3].x + lastX: + get_tree().reload_current_scene() + else: + var currentZ = position.z + var lastZ = last.position.z + + if vertices[0].z + currentZ < otherVerts[0].z + lastZ: + _newVerts[0].z = otherVerts[0].z - currentZ + lastZ + _newVerts[1].z = otherVerts[0].z - currentZ + lastZ + _newVerts[2].z = otherVerts[0].z - currentZ + lastZ + _newVerts[3].z = otherVerts[0].z - currentZ + lastZ + + if vertices[3].z + currentZ > otherVerts[3].z + lastZ: + _newVerts[4].z = otherVerts[3].z - currentZ + lastZ + _newVerts[5].z = otherVerts[3].z - currentZ + lastZ + _newVerts[6].z = otherVerts[3].z - currentZ + lastZ + _newVerts[7].z = otherVerts[3].z - currentZ + lastZ + + if vertices[3].z + currentZ < otherVerts[0].z + lastZ or vertices[0].z + currentZ > otherVerts[3].z + lastZ: + get_tree().reload_current_scene() + + + newVerts = _newVerts + rebuild_mesh(_newVerts) + + var inst = load("res://platform.tscn").instantiate() + inst.cam = cam + inst.labelScore = labelScore + get_parent().add_child(inst) + + inst.isActive = false + inst.translate(Vector3(0, 0.2, 0) + position) + inst.last = self + inst.speed = speed + 0.2 + + inst.calculate_randoms() + inst.rebuild_mesh(newVerts) + + labelScore.text = str(score) + inst.score = score + 1 + inst.isActive = true diff --git a/platform.tscn b/platform.tscn new file mode 100644 index 0000000..41ad82e --- /dev/null +++ b/platform.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://1t1p7sfwxisv"] + +[ext_resource type="Script" path="res://platform.gd" id="1_sqti0"] + +[node name="Platform" type="MeshInstance3D"] +script = ExtResource("1_sqti0") diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..54fce98 --- /dev/null +++ b/project.godot @@ -0,0 +1,30 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="Stack" +config/features=PackedStringArray("4.2", "Forward Plus") +boot_splash/image="res://Icon.png" +config/icon="res://Icon.png" + +[input] + +Click={ +"deadzone": 0.5, +"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":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null) +, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} + +[rendering] + +anti_aliasing/quality/screen_space_aa=1 +anti_aliasing/quality/use_taa=true diff --git a/world.tscn b/world.tscn new file mode 100644 index 0000000..d1d5071 --- /dev/null +++ b/world.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=6 format=3 uid="uid://dpeo5y05nt5mi"] + +[ext_resource type="PackedScene" uid="uid://1t1p7sfwxisv" path="res://platform.tscn" id="1_jquwx"] +[ext_resource type="Texture2D" uid="uid://bj5w0ki1au4jr" path="res://Sky.png" id="2_rqa7j"] + +[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_qnpi8"] +panorama = ExtResource("2_rqa7j") + +[sub_resource type="Sky" id="Sky_eicqm"] +sky_material = SubResource("PanoramaSkyMaterial_qnpi8") + +[sub_resource type="Environment" id="Environment_20yoh"] +background_mode = 2 +sky = SubResource("Sky_eicqm") +tonemap_mode = 3 +volumetric_fog_density = 0.01 + +[node name="World" type="Node3D"] + +[node name="Overlay" type="CanvasLayer" parent="."] + +[node name="Score" type="Label" parent="Overlay"] +unique_name_in_owner = true +offset_right = 40.0 +offset_bottom = 23.0 + +[node name="Camera3D" type="Camera3D" parent="."] +unique_name_in_owner = true +transform = Transform3D(-0.618408, 0.567333, -0.543787, 2.98023e-08, 0.691967, 0.721929, 0.785857, 0.446447, -0.427918, -4.23832, 6.42557, -3.40231) + +[node name="Base" parent="." instance=ExtResource("1_jquwx")] +unique_name_in_owner = true +skeleton = NodePath("../Platform1") + +[node name="Platform1" parent="." instance=ExtResource("1_jquwx")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0) + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_20yoh") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.928376, 0.338154, -0.154177, -3.82119e-09, 0.414852, 0.909889, 0.371643, -0.844719, 0.385139, 0, 0, 0) +light_energy = 0.7 +light_indirect_energy = 0.0