generated from krampus/template-godot4
72 lines
1.5 KiB
GDScript
72 lines
1.5 KiB
GDScript
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 _hit_lag_frames := -1
|
|
|
|
@onready var content: Node = %Content
|
|
@onready var rumbler: Rumbler = %Rumbler
|
|
|
|
|
|
## Start playing a screen shake effect.
|
|
func screen_shake(intensity: float, duration: float = 0.2) -> void:
|
|
if not Game.settings.enable_screen_shake:
|
|
return
|
|
|
|
var tween := create_tween()
|
|
rumbler.intensity = intensity
|
|
tween.tween_property(rumbler, "intensity", 0.0, duration).set_trans(Tween.TRANS_CUBIC)
|
|
tween.tween_callback(_reset_position)
|
|
|
|
|
|
## Rumble the screen indefinitely.
|
|
func set_rumble(intensity: float) -> void:
|
|
if not Game.settings.enable_screen_shake:
|
|
return
|
|
|
|
rumbler.intensity = intensity
|
|
|
|
|
|
## Stop rumbling the screen.
|
|
func stop_rumble() -> void:
|
|
set_rumble(0)
|
|
|
|
|
|
## 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 Game.settings.enable_hit_lag:
|
|
return
|
|
|
|
_hit_lag_frames = frames
|
|
|
|
|
|
func _reset_position() -> void:
|
|
position = Vector2.ZERO
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if _hit_lag_frames >= 0:
|
|
if _hit_lag_frames == 0:
|
|
get_tree().paused = false
|
|
else:
|
|
get_tree().paused = true
|
|
_hit_lag_frames -= 1
|