Jam10/Scripts/Units/FollowReplay.gd

30 lines
733 B
GDScript3
Raw Permalink Normal View History

2023-01-30 08:56:47 +00:00
extends Unit
var replay : ReplayRecording = null
2023-01-30 10:12:53 +00:00
export var replay_file: String
func _ready():
._ready()
replay = ReplayRecording.new()
2023-01-30 19:49:06 +00:00
replay.load_from_uri(replay_file % MusicController.difficulty)
2023-01-30 10:12:53 +00:00
2023-01-30 08:56:47 +00:00
func process_unit(delta : float, time_elapsed : float):
self.time_elapsed = time_elapsed
2023-01-30 10:12:53 +00:00
if replay != null and replay.time_per_frame > 0:
2023-01-30 08:56:47 +00:00
handle_replay(time_elapsed)
func handle_replay(at_time: float):
var frame: int = int(at_time / replay.time_per_frame)
var subframe: float = (at_time / replay.time_per_frame) - frame
pos = lerp(replay.position(frame), replay.position(frame + 1), subframe)
var sprite: int = replay.sprite(frame)
var index: int = sprite >> 3
sprite &= 7
2023-01-30 10:12:53 +00:00
set_sprite(sprite, index, true)