Reworked CollisionSwitcher to the arrays
This commit is contained in:
@@ -7,4 +7,4 @@ extends AbstractCultist
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
super._ready()
|
super._ready()
|
||||||
collision_switcher.material = sprite.material
|
collision_switcher.add_material(sprite.material)
|
||||||
|
|||||||
@@ -4,14 +4,14 @@
|
|||||||
[ext_resource type="Script" uid="uid://das7ujanefsn0" path="res://game/characters/enemies/abstract_color_cultist.gd" id="2_rd56i"]
|
[ext_resource type="Script" uid="uid://das7ujanefsn0" path="res://game/characters/enemies/abstract_color_cultist.gd" id="2_rd56i"]
|
||||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="3_e5cea"]
|
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="3_e5cea"]
|
||||||
|
|
||||||
[sub_resource type="ViewportTexture" id="ViewportTexture_c7l74"]
|
[sub_resource type="ViewportTexture" id="ViewportTexture_f5md8"]
|
||||||
viewport_path = NodePath("SubViewport")
|
viewport_path = NodePath("SubViewport")
|
||||||
|
|
||||||
[node name="AbstractColorCultist" unique_id=644641841 instance=ExtResource("1_12hr0")]
|
[node name="AbstractColorCultist" unique_id=644641841 instance=ExtResource("1_12hr0")]
|
||||||
script = ExtResource("2_rd56i")
|
script = ExtResource("2_rd56i")
|
||||||
|
|
||||||
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
|
[node name="CultistSprite" parent="." index="1" unique_id=797412888]
|
||||||
texture = SubResource("ViewportTexture_c7l74")
|
texture = SubResource("ViewportTexture_f5md8")
|
||||||
|
|
||||||
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552 node_paths=PackedStringArray("object") instance=ExtResource("3_e5cea")]
|
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552 node_paths=PackedStringArray("objects") instance=ExtResource("3_e5cea")]
|
||||||
object = NodePath("..")
|
objects = [NodePath("..")]
|
||||||
|
|||||||
@@ -29,14 +29,17 @@ var _is_switching_needed := false
|
|||||||
@onready var particles : GPUParticles2D = $GPUParticles2D
|
@onready var particles : GPUParticles2D = $GPUParticles2D
|
||||||
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||||
@onready var pickups : Node2D = $Pickups
|
@onready var pickups : Node2D = $Pickups
|
||||||
|
|
||||||
|
@onready var switch_buffer_timer : Timer = $SwitchBufferTimer
|
||||||
@onready var jump_buffer_timer : Timer = $JumpBufferTimer
|
@onready var jump_buffer_timer : Timer = $JumpBufferTimer
|
||||||
@onready var coyote_time_timer : Timer = $CoyoteTimeTimer
|
@onready var coyote_time_timer : Timer = $CoyoteTimeTimer
|
||||||
|
|
||||||
@onready var center_area : Area2D = $CenterArea2D
|
@onready var center_area : Area2D = $CenterArea2D
|
||||||
@onready var state_machine : PlayerStateMachine = $PlayerStateMachine
|
@onready var state_machine : PlayerStateMachine = $PlayerStateMachine
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
collision_switcher.material = sprite.material
|
collision_switcher.add_material(sprite.material)
|
||||||
|
|
||||||
state_machine.init()
|
state_machine.init()
|
||||||
|
|
||||||
@@ -77,7 +80,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
else:
|
else:
|
||||||
_slow_down(delta)
|
_slow_down(delta)
|
||||||
|
|
||||||
if _is_switching_needed:
|
if _is_switching_needed and not is_dead:
|
||||||
_switch()
|
_switch()
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
@@ -85,22 +88,19 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("switch_color") and can_switch_color and not particles.emitting:
|
if event.is_action_pressed("switch_color") and can_switch_color and not is_dead:
|
||||||
|
_is_switching_needed = true
|
||||||
|
switch_buffer_timer.start()
|
||||||
_switch()
|
_switch()
|
||||||
|
|
||||||
|
|
||||||
func _switch() -> void:
|
func _switch() -> void:
|
||||||
_is_switching_needed = false
|
if center_area.get_overlapping_bodies().size() == 0 and not particles.emitting:
|
||||||
|
|
||||||
if is_dead:
|
|
||||||
return
|
|
||||||
|
|
||||||
if center_area.get_overlapping_bodies().size() == 0:
|
|
||||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_switch, global_position)
|
SoundManager.play_sfx_stream(SoundManager.sfx_stream_switch, global_position)
|
||||||
collision_switcher.switch_color()
|
collision_switcher.switch_color()
|
||||||
|
switch_buffer_timer.stop()
|
||||||
particles.restart()
|
particles.restart()
|
||||||
else:
|
_is_switching_needed = false
|
||||||
_is_switching_needed = true
|
|
||||||
|
|
||||||
|
|
||||||
func kill(type := KillingArea.Type.None) -> void:
|
func kill(type := KillingArea.Type.None) -> void:
|
||||||
@@ -141,3 +141,7 @@ func _rearrange_pickups() -> void:
|
|||||||
var node := children[i] as Node2D
|
var node := children[i] as Node2D
|
||||||
node.position.x = i * PICKUP_OFFSET - pickup_shift
|
node.position.x = i * PICKUP_OFFSET - pickup_shift
|
||||||
node.position.y = 0
|
node.position.y = 0
|
||||||
|
|
||||||
|
|
||||||
|
func _on_switch_buffer_timer_timeout() -> void:
|
||||||
|
_is_switching_needed = false
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ process_material = SubResource("ParticleProcessMaterial_bfpdl")
|
|||||||
position = Vector2(0, 1)
|
position = Vector2(0, 1)
|
||||||
shape = SubResource("CapsuleShape2D_xln5q")
|
shape = SubResource("CapsuleShape2D_xln5q")
|
||||||
|
|
||||||
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
|
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("objects") instance=ExtResource("2_j06tb")]
|
||||||
object = NodePath("..")
|
objects = [NodePath("..")]
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
|
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
|
||||||
process_callback = 0
|
process_callback = 0
|
||||||
@@ -76,6 +76,10 @@ drag_bottom_margin = 0.1
|
|||||||
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
|
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
|
||||||
position = Vector2(0, -24)
|
position = Vector2(0, -24)
|
||||||
|
|
||||||
|
[node name="SwitchBufferTimer" type="Timer" parent="." unique_id=115300327]
|
||||||
|
wait_time = 0.5
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
|
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
|
||||||
wait_time = 0.1
|
wait_time = 0.1
|
||||||
one_shot = true
|
one_shot = true
|
||||||
@@ -240,3 +244,5 @@ jump_right_state = NodePath("../JumpRightState")
|
|||||||
fall_state = NodePath("../FallState")
|
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="timeout" from="SwitchBufferTimer" to="." method="_on_switch_buffer_timer_timeout"]
|
||||||
|
|||||||
+41
-25
@@ -37,16 +37,13 @@ const SHADER_SWITCH_COLORS = "shader_parameter/switch_colors"
|
|||||||
const SHADER_INTENSITY = "shader_parameter/intensity"
|
const SHADER_INTENSITY = "shader_parameter/intensity"
|
||||||
|
|
||||||
|
|
||||||
@export var object : CollisionObject2D
|
@export var objects : Array[CollisionObject2D] = []
|
||||||
|
|
||||||
@export var initial_state := State.White
|
@export var initial_state := State.White
|
||||||
|
|
||||||
|
|
||||||
var material : Material:
|
var _materials : Array[Material]
|
||||||
set(value):
|
|
||||||
material = value
|
|
||||||
if is_node_ready():
|
|
||||||
_apply_color()
|
|
||||||
|
|
||||||
var _state : State:
|
var _state : State:
|
||||||
set(value):
|
set(value):
|
||||||
@@ -56,25 +53,30 @@ var _state : State:
|
|||||||
|
|
||||||
var _intensity_tween : Tween
|
var _intensity_tween : Tween
|
||||||
|
|
||||||
var _grey_layer := 0
|
var _grey_layers : Dictionary[CollisionObject2D, int] = {}
|
||||||
var _color_layer := 0
|
var _color_layers : Dictionary[CollisionObject2D, int] = {}
|
||||||
|
|
||||||
var _grey_mask := 0
|
var _grey_masks : Dictionary[CollisionObject2D, int] = {}
|
||||||
var _color_mask := 0
|
var _color_masks : Dictionary[CollisionObject2D, int] = {}
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_grey_layer = _get_grey_collision(object.collision_layer)
|
for object in objects:
|
||||||
_color_layer = _get_color_collision(object.collision_layer)
|
_grey_layers[object] = _get_grey_collision(object.collision_layer)
|
||||||
|
_color_layers[object] = _get_color_collision(object.collision_layer)
|
||||||
_grey_mask = _get_grey_collision(object.collision_mask)
|
_grey_masks[object] = _get_grey_collision(object.collision_mask)
|
||||||
_color_mask = _get_color_collision(object.collision_mask)
|
_color_masks[object] = _get_color_collision(object.collision_mask)
|
||||||
|
|
||||||
_state = initial_state
|
_state = initial_state
|
||||||
|
|
||||||
_apply_color()
|
_apply_color()
|
||||||
|
|
||||||
|
|
||||||
|
func add_material(material: Material) -> void:
|
||||||
|
_materials.append(material)
|
||||||
|
_apply_color_to_material(material)
|
||||||
|
|
||||||
|
|
||||||
func switch_color(switch_time := 0.0) -> void:
|
func switch_color(switch_time := 0.0) -> void:
|
||||||
if _intensity_tween != null and _intensity_tween.is_running(): return #TODO
|
if _intensity_tween != null and _intensity_tween.is_running(): return #TODO
|
||||||
|
|
||||||
@@ -99,7 +101,8 @@ func _get_color_collision(collision: int) -> int:
|
|||||||
|
|
||||||
|
|
||||||
func _set_shader_internsity(value: float) -> void:
|
func _set_shader_internsity(value: float) -> void:
|
||||||
material.set(SHADER_INTENSITY, value)
|
for material in _materials:
|
||||||
|
material.set(SHADER_INTENSITY, value)
|
||||||
|
|
||||||
|
|
||||||
func _update_state() -> void:
|
func _update_state() -> void:
|
||||||
@@ -111,23 +114,36 @@ func _update_state() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _apply_color() -> void:
|
func _apply_color() -> void:
|
||||||
|
for object in objects:
|
||||||
|
_apply_color_to_object(object)
|
||||||
|
|
||||||
|
for material in _materials:
|
||||||
|
_apply_color_to_material(material)
|
||||||
|
|
||||||
|
|
||||||
|
func _apply_color_to_object(object: CollisionObject2D) -> void:
|
||||||
var layer := 0
|
var layer := 0
|
||||||
var mask := 0
|
var mask := 0
|
||||||
|
var grey_layer := _grey_layers[object]
|
||||||
|
var color_layer := _color_layers[object]
|
||||||
|
var grey_mask := _grey_masks[object]
|
||||||
|
var color_mask := _color_masks[object]
|
||||||
|
|
||||||
match _state:
|
match _state:
|
||||||
State.Black:
|
State.Black:
|
||||||
layer = _grey_layer | _color_layer
|
layer = grey_layer | color_layer
|
||||||
mask = _grey_mask | _color_mask
|
mask = grey_mask | color_mask
|
||||||
State.White:
|
State.White:
|
||||||
layer = _grey_layer | (_color_layer << COLLISION_WHITE_SHIFT)
|
layer = grey_layer | (color_layer << COLLISION_WHITE_SHIFT)
|
||||||
mask = _grey_mask | (_color_mask << COLLISION_WHITE_SHIFT)
|
mask = grey_mask | (color_mask << COLLISION_WHITE_SHIFT)
|
||||||
State.TransitionToBlack, State.TransitionToWhite:
|
State.TransitionToBlack, State.TransitionToWhite:
|
||||||
layer = _grey_layer | _color_layer | (_color_layer << COLLISION_WHITE_SHIFT)
|
layer = grey_layer | color_layer | (color_layer << COLLISION_WHITE_SHIFT)
|
||||||
mask = _grey_mask | _color_mask | (_color_mask << COLLISION_WHITE_SHIFT)
|
mask = grey_mask | color_mask | (color_mask << COLLISION_WHITE_SHIFT)
|
||||||
|
|
||||||
object.collision_layer = layer
|
object.collision_layer = layer
|
||||||
object.collision_mask = mask
|
object.collision_mask = mask
|
||||||
|
|
||||||
if material != null:
|
|
||||||
var is_black := _state == State.Black or _state == State.TransitionToBlack
|
func _apply_color_to_material(material: Material) -> void:
|
||||||
material.set(SHADER_SWITCH_COLORS, is_black)
|
var is_black := _state == State.Black or _state == State.TransitionToBlack
|
||||||
|
material.set(SHADER_SWITCH_COLORS, is_black)
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ enum PlatformColor {
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
super._ready()
|
super._ready()
|
||||||
collision_switcher.material = platform_sprite.material
|
collision_switcher.add_material(platform_sprite.material)
|
||||||
if initial_color == PlatformColor.Black:
|
if initial_color == PlatformColor.Black:
|
||||||
collision_switcher.switch_color()
|
collision_switcher.switch_color()
|
||||||
|
|||||||
@@ -37,5 +37,5 @@ material = SubResource("ShaderMaterial_vbsvi")
|
|||||||
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
|
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
|
||||||
shape = SubResource("RectangleShape2D_pbfpg")
|
shape = SubResource("RectangleShape2D_pbfpg")
|
||||||
|
|
||||||
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("object") instance=ExtResource("6_mk014")]
|
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects") instance=ExtResource("6_mk014")]
|
||||||
object = NodePath("..")
|
objects = [NodePath("..")]
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ extends AbstractColorPlatform
|
|||||||
|
|
||||||
|
|
||||||
@onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D
|
@onready var touch_check_collision: CollisionShape2D = $Area2D/CollisionShape2D
|
||||||
|
@onready var area_collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||||
|
|
||||||
|
|
||||||
func rebuild_platform() -> void:
|
func rebuild_platform() -> void:
|
||||||
super.rebuild_platform()
|
super.rebuild_platform()
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ material = SubResource("ShaderMaterial_wa58h")
|
|||||||
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
|
[node name="CollisionShape2D" parent="." index="2" unique_id=175449124]
|
||||||
shape = SubResource("RectangleShape2D_vol56")
|
shape = SubResource("RectangleShape2D_vol56")
|
||||||
|
|
||||||
|
[node name="CollisionSwitcher" parent="." index="3" unique_id=542648449 node_paths=PackedStringArray("objects")]
|
||||||
|
objects = [NodePath(".."), NodePath("../Area2D")]
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="." index="4" unique_id=1655744842]
|
[node name="Area2D" type="Area2D" parent="." index="4" unique_id=1655744842]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 192
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" index="0" unique_id=1261028767]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" index="0" unique_id=1261028767]
|
||||||
position = Vector2(0, -4.5)
|
position = Vector2(0, -4.5)
|
||||||
|
|||||||
Reference in New Issue
Block a user