Added SelfMovingPlatform

This commit is contained in:
2026-06-12 18:38:22 +03:00
parent 59d71a4c57
commit 22475d78c2
6 changed files with 208 additions and 16 deletions
+28 -7
View File
@@ -3,8 +3,8 @@
[ext_resource type="PackedScene" uid="uid://mpsu4g2b5h3a" path="res://game/levels/abstract_level.tscn" id="1_15okj"]
[ext_resource type="Script" uid="uid://bc114fx0hcb6s" path="res://game/levels/test_level.gd" id="2_a2sw7"]
[ext_resource type="PackedScene" uid="uid://ct6n0u0iegynv" path="res://game/doors/lever_door.tscn" id="2_r01v2"]
[ext_resource type="PackedScene" uid="uid://guvijso3k6eq" path="res://game/platform/abstract_platform.tscn" id="3_pmn5w"]
[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/self_moving_platform.tscn" id="4_h1708"]
[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://dwvv5dj8lqif2" path="res://game/doors/triangle_door.tscn" id="6_75eok"]
@@ -25,13 +25,38 @@
[ext_resource type="PackedScene" uid="uid://bv2gahb4wxgb1" path="res://game/characters/enemies/white_cultist.tscn" id="20_rt0xo"]
[ext_resource type="PackedScene" uid="uid://wpkj48bqyuy2" path="res://game/platform/abstract_color_platform.tscn" id="24_h1708"]
[sub_resource type="Curve2D" id="Curve2D_h1708"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 229, -75, 0, 0, 0, 0, 47, -75, 0, 0, 0, 0, 160, -26, 0, 0, 0, 0, 229, -75)
}
point_count = 4
[node name="TestLevel" unique_id=600627332 instance=ExtResource("1_15okj")]
script = ExtResource("2_a2sw7")
[node name="AbstractPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="0" unique_id=1226827206 instance=ExtResource("3_pmn5w")]
position = Vector2(180, -51)
[node name="AbstractColoredPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="0" unique_id=137546339 instance=ExtResource("24_h1708")]
position = Vector2(274, -81)
platform_width = 48
[node name="SelfMovingPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="1" unique_id=349378100 node_paths=PackedStringArray("path_follow") instance=ExtResource("4_h1708")]
position = Vector2(201.03143, -75)
rotation = -3.1415925
is_loop = true
path_follow = NodePath("../Path2D/PathFollow2D")
platform_width = 104
[node name="Path2D" type="Path2D" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="2" unique_id=1306055237]
curve = SubResource("Curve2D_h1708")
[node name="PathFollow2D" type="PathFollow2D" parent="Platforms/Path2D" index="0" unique_id=1206016336]
position = Vector2(201.03143, -75)
rotation = 3.1415927
progress = 27.97701
rotates = false
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="Platforms/Path2D/PathFollow2D" index="0" unique_id=1642833722]
remote_path = NodePath("../../../SelfMovingPlatform")
[node name="LeverDoor" parent="Doors" parent_id_path=PackedInt32Array(1468144392) index="0" unique_id=1575363350 instance=ExtResource("2_r01v2")]
position = Vector2(416, -56)
@@ -115,7 +140,3 @@ position = Vector2(1334, 103)
[node name="CollisionShape2D" parent="LevelEnd" index="0" unique_id=937956890]
position = Vector2(42, 59)
[node name="AbstractColoredPlatform" parent="." index="10" unique_id=137546339 instance=ExtResource("24_h1708")]
position = Vector2(274, -81)
platform_width = 48
+7 -9
View File
@@ -1,6 +1,6 @@
@tool
class_name AbstractPlatform
extends Node2D
extends AnimatableBody2D
const TILE_SIZE = 8
@@ -23,8 +23,9 @@ const MAX_WIDTH = TILE_SIZE * 32
func _ready() -> void:
if not Engine.is_editor_hint():
platform_rect.material.set_shader_parameter("seed", randf())
platform_rect.material.set_shader_parameter("tile_size", TILE_SIZE)
platform_rect.material.set_shader_parameter("seed", randf())
rebuild_platform()
@@ -32,14 +33,11 @@ func rebuild_platform() -> void:
var shape := collision.shape as RectangleShape2D
shape.size.x = platform_width
sub_viewport.size = Vector2(platform_width, TILE_SIZE)
var platfor_size := Vector2(platform_width, TILE_SIZE)
sub_viewport.size = platfor_size
icon_sprite.position = platfor_size/2
platform_rect.size.x = platform_width
platform_rect.position = Vector2.ZERO
icon_sprite.position = Vector2.ZERO
platform_rect.material.set_shader_parameter("platform_width", platform_width)
func _physics_process(_delta: float) -> void:
if Engine.is_editor_hint():
return
+3
View File
@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://egknefyib2ui"]
[node name="PlatformPath" type="Line2D" unique_id=2089103569]
+50
View File
@@ -0,0 +1,50 @@
@tool
class_name SelfMovingPlatform
extends AbstractPlatform
const SPEED_FACTOR = 0.025
const ANIMATION_ACTIVE = "active"
@export var is_loop := false
@export var path_follow : PathFollow2D
@export_range(0, 25, 0.1) var speed : float = 10.0
var is_reverse := false
var tween: Tween
func _ready() -> void:
super._ready()
icon_sprite.play(ANIMATION_ACTIVE)
if not Engine.is_editor_hint():
_start_movement()
func _start_movement() -> void:
if tween and tween.is_running():
tween.kill()
var target := 0.0 if is_reverse else 1.0
var distance := absf(target - path_follow.progress_ratio)
var duration := distance / (speed * SPEED_FACTOR)
tween = create_tween()
if not is_loop:
tween.set_trans(Tween.TRANS_SINE)
tween.set_ease(Tween.EASE_IN_OUT)
tween.finished.connect(_on_tween_finished)
tween.tween_property(path_follow, "progress_ratio", target, duration)
func _on_tween_finished() -> void:
if is_loop:
path_follow.progress_ratio = 0
else:
is_reverse = not is_reverse
_start_movement()
@@ -0,0 +1 @@
uid://cwji3vqis6w6b
+119
View File
@@ -0,0 +1,119 @@
[gd_scene format=3 uid="uid://jab32eoyc523"]
[ext_resource type="PackedScene" uid="uid://guvijso3k6eq" path="res://game/platform/abstract_platform.tscn" id="1_jmy7p"]
[ext_resource type="Script" uid="uid://cwji3vqis6w6b" path="res://game/platform/self_moving_platform.gd" id="2_ayqtn"]
[ext_resource type="Shader" uid="uid://d4hm3vjx1rhsf" path="res://game/shaders/platform.gdshader" id="2_ex4q8"]
[ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="3_ayqtn"]
[ext_resource type="Texture2D" uid="uid://bi2h4g71bro7v" path="res://images/level/platform-icons.png" id="5_ayqtn"]
[sub_resource type="ViewportTexture" id="ViewportTexture_ayqtn"]
viewport_path = NodePath("SubViewport")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_v7ftt"]
resource_local_to_scene = true
shader = ExtResource("2_ex4q8")
shader_parameter/tile_size = 8.0
shader_parameter/platform_width = 24.0
shader_parameter/atlas = ExtResource("3_ayqtn")
shader_parameter/seed = 0.94376683
[sub_resource type="AtlasTexture" id="AtlasTexture_v7ftt"]
atlas = ExtResource("5_ayqtn")
region = Rect2(0, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_xuyth"]
atlas = ExtResource("5_ayqtn")
region = Rect2(8, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_4wvh7"]
atlas = ExtResource("5_ayqtn")
region = Rect2(16, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_q6fss"]
atlas = ExtResource("5_ayqtn")
region = Rect2(24, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_myyrw"]
atlas = ExtResource("5_ayqtn")
region = Rect2(32, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_q3dcw"]
atlas = ExtResource("5_ayqtn")
region = Rect2(40, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_gb0pd"]
atlas = ExtResource("5_ayqtn")
region = Rect2(32, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_sqmiv"]
atlas = ExtResource("5_ayqtn")
region = Rect2(24, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_mvt4t"]
atlas = ExtResource("5_ayqtn")
region = Rect2(16, 48, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_ppe0t"]
atlas = ExtResource("5_ayqtn")
region = Rect2(8, 48, 8, 8)
[sub_resource type="SpriteFrames" id="SpriteFrames_22kvf"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_v7ftt")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xuyth")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4wvh7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_q6fss")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_myyrw")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_q3dcw")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_gb0pd")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_sqmiv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_mvt4t")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ppe0t")
}],
"loop": true,
"name": &"active",
"speed": 10.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xuyth"]
resource_local_to_scene = true
size = Vector2(16, 7)
[node name="SelfMovingPlatform" unique_id=137546339 instance=ExtResource("1_jmy7p")]
script = ExtResource("2_ayqtn")
speed = 10.0
[node name="Sprite2D" parent="." index="0" unique_id=264863796]
texture = SubResource("ViewportTexture_ayqtn")
[node name="PlatformRect" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="0" unique_id=794315918]
material = SubResource("ShaderMaterial_v7ftt")
[node name="IconSprite" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="1" unique_id=1917841765]
position = Vector2(8, 4)
sprite_frames = SubResource("SpriteFrames_22kvf")
animation = &"active"
frame_progress = 0.974508
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
shape = SubResource("RectangleShape2D_xuyth")