extends Camera2D

@export var INTENSITY = 2.0
@export var DURATION = 1000.0
@export var STARTTIME = 0

var currentStrength = 1

func _ready() -> void:
	randomize()

func _process(delta: float) -> void:
	var decreaser = (DURATION - (Time.get_ticks_msec() - STARTTIME)) / DURATION
	
	var randX = randf_range(-1,1) * currentStrength * decreaser
	var randY = randf_range(-1,1) * currentStrength * decreaser
	offset = Vector2(randX, randY)
	
	if decreaser < 0:
		offset = Vector2.ZERO
		
func shake(strength : float = 1, duration : float = 1):
	currentStrength = float(strength)
	DURATION = float(duration*1000)
	STARTTIME = Time.get_ticks_msec()
		
