Added HiddedColorPlatform
This commit is contained in:
@@ -3,13 +3,11 @@ class_name AbstractColorPlatform
|
||||
extends AbstractPlatform
|
||||
|
||||
|
||||
enum PlatformColor {
|
||||
White,
|
||||
Black,
|
||||
}
|
||||
|
||||
|
||||
@export var initial_color := PlatformColor.White
|
||||
@export var initial_color := CollisionSwitcher.ObjectColor.White:
|
||||
set(value):
|
||||
initial_color = value
|
||||
if Engine.is_editor_hint() and is_node_ready():
|
||||
collision_switcher.switch_color()
|
||||
|
||||
|
||||
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||
@@ -18,5 +16,5 @@ enum PlatformColor {
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
collision_switcher.add_material(platform_sprite.material)
|
||||
if initial_color == PlatformColor.Black:
|
||||
if initial_color == CollisionSwitcher.ObjectColor.Black:
|
||||
collision_switcher.switch_color()
|
||||
|
||||
@@ -9,7 +9,6 @@ const SHADER_PLATFORM_WIDTH = "shader_parameter/platform_width"
|
||||
|
||||
const ANIMATION_COLOR_SWITCHING = "color_switching"
|
||||
const ANIMATION_HIDING = "hiding"
|
||||
const ANIMATION_TIMER = "timer"
|
||||
|
||||
const ANIMATION_SELF_MOVING = "self_moving"
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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")
|
||||
@@ -3,16 +3,28 @@ class_name TouchColorPlatform
|
||||
extends AbstractColorPlatform
|
||||
|
||||
|
||||
const INTENSITY = 0.85
|
||||
const INTENSITY_SET_TIME = 0.5
|
||||
|
||||
|
||||
const SWITCH_TIME = 1.5
|
||||
|
||||
|
||||
var _is_body_in := false
|
||||
|
||||
var _intensity_tween : Tween
|
||||
|
||||
|
||||
@onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D
|
||||
@onready var switch_timer: Timer = $SwitchTimer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
icon_sprite.hide()
|
||||
_reset_intensity()
|
||||
|
||||
|
||||
func rebuild_platform() -> void:
|
||||
super.rebuild_platform()
|
||||
touch_check_collision.shape.size.x = platform_width - 4
|
||||
@@ -22,6 +34,14 @@ func _switch() -> void:
|
||||
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:
|
||||
_is_body_in = true
|
||||
_switch()
|
||||
@@ -31,7 +51,8 @@ func _on_body_exited(_body: Node2D) -> void:
|
||||
_is_body_in = false
|
||||
|
||||
|
||||
func _on_collision_switched() -> void:
|
||||
func _on_collision_switched(_color: CollisionSwitcher.ObjectColor) -> void:
|
||||
_reset_intensity()
|
||||
if _is_body_in:
|
||||
switch_timer.start()
|
||||
|
||||
|
||||
@@ -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="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
|
||||
shader = ExtResource("3_vol56")
|
||||
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/use_world_pos = false
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_3k57e"]
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_vol56"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_3tasl"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4wo0k"]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("2_4n4xw")
|
||||
shader_parameter/tile_size = 8.0
|
||||
@@ -31,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_eqoit"]
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3k57e"]
|
||||
resource_local_to_scene = true
|
||||
size = Vector2(16, 7)
|
||||
|
||||
@@ -42,14 +42,14 @@ size = Vector2(12, 1)
|
||||
script = ExtResource("2_wa58h")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0" unique_id=264863796]
|
||||
material = SubResource("ShaderMaterial_4wo0k")
|
||||
texture = SubResource("ViewportTexture_3k57e")
|
||||
material = SubResource("ShaderMaterial_wa58h")
|
||||
texture = SubResource("ViewportTexture_vol56")
|
||||
|
||||
[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]
|
||||
shape = SubResource("RectangleShape2D_eqoit")
|
||||
shape = SubResource("RectangleShape2D_3k57e")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects")]
|
||||
objects = [NodePath(".."), NodePath("../Area2D")]
|
||||
|
||||
Reference in New Issue
Block a user