Added HiddedColorPlatform

This commit is contained in:
2026-06-21 19:29:27 +03:00
parent a1601c9266
commit 569cde340b
12 changed files with 147 additions and 22 deletions
+5
View File
@@ -4,6 +4,7 @@ extends CharacterBody2D
signal dead signal dead
signal interacted signal interacted
signal color_switched(new_color: CollisionSwitcher.ObjectColor)
const PICKUP_OFFSET = 16.0 const PICKUP_OFFSET = 16.0
@@ -149,3 +150,7 @@ func _rearrange_pickups() -> void:
func _on_switch_buffer_timer_timeout() -> void: func _on_switch_buffer_timer_timeout() -> void:
_is_switching_needed = false _is_switching_needed = false
func _on_collision_switched(new_color: CollisionSwitcher.ObjectColor) -> void:
color_switched.emit(new_color)
+1
View File
@@ -270,4 +270,5 @@ fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState") fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState") fall_right_state = NodePath("../FallRightState")
[connection signal="switched" from="CollisionSwitcher" to="." method="_on_collision_switched"]
[connection signal="timeout" from="SwitchBufferTimer" to="." method="_on_switch_buffer_timer_timeout"] [connection signal="timeout" from="SwitchBufferTimer" to="." method="_on_switch_buffer_timer_timeout"]
+24 -4
View File
@@ -3,7 +3,13 @@ class_name CollisionSwitcher
extends Node extends Node
signal switched signal switched(new_color: CollisionSwitcher.ObjectColor)
enum ObjectColor {
White,
Black,
}
enum Collisions { enum Collisions {
@@ -85,12 +91,14 @@ func switch_color(switch_time := 0.0) -> void:
if is_zero_approx(switch_time): if is_zero_approx(switch_time):
_state = State.Black if _state == State.White else State.White _state = State.Black if _state == State.White else State.White
switched.emit() _emit_switch_signal()
else: else:
_state = State.TransitionToBlack if _state == State.White else State.TransitionToWhite _state = State.TransitionToBlack if _state == State.White else State.TransitionToWhite
_intensity_tween = create_tween() _intensity_tween = create_tween()
_intensity_tween.tween_method(_set_shader_internsity, 0.0, MAX_INTENSITY, switch_time) _intensity_tween.tween_method(_set_shader_internsity, 0.0, MAX_INTENSITY, switch_time) \
.set_ease(Tween.EASE_OUT_IN) \
.set_trans(Tween.TRANS_SINE)
_intensity_tween.finished.connect(_update_state) _intensity_tween.finished.connect(_update_state)
@@ -115,7 +123,7 @@ func _update_state() -> void:
_state = State.Black _state = State.Black
State.TransitionToWhite: State.TransitionToWhite:
_state = State.White _state = State.White
switched.emit() _emit_switch_signal()
func _apply_color() -> void: func _apply_color() -> void:
@@ -152,3 +160,15 @@ func _apply_color_to_object(object: CollisionObject2D) -> void:
func _apply_color_to_material(material: Material) -> void: func _apply_color_to_material(material: Material) -> void:
var is_black := _state == State.Black or _state == State.TransitionToBlack var is_black := _state == State.Black or _state == State.TransitionToBlack
material.set(SHADER_SWITCH_COLORS, is_black) material.set(SHADER_SWITCH_COLORS, is_black)
func _emit_switch_signal() -> void:
var color : ObjectColor
match _state:
State.White:
color = ObjectColor.White
State.Black:
color = ObjectColor.Black
_:
return
switched.emit(color)
+2
View File
@@ -10,3 +10,5 @@ func _ready() -> void:
$Objects/LeverPlatform.switching.connect($ConnectionCables/ConnectionCablePlatform.toggle) $Objects/LeverPlatform.switching.connect($ConnectionCables/ConnectionCablePlatform.toggle)
$Objects/LeverMoving.switching.connect($Platforms/SelfMovingPlatform.toggle) $Objects/LeverMoving.switching.connect($Platforms/SelfMovingPlatform.toggle)
$Platforms/HiddenColorPlatform.set_player(player)
+6
View File
@@ -16,6 +16,7 @@
[ext_resource type="PackedScene" uid="uid://cudbspmpx6sik" path="res://game/pickups/book_pickup.tscn" id="7_fq0h3"] [ext_resource type="PackedScene" uid="uid://cudbspmpx6sik" path="res://game/pickups/book_pickup.tscn" id="7_fq0h3"]
[ext_resource type="PackedScene" uid="uid://dioc4r03dfleq" path="res://game/doors/book_door.tscn" id="8_75eok"] [ext_resource type="PackedScene" uid="uid://dioc4r03dfleq" path="res://game/doors/book_door.tscn" id="8_75eok"]
[ext_resource type="PackedScene" uid="uid://c4gqqhlew67ay" path="res://game/pickups/circle_key_pickup.tscn" id="8_g1txn"] [ext_resource type="PackedScene" uid="uid://c4gqqhlew67ay" path="res://game/pickups/circle_key_pickup.tscn" id="8_g1txn"]
[ext_resource type="PackedScene" uid="uid://bqb2qncny11a" path="res://game/platform/hidden_color_platform.tscn" id="8_lxcjr"]
[ext_resource type="PackedScene" uid="uid://ciubf1ttwc133" path="res://game/pickups/square_key_pickup.tscn" id="9_yrqjd"] [ext_resource type="PackedScene" uid="uid://ciubf1ttwc133" path="res://game/pickups/square_key_pickup.tscn" id="9_yrqjd"]
[ext_resource type="PackedScene" uid="uid://dqgmfpv2mhdpn" path="res://game/pickups/triangle_key_pickup.tscn" id="10_dea75"] [ext_resource type="PackedScene" uid="uid://dqgmfpv2mhdpn" path="res://game/pickups/triangle_key_pickup.tscn" id="10_dea75"]
[ext_resource type="PackedScene" uid="uid://be3mqeb784shj" path="res://game/objects/informative/movement_action_tip.tscn" id="10_ffor3"] [ext_resource type="PackedScene" uid="uid://be3mqeb784shj" path="res://game/objects/informative/movement_action_tip.tscn" id="10_ffor3"]
@@ -85,6 +86,11 @@ platform_width = 104
position = Vector2(200, -25) position = Vector2(200, -25)
platform_width = 80 platform_width = 80
[node name="HiddenColorPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="4" unique_id=1861027364 instance=ExtResource("8_lxcjr")]
position = Vector2(13, -104)
collision_layer = 2
platform_width = 80
[node name="LeverDoor" parent="Doors" parent_id_path=PackedInt32Array(1468144392) index="0" unique_id=1575363350 instance=ExtResource("2_r01v2")] [node name="LeverDoor" parent="Doors" parent_id_path=PackedInt32Array(1468144392) index="0" unique_id=1575363350 instance=ExtResource("2_r01v2")]
position = Vector2(416, -56) position = Vector2(416, -56)
+6 -8
View File
@@ -3,13 +3,11 @@ class_name AbstractColorPlatform
extends AbstractPlatform extends AbstractPlatform
enum PlatformColor { @export var initial_color := CollisionSwitcher.ObjectColor.White:
White, set(value):
Black, initial_color = value
} if Engine.is_editor_hint() and is_node_ready():
collision_switcher.switch_color()
@export var initial_color := PlatformColor.White
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher @onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
@@ -18,5 +16,5 @@ enum PlatformColor {
func _ready() -> void: func _ready() -> void:
super._ready() super._ready()
collision_switcher.add_material(platform_sprite.material) collision_switcher.add_material(platform_sprite.material)
if initial_color == PlatformColor.Black: if initial_color == CollisionSwitcher.ObjectColor.Black:
collision_switcher.switch_color() collision_switcher.switch_color()
-1
View File
@@ -9,7 +9,6 @@ const SHADER_PLATFORM_WIDTH = "shader_parameter/platform_width"
const ANIMATION_COLOR_SWITCHING = "color_switching" const ANIMATION_COLOR_SWITCHING = "color_switching"
const ANIMATION_HIDING = "hiding" const ANIMATION_HIDING = "hiding"
const ANIMATION_TIMER = "timer"
const ANIMATION_SELF_MOVING = "self_moving" const ANIMATION_SELF_MOVING = "self_moving"
+23
View File
@@ -0,0 +1,23 @@
@tool
class_name HiddenColorPlatform
extends AbstractColorPlatform
func _ready() -> void:
super._ready()
icon_sprite.play(ANIMATION_HIDING)
if not Engine.is_editor_hint():
if initial_color == CollisionSwitcher.ObjectColor.White:
platform_sprite.hide()
func set_player(player: Player) -> void:
player.color_switched.connect(_on_player_color_switched)
func _on_player_color_switched(player_new_color: CollisionSwitcher.ObjectColor) -> void:
if player_new_color == initial_color:
platform_sprite.hide()
else:
platform_sprite.show()
@@ -0,0 +1 @@
uid://bmdc7dyijp211
+49
View File
@@ -0,0 +1,49 @@
[gd_scene format=3 uid="uid://bqb2qncny11a"]
[ext_resource type="PackedScene" uid="uid://wpkj48bqyuy2" path="res://game/platform/abstract_color_platform.tscn" id="1_s638m"]
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="2_4acet"]
[ext_resource type="Script" uid="uid://bmdc7dyijp211" path="res://game/platform/hidden_color_platform.gd" id="2_nlrds"]
[ext_resource type="Shader" uid="uid://d4hm3vjx1rhsf" path="res://game/shaders/platform.gdshader" id="3_nlrds"]
[ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="4_h5jhn"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ff5f1"]
resource_local_to_scene = true
shader = ExtResource("2_4acet")
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_17dby"]
viewport_path = NodePath("SubViewport")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_el5k2"]
resource_local_to_scene = true
shader = ExtResource("3_nlrds")
shader_parameter/tile_size = 8.0
shader_parameter/platform_width = 24.0
shader_parameter/atlas = ExtResource("4_h5jhn")
shader_parameter/seed = 0.12241629
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hm14r"]
resource_local_to_scene = true
size = Vector2(16, 7)
[node name="HiddenColorPlatform" unique_id=137546339 instance=ExtResource("1_s638m")]
script = ExtResource("2_nlrds")
[node name="Sprite2D" parent="." index="0" unique_id=264863796]
material = SubResource("ShaderMaterial_ff5f1")
texture = SubResource("ViewportTexture_17dby")
[node name="PlatformRect" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="0" unique_id=794315918]
material = SubResource("ShaderMaterial_el5k2")
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
shape = SubResource("RectangleShape2D_hm14r")
+22 -1
View File
@@ -3,16 +3,28 @@ class_name TouchColorPlatform
extends AbstractColorPlatform extends AbstractColorPlatform
const INTENSITY = 0.85
const INTENSITY_SET_TIME = 0.5
const SWITCH_TIME = 1.5 const SWITCH_TIME = 1.5
var _is_body_in := false var _is_body_in := false
var _intensity_tween : Tween
@onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D @onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D
@onready var switch_timer: Timer = $SwitchTimer @onready var switch_timer: Timer = $SwitchTimer
func _ready() -> void:
super._ready()
icon_sprite.hide()
_reset_intensity()
func rebuild_platform() -> void: func rebuild_platform() -> void:
super.rebuild_platform() super.rebuild_platform()
touch_check_collision.shape.size.x = platform_width - 4 touch_check_collision.shape.size.x = platform_width - 4
@@ -22,6 +34,14 @@ func _switch() -> void:
collision_switcher.switch_color(SWITCH_TIME) collision_switcher.switch_color(SWITCH_TIME)
func _reset_intensity() -> void:
if _intensity_tween != null and _intensity_tween.is_running():
_intensity_tween.kill()
_intensity_tween = create_tween()
_intensity_tween.tween_property(platform_sprite.material, CollisionSwitcher.SHADER_INTENSITY, \
INTENSITY, INTENSITY_SET_TIME)
func _on_body_entered(_body: Node2D) -> void: func _on_body_entered(_body: Node2D) -> void:
_is_body_in = true _is_body_in = true
_switch() _switch()
@@ -31,7 +51,8 @@ func _on_body_exited(_body: Node2D) -> void:
_is_body_in = false _is_body_in = false
func _on_collision_switched() -> void: func _on_collision_switched(_color: CollisionSwitcher.ObjectColor) -> void:
_reset_intensity()
if _is_body_in: if _is_body_in:
switch_timer.start() switch_timer.start()
+8 -8
View File
@@ -6,7 +6,7 @@
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="3_vol56"] [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"] [ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="3_wa58h"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4wo0k"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wa58h"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("3_vol56") shader = ExtResource("3_vol56")
shader_parameter/black_color = Color(0, 0, 0, 1) shader_parameter/black_color = Color(0, 0, 0, 1)
@@ -20,10 +20,10 @@ shader_parameter/seed = 0.0
shader_parameter/direction = Vector2(1, 1) shader_parameter/direction = Vector2(1, 1)
shader_parameter/use_world_pos = false shader_parameter/use_world_pos = false
[sub_resource type="ViewportTexture" id="ViewportTexture_3k57e"] [sub_resource type="ViewportTexture" id="ViewportTexture_vol56"]
viewport_path = NodePath("SubViewport") viewport_path = NodePath("SubViewport")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_3tasl"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_4wo0k"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_4n4xw") shader = ExtResource("2_4n4xw")
shader_parameter/tile_size = 8.0 shader_parameter/tile_size = 8.0
@@ -31,7 +31,7 @@ shader_parameter/platform_width = 24.0
shader_parameter/atlas = ExtResource("3_wa58h") shader_parameter/atlas = ExtResource("3_wa58h")
shader_parameter/seed = 0.12241629 shader_parameter/seed = 0.12241629
[sub_resource type="RectangleShape2D" id="RectangleShape2D_eqoit"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_3k57e"]
resource_local_to_scene = true resource_local_to_scene = true
size = Vector2(16, 7) size = Vector2(16, 7)
@@ -42,14 +42,14 @@ size = Vector2(12, 1)
script = ExtResource("2_wa58h") script = ExtResource("2_wa58h")
[node name="Sprite2D" parent="." index="0" unique_id=264863796] [node name="Sprite2D" parent="." index="0" unique_id=264863796]
material = SubResource("ShaderMaterial_4wo0k") material = SubResource("ShaderMaterial_wa58h")
texture = SubResource("ViewportTexture_3k57e") texture = SubResource("ViewportTexture_vol56")
[node name="PlatformRect" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="0" unique_id=794315918] [node name="PlatformRect" parent="SubViewport" parent_id_path=PackedInt32Array(226200089) index="0" unique_id=794315918]
material = SubResource("ShaderMaterial_3tasl") material = SubResource("ShaderMaterial_4wo0k")
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124] [node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
shape = SubResource("RectangleShape2D_eqoit") shape = SubResource("RectangleShape2D_3k57e")
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects")] [node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects")]
objects = [NodePath(".."), NodePath("../Area2D")] objects = [NodePath(".."), NodePath("../Area2D")]