From 24481b1f33f306192bd38184b6fbb6c7deda4159 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Fri, 19 Jun 2026 22:03:35 +0300 Subject: [PATCH] Added controlable movement platform --- game/levels/test_level.gd | 2 ++ game/levels/test_level.tscn | 20 +++++++++++++++ game/platform/abstract_platform.tscn | 26 +++++++++---------- game/platform/moving_platform.gd | 38 ++++++++++++++++++++-------- game/platform/moving_platform.tscn | 8 +++--- project.godot | 2 +- 6 files changed, 68 insertions(+), 28 deletions(-) diff --git a/game/levels/test_level.gd b/game/levels/test_level.gd index 263a792..9d44efe 100644 --- a/game/levels/test_level.gd +++ b/game/levels/test_level.gd @@ -8,3 +8,5 @@ func _ready() -> void: $Objects/LeverPlatform.switching.connect($Platforms/ColorSwitchingPlatform.toggle) $Objects/LeverPlatform.switching.connect($ConnectionCables/ConnectionCablePlatform.toggle) + + $Objects/LeverMoving.switching.connect($Platforms/SelfMovingPlatform.toggle) diff --git a/game/levels/test_level.tscn b/game/levels/test_level.tscn index 4c778bc..7b249c2 100644 --- a/game/levels/test_level.tscn +++ b/game/levels/test_level.tscn @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://dq3080605jqta" path="res://game/objects/interactive/connection_cable.tscn" id="3_a50fq"] [ext_resource type="PackedScene" uid="uid://b3kyqvuxmfn8f" path="res://game/objects/decorative/fireplace.tscn" id="3_tuvkr"] [ext_resource type="PackedScene" uid="uid://jab32eoyc523" path="res://game/platform/moving_platform.tscn" id="4_h1708"] +[ext_resource type="Shader" uid="uid://dbsrm43wcolg4" path="res://game/shaders/connection_cable.gdshader" id="4_lxcjr"] [ext_resource type="PackedScene" uid="uid://g0n5npbt3hb2" path="res://game/doors/circle_door.tscn" id="4_yrqjd"] [ext_resource type="PackedScene" uid="uid://cojxqx5al7kyv" path="res://game/doors/locked_door.tscn" id="5_1skah"] [ext_resource type="PackedScene" uid="uid://bwmd8w677p7k3" path="res://game/platform/color_switching_platform.tscn" id="5_a50fq"] @@ -26,6 +27,20 @@ [ext_resource type="PackedScene" uid="uid://cutjutvd8dqqc" path="res://game/characters/enemies/black_cultist.tscn" id="19_ohfy3"] [ext_resource type="PackedScene" uid="uid://bv2gahb4wxgb1" path="res://game/characters/enemies/white_cultist.tscn" id="20_rt0xo"] +[sub_resource type="ShaderMaterial" id="ShaderMaterial_lxcjr"] +resource_local_to_scene = true +shader = ExtResource("4_lxcjr") +shader_parameter/glow_interval = 1.0 +shader_parameter/glow_radius = 1.0 +shader_parameter/travel_time = 5.0 + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_te8eb"] +resource_local_to_scene = true +shader = ExtResource("4_lxcjr") +shader_parameter/glow_interval = 1.0 +shader_parameter/glow_radius = 1.0 +shader_parameter/travel_time = 5.0 + [sub_resource type="Curve2D" id="Curve2D_h1708"] _data = { "points": PackedVector2Array(0, 0, 0, 0, 229, -75, 0, 0, 0, 0, 47, -75) @@ -36,10 +51,12 @@ point_count = 2 script = ExtResource("2_a2sw7") [node name="ConnectionCableDoor" parent="ConnectionCables" parent_id_path=PackedInt32Array(279521385) index="0" unique_id=1234500644 instance=ExtResource("3_a50fq")] +material = SubResource("ShaderMaterial_lxcjr") position = Vector2(208, 13) points = PackedVector2Array(0, 0, 92, 0, 92, -49, 199, -49) [node name="ConnectionCablePlatform" parent="ConnectionCables" parent_id_path=PackedInt32Array(279521385) index="1" unique_id=561577961 instance=ExtResource("3_a50fq")] +material = SubResource("ShaderMaterial_te8eb") position = Vector2(520, -35) points = PackedVector2Array(0, 0, 0, -76, -454, -76, -454, 3) @@ -113,6 +130,9 @@ position = Vector2(208, 8) [node name="LeverPlatform" parent="Objects" parent_id_path=PackedInt32Array(1320033435) index="6" unique_id=705939742 instance=ExtResource("13_00l78")] position = Vector2(520, -40) +[node name="LeverMoving" parent="Objects" parent_id_path=PackedInt32Array(1320033435) index="7" unique_id=1003631621 instance=ExtResource("13_00l78")] +position = Vector2(155, 8) + [node name="BookPickup" parent="Pickups" parent_id_path=PackedInt32Array(1113969064) index="0" unique_id=261982174 instance=ExtResource("7_fq0h3")] position = Vector2(1216, 86) diff --git a/game/platform/abstract_platform.tscn b/game/platform/abstract_platform.tscn index 2692751..9c64b8a 100644 --- a/game/platform/abstract_platform.tscn +++ b/game/platform/abstract_platform.tscn @@ -268,12 +268,12 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_v0w7w") }], -"loop": true, +"loop": 1, "name": &"color_switching", "speed": 10.0 }, { "frames": [], -"loop": true, +"loop": 1, "name": &"default", "speed": 5.0 }, { @@ -308,7 +308,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_ml711") }], -"loop": true, +"loop": 1, "name": &"hiding", "speed": 10.0 }, { @@ -331,7 +331,7 @@ animations = [{ "duration": 3.0, "texture": SubResource("AtlasTexture_uxm1i") }], -"loop": true, +"loop": 1, "name": &"moving_down_active", "speed": 10.0 }, { @@ -339,7 +339,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_yj8cj") }], -"loop": true, +"loop": 1, "name": &"moving_down_static", "speed": 10.0 }, { @@ -362,7 +362,7 @@ animations = [{ "duration": 3.0, "texture": SubResource("AtlasTexture_w5ro3") }], -"loop": true, +"loop": 1, "name": &"moving_left_active", "speed": 10.0 }, { @@ -370,7 +370,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_5xqsc") }], -"loop": true, +"loop": 1, "name": &"moving_left_static", "speed": 10.0 }, { @@ -393,7 +393,7 @@ animations = [{ "duration": 3.0, "texture": SubResource("AtlasTexture_qiapf") }], -"loop": true, +"loop": 1, "name": &"moving_right_active", "speed": 10.0 }, { @@ -401,7 +401,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_s6swh") }], -"loop": true, +"loop": 1, "name": &"moving_right_static", "speed": 10.0 }, { @@ -424,7 +424,7 @@ animations = [{ "duration": 3.0, "texture": SubResource("AtlasTexture_n8r07") }], -"loop": true, +"loop": 1, "name": &"moving_up_active", "speed": 10.0 }, { @@ -432,7 +432,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_vri0m") }], -"loop": true, +"loop": 1, "name": &"moving_up_static", "speed": 10.0 }, { @@ -467,7 +467,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_egipa") }], -"loop": true, +"loop": 1, "name": &"self_moving", "speed": 10.0 }, { @@ -484,7 +484,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_txrl7") }], -"loop": true, +"loop": 1, "name": &"timer", "speed": 10.0 }] diff --git a/game/platform/moving_platform.gd b/game/platform/moving_platform.gd index 38d998b..77b0221 100644 --- a/game/platform/moving_platform.gd +++ b/game/platform/moving_platform.gd @@ -21,10 +21,14 @@ const ANIMATION_MAP : Dictionary[Type, Dictionary] = { @export var is_loop := false -@export var type := Type.SelfMoving @export var path : Path2D @export var path_follow : PathFollow2D @export_range(0, 25, 0.1) var speed : float = 10.0 +@export var type := Type.SelfMoving: + set(value): + type = value + if is_node_ready(): + _initialize_platform() var is_moving := false @@ -32,13 +36,26 @@ var is_reverse := false var tween: Tween -@onready var restart_timer : Timer = $RestartTimer +@onready var invert_timer : Timer = $InvertTimer func _ready() -> void: super._ready() + _initialize_platform() + + +func toggle() -> void: + if type == Type.SelfMoving: return + + if is_moving: + _stop_movement() + else: + _start_movement() + + +func _initialize_platform() -> void: if not Engine.is_editor_hint() and type == Type.SelfMoving: - start_movement() + _start_movement() else: _select_animation() @@ -49,12 +66,12 @@ func _select_animation() -> void: icon_sprite.play(ANIMATION_SELF_MOVING) return - var direction : String = ANIMATION_MAP[type][is_reverse] + var direction : String = ANIMATION_MAP[type][not is_reverse] var suffix := ANIMATION_ACTIVE_SUFFIX if is_moving else ANIMATION_STATIC_SUFFIX icon_sprite.play(ANIMATION_MOVING_PREFIX + direction + suffix) -func start_movement() -> void: +func _start_movement() -> void: is_moving = true if tween and tween.is_running(): tween.kill() @@ -67,22 +84,23 @@ func start_movement() -> void: tween = create_tween() var target_ratio := 0.0 if is_reverse else 1.0 tween.tween_property(path_follow, "progress_ratio", target_ratio, duration) - tween.finished.connect(_restart_movement) + tween.finished.connect(_invert_movement) -func stop_movement() -> void: +func _stop_movement() -> void: is_moving = false if tween and tween.is_running(): tween.kill() + if not invert_timer.is_stopped(): + invert_timer.stop() _select_animation() -func _restart_movement() -> void: - is_moving = false +func _invert_movement() -> void: if is_loop: path_follow.progress_ratio = 0 else: is_reverse = not is_reverse _select_animation() - restart_timer.start() + invert_timer.start() diff --git a/game/platform/moving_platform.tscn b/game/platform/moving_platform.tscn index 383cb90..15078d5 100644 --- a/game/platform/moving_platform.tscn +++ b/game/platform/moving_platform.tscn @@ -23,8 +23,8 @@ size = Vector2(16, 7) [node name="MovingPlatform" unique_id=137546339 instance=ExtResource("1_aar0q")] script = ExtResource("2_c250g") is_loop = false -type = 0 speed = 10.0 +type = 0 [node name="Sprite2D" parent="." index="0" unique_id=264863796] texture = SubResource("ViewportTexture_aar0q") @@ -34,13 +34,13 @@ material = SubResource("ShaderMaterial_c250g") [node name="IconSprite" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="1" unique_id=1917841765] animation = &"self_moving" -frame_progress = 0.80246073 +frame_progress = 0.14216548 [node name="CollisionShape2D" parent="." index="2" unique_id=175449124] shape = SubResource("RectangleShape2D_7t213") -[node name="RestartTimer" type="Timer" parent="." index="3" unique_id=1793755125] +[node name="InvertTimer" type="Timer" parent="." index="3" unique_id=1793755125] wait_time = 3.0 one_shot = true -[connection signal="timeout" from="RestartTimer" to="." method="start_movement"] +[connection signal="timeout" from="InvertTimer" to="." method="_start_movement"] diff --git a/project.godot b/project.godot index 23ab8b8..0327531 100644 --- a/project.godot +++ b/project.godot @@ -16,7 +16,7 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true config/name="Cult Manor" run/main_scene="uid://c4iica45gnke0" -config/features=PackedStringArray("4.6", "GL Compatibility") +config/features=PackedStringArray("4.7", "GL Compatibility") boot_splash/bg_color=Color(0, 0, 0, 1) boot_splash/show_image=false config/icon="uid://cfhk8xk856i1u"