Timed switching brought back. Added waiting for sprite emit finishing for player switching
This commit is contained in:
@@ -84,7 +84,7 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("switch_color") and can_switch_color:
|
||||
if event.is_action_pressed("switch_color") and can_switch_color and not particles.emitting:
|
||||
_switch()
|
||||
|
||||
|
||||
|
||||
@@ -23,17 +23,24 @@ enum Collisions {
|
||||
enum State {
|
||||
Black,
|
||||
White,
|
||||
TransitionToBlack,
|
||||
TransitionToWhite,
|
||||
}
|
||||
|
||||
|
||||
const COLLISION_WHITE_SHIFT = 4
|
||||
|
||||
const MIN_INTENSITY = 0.0
|
||||
const MAX_INTENSITY = 1.0
|
||||
|
||||
const SHADER_SWITCH_COLORS = "shader_parameter/switch_colors"
|
||||
const SHADER_INTENSITY = "shader_parameter/intensity"
|
||||
|
||||
|
||||
@export var object : CollisionObject2D
|
||||
|
||||
@export var initial_state : State = State.White
|
||||
@export_range(0.0, 60.0, 0.1) var switch_time := 0.0
|
||||
@export var initial_state := State.White
|
||||
|
||||
|
||||
var material : Material:
|
||||
@@ -46,6 +53,8 @@ var _state : State:
|
||||
_state = value
|
||||
_apply_color()
|
||||
|
||||
var _intensity_tween : Tween
|
||||
|
||||
var _grey_layer := 0
|
||||
var _color_layer := 0
|
||||
|
||||
@@ -64,8 +73,16 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func switch_color() -> void:
|
||||
_state = State.Black if _state == State.White else State.White
|
||||
|
||||
if _intensity_tween != null and _intensity_tween.is_running(): return #TODO
|
||||
|
||||
if is_zero_approx(switch_time):
|
||||
_state = State.Black if _state == State.White else State.White
|
||||
else:
|
||||
_state = State.TransitionToBlack if _state == State.White else State.TransitionToWhite
|
||||
|
||||
_intensity_tween = create_tween()
|
||||
_intensity_tween.tween_method(_set_shader_internsity, 0.0, MAX_INTENSITY, switch_time)
|
||||
_intensity_tween.finished.connect(_update_state)
|
||||
|
||||
|
||||
func _get_grey_collision(collision: int) -> int:
|
||||
@@ -78,6 +95,18 @@ func _get_color_collision(collision: int) -> int:
|
||||
return black_collision | white_collision
|
||||
|
||||
|
||||
func _set_shader_internsity(value: float) -> void:
|
||||
material.set(SHADER_INTENSITY, value)
|
||||
|
||||
|
||||
func _update_state() -> void:
|
||||
match _state:
|
||||
State.TransitionToBlack:
|
||||
_state = State.Black
|
||||
State.TransitionToWhite:
|
||||
_state = State.White
|
||||
|
||||
|
||||
func _apply_color() -> void:
|
||||
var layer := 0
|
||||
var mask := 0
|
||||
@@ -89,10 +118,13 @@ func _apply_color() -> void:
|
||||
State.White:
|
||||
layer = _grey_layer | (_color_layer << COLLISION_WHITE_SHIFT)
|
||||
mask = _grey_mask | (_color_mask << COLLISION_WHITE_SHIFT)
|
||||
State.TransitionToBlack, State.TransitionToWhite:
|
||||
layer = _grey_layer | _color_layer | (_color_layer << COLLISION_WHITE_SHIFT)
|
||||
mask = _grey_mask | _color_mask | (_color_mask << COLLISION_WHITE_SHIFT)
|
||||
|
||||
object.collision_layer = layer
|
||||
object.collision_mask = mask
|
||||
|
||||
if material != null:
|
||||
var is_black := _state == State.Black
|
||||
var is_black := _state == State.Black or _state == State.TransitionToBlack
|
||||
material.set(SHADER_SWITCH_COLORS, is_black)
|
||||
|
||||
Reference in New Issue
Block a user