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
|
2026-05-05 06:51:48 +08:00
|
|
|
var shaking: bool = false
|
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)
|
2026-05-05 12:37:06 +08:00
|
|
|
position += MouseTool.getPositionByScreen(Vector2.ONE * 0.5, self ) / 2
|
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):
|
2026-05-03 11:09:12 +08:00
|
|
|
if StarterPanel.buildingShader: return
|
2025-09-21 07:06:43 +08:00
|
|
|
var startTime = WorldManager.getTime()
|
2026-05-08 18:44:57 +08:00
|
|
|
instance.shakeIntensity += intensity
|
2026-05-08 15:57:03 +08:00
|
|
|
instance.shaking = true
|
2025-09-21 07:06:43 +08:00
|
|
|
await TickTool.until(
|
|
|
|
|
func():
|
|
|
|
|
instance.shakeIntensity = steper.call(instance.shakeIntensity, intensity, 1 - (WorldManager.getTime() - startTime) / millseconds)
|
2026-05-05 06:51:48 +08:00
|
|
|
return WorldManager.getTime() - startTime >= millseconds || !instance.shaking
|
2025-09-21 07:06:43 +08:00
|
|
|
)
|
2026-05-08 15:57:03 +08:00
|
|
|
instance.shaking = false
|
2025-09-21 07:06:43 +08:00
|
|
|
instance.shakeIntensity = 0
|
2026-05-05 06:51:48 +08:00
|
|
|
static func shakeStop():
|
|
|
|
|
instance.shaking = false
|
|
|
|
|
instance.shakeIntensity = 0
|
2025-08-28 12:00:09 +08:00
|
|
|
static func playAnimation(animation: String):
|
|
|
|
|
instance.animator.play(animation)
|