Added color switching to the TouchColorPlatform
This commit is contained in:
@@ -3,6 +3,9 @@ class_name CollisionSwitcher
|
||||
extends Node
|
||||
|
||||
|
||||
signal switched
|
||||
|
||||
|
||||
enum Collisions {
|
||||
GREY_WORLD = 1 << 0,
|
||||
GREY_ENEMY = 1 << 4,
|
||||
@@ -82,6 +85,7 @@ func switch_color(switch_time := 0.0) -> void:
|
||||
|
||||
if is_zero_approx(switch_time):
|
||||
_state = State.Black if _state == State.White else State.White
|
||||
switched.emit()
|
||||
else:
|
||||
_state = State.TransitionToBlack if _state == State.White else State.TransitionToWhite
|
||||
|
||||
@@ -111,6 +115,7 @@ func _update_state() -> void:
|
||||
_state = State.Black
|
||||
State.TransitionToWhite:
|
||||
_state = State.White
|
||||
switched.emit()
|
||||
|
||||
|
||||
func _apply_color() -> void:
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://bwmd8w677p7k3" path="res://game/platform/trigger_color_platform.tscn" id="5_a50fq"]
|
||||
[ext_resource type="PackedScene" uid="uid://dwvv5dj8lqif2" path="res://game/doors/triangle_door.tscn" id="6_75eok"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7imlh4sl036i" path="res://game/doors/square_door.tscn" id="7_1skah"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpntbx0bpni2t" path="res://game/platform/touch_color_platform.tscn" id="7_a50fq"]
|
||||
[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://c4gqqhlew67ay" path="res://game/pickups/circle_key_pickup.tscn" id="8_g1txn"]
|
||||
@@ -25,14 +26,14 @@
|
||||
[ext_resource type="PackedScene" uid="uid://dx1yasi8wlaye" path="res://game/objects/decorative/bookstand.tscn" id="13_g3b4m"]
|
||||
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/enemies/cultist.tscn" id="27_te8eb"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h1708"]
|
||||
[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_a50fq"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_te8eb"]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("4_lxcjr")
|
||||
shader_parameter/glow_interval = 1.0
|
||||
@@ -49,12 +50,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_h1708")
|
||||
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_a50fq")
|
||||
material = SubResource("ShaderMaterial_te8eb")
|
||||
position = Vector2(520, -35)
|
||||
points = PackedVector2Array(0, 0, 0, -76, -454, -76, -454, 3)
|
||||
|
||||
@@ -80,6 +81,10 @@ collision_layer = 2
|
||||
initial_color = 1
|
||||
platform_width = 104
|
||||
|
||||
[node name="TouchColorPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="3" unique_id=1702050833 instance=ExtResource("7_a50fq")]
|
||||
position = Vector2(200, -25)
|
||||
platform_width = 80
|
||||
|
||||
[node name="LeverDoor" parent="Doors" parent_id_path=PackedInt32Array(1468144392) index="0" unique_id=1575363350 instance=ExtResource("2_r01v2")]
|
||||
position = Vector2(416, -56)
|
||||
|
||||
@@ -142,8 +147,6 @@ position = Vector2(803, -56)
|
||||
|
||||
[node name="Cultist1" parent="Enemies" parent_id_path=PackedInt32Array(857989772) index="0" unique_id=1676614852 instance=ExtResource("27_te8eb")]
|
||||
position = Vector2(743, -48)
|
||||
collision_layer = 64
|
||||
collision_mask = 33
|
||||
|
||||
[node name="Cultist2" parent="Enemies" parent_id_path=PackedInt32Array(857989772) index="1" unique_id=1025404981 instance=ExtResource("27_te8eb")]
|
||||
position = Vector2(936, -48)
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_p23e2"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("1_p23e2")
|
||||
shader_parameter/black_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/white_color = Color(1, 1, 1, 1)
|
||||
shader_parameter/switch_colors = true
|
||||
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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user