Added color switching to the TouchColorPlatform

This commit is contained in:
2026-06-20 23:23:47 +03:00
parent 66ee9887c8
commit 6452b8e2e3
5 changed files with 79 additions and 14 deletions
+30 -1
View File
@@ -3,10 +3,39 @@ class_name TouchColorPlatform
extends AbstractColorPlatform
const SWITCH_TIME = 1.5
var _is_body_in := false
@onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D
@onready var area_collision_switcher : CollisionSwitcher = $CollisionSwitcher
@onready var switch_timer: Timer = $SwitchTimer
func rebuild_platform() -> void:
super.rebuild_platform()
touch_check_collision.shape.size.x = platform_width - 4
func _switch() -> void:
collision_switcher.switch_color(SWITCH_TIME)
func _on_body_entered(_body: Node2D) -> void:
_is_body_in = true
_switch()
func _on_body_exited(_body: Node2D) -> void:
_is_body_in = false
func _on_collision_switched() -> void:
if _is_body_in:
switch_timer.start()
func _on_switch_timer_timeout() -> void:
if _is_body_in:
_switch()
+31 -6
View File
@@ -3,12 +3,27 @@
[ext_resource type="PackedScene" uid="uid://wpkj48bqyuy2" path="res://game/platform/abstract_color_platform.tscn" id="1_xxggt"]
[ext_resource type="Shader" uid="uid://d4hm3vjx1rhsf" path="res://game/shaders/platform.gdshader" id="2_4n4xw"]
[ext_resource type="Script" uid="uid://d2xfxje428psp" path="res://game/platform/touch_color_platform.gd" id="2_wa58h"]
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="3_vol56"]
[ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="3_wa58h"]
[sub_resource type="ViewportTexture" id="ViewportTexture_4n4xw"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4wo0k"]
resource_local_to_scene = true
shader = ExtResource("3_vol56")
shader_parameter/black_color = Color(0, 0, 0, 1)
shader_parameter/white_color = Color(1, 1, 1, 1)
shader_parameter/switch_colors = false
shader_parameter/threshold = 0.5
shader_parameter/speed = 1.0
shader_parameter/intensity = 1.0
shader_parameter/scale = 5.0
shader_parameter/seed = 0.0
shader_parameter/direction = Vector2(1, 1)
shader_parameter/use_world_pos = false
[sub_resource type="ViewportTexture" id="ViewportTexture_3k57e"]
viewport_path = NodePath("SubViewport")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wa58h"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_3tasl"]
resource_local_to_scene = true
shader = ExtResource("2_4n4xw")
shader_parameter/tile_size = 8.0
@@ -16,7 +31,7 @@ shader_parameter/platform_width = 24.0
shader_parameter/atlas = ExtResource("3_wa58h")
shader_parameter/seed = 0.12241629
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vol56"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_eqoit"]
resource_local_to_scene = true
size = Vector2(16, 7)
@@ -27,13 +42,14 @@ size = Vector2(12, 1)
script = ExtResource("2_wa58h")
[node name="Sprite2D" parent="." index="0" unique_id=264863796]
texture = SubResource("ViewportTexture_4n4xw")
material = SubResource("ShaderMaterial_4wo0k")
texture = SubResource("ViewportTexture_3k57e")
[node name="PlatformRect" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="0" unique_id=794315918]
material = SubResource("ShaderMaterial_wa58h")
material = SubResource("ShaderMaterial_3tasl")
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
shape = SubResource("RectangleShape2D_vol56")
shape = SubResource("RectangleShape2D_eqoit")
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects")]
objects = [NodePath(".."), NodePath("../Area2D")]
@@ -46,3 +62,12 @@ collision_mask = 192
position = Vector2(0, -4.5)
shape = SubResource("RectangleShape2D_bhunq")
debug_color = Color(0.9020316, 0.24375501, 0.4918024, 0.41960785)
[node name="SwitchTimer" type="Timer" parent="." index="5" unique_id=1137076745]
wait_time = 0.5
one_shot = true
[connection signal="switched" from="CollisionSwitcher" to="." method="_on_collision_switched"]
[connection signal="body_entered" from="Area2D" to="." method="_on_body_entered"]
[connection signal="body_exited" from="Area2D" to="." method="_on_body_exited"]
[connection signal="timeout" from="SwitchTimer" to="." method="_on_switch_timer_timeout"]