2025-08-28 08:15:18 +08:00
|
|
|
@tool
|
2025-08-28 06:49:50 +08:00
|
|
|
extends Camera2D
|
2025-08-28 08:15:18 +08:00
|
|
|
class_name CameraManager
|
|
|
|
|
|
2025-12-16 22:37:04 +08:00
|
|
|
@export var constantOffset: Vector2 = Vector2.ZERO
|
|
|
|
|
|
2025-08-28 12:00:09 +08:00
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
|
|
2025-08-28 14:15:01 +08:00
|
|
|
var shakeIntensity: float = 0
|
2025-08-28 11:14:14 +08:00
|
|
|
|
|
|
|
|
static var instance: CameraManager = null
|
2025-08-28 08:15:18 +08:00
|
|
|
|
|
|
|
|
func _ready():
|
2025-08-28 11:14:14 +08:00
|
|
|
instance = self
|
2025-08-28 08:15:18 +08:00
|
|
|
func _physics_process(_delta):
|
|
|
|
|
if is_instance_valid(UIState.player):
|
2025-12-16 22:37:04 +08:00
|
|
|
position = UIState.player.position + constantOffset
|
2026-01-18 15:31:52 +08:00
|
|
|
position += MathTool.sampleInCircle(shakeIntensity)
|
2025-12-17 22:14:29 +08:00
|
|
|
offset += ((get_global_mouse_position() - UIState.player.position).clampf(-100, 100) - offset) * 0.15
|
2025-08-28 11:14:14 +08:00
|
|
|
|
2025-09-21 07:06:43 +08:00
|
|
|
static func shake(millseconds: float, intensity: float = 10, steper: Callable = func(currentValue, _totalValue, _restPercent): return currentValue):
|
|
|
|
|
var startTime = WorldManager.getTime()
|
|
|
|
|
instance.shakeIntensity = intensity
|
|
|
|
|
await TickTool.until(
|
|
|
|
|
func():
|
|
|
|
|
instance.shakeIntensity = steper.call(instance.shakeIntensity, intensity, 1 - (WorldManager.getTime() - startTime) / millseconds)
|
|
|
|
|
return WorldManager.getTime() - startTime >= millseconds
|
|
|
|
|
)
|
|
|
|
|
instance.shakeIntensity = 0
|
2025-08-28 12:00:09 +08:00
|
|
|
static func playAnimation(animation: String):
|
|
|
|
|
instance.animator.play(animation)
|