class_name GameViewportContainer extends SubViewportContainer ## SubViewportContainer with game-specific special effects const SMALL_HIT_LAG_FRAMES := 5 const BIG_HIT_LAG_FRAMES := 10 const HUGE_HIT_LAG_FRAMES := 20 var _screen_shake_intensity := 0.0 var _hit_lag_frames := -1 @onready var root_control: Control = %RootControl @onready var content: Node = %Content ## Start playing a screen shake effect. func screen_shake(intensity: float, duration: float = 0.2) -> void: if not ProjectSettings.get_setting("game/config/accessibility/enable_screen_shake"): return var tween := get_tree().create_tween() _screen_shake_intensity = intensity tween.tween_property(self, "_screen_shake_intensity", 0.0, duration).set_trans( Tween.TRANS_CUBIC ) tween.tween_callback(_reset_position) ## Hit lag for a small impact. func hit_lag_small() -> void: hit_lag(SMALL_HIT_LAG_FRAMES) ## Hit lag for a big impact. func hit_lag_big() -> void: hit_lag(BIG_HIT_LAG_FRAMES) ## Hit lag for a huge impact. func hit_lag_huge() -> void: hit_lag(HUGE_HIT_LAG_FRAMES) ## Stop processing for some number of frames. func hit_lag(frames: int = 1) -> void: if not ProjectSettings.get_setting("game/config/accessibility/enable_hit_lag"): return _hit_lag_frames = frames func _reset_position() -> void: position = Vector2.ZERO func _process(_delta: float) -> void: if _screen_shake_intensity > 0: position.x = randfn(0, _screen_shake_intensity) position.y = randfn(0, _screen_shake_intensity) if _hit_lag_frames >= 0: if _hit_lag_frames == 0: content.process_mode = Node.PROCESS_MODE_INHERIT else: content.process_mode = Node.PROCESS_MODE_DISABLED _hit_lag_frames -= 1