diff --git a/godot/control_scheme/controller.gd b/godot/control_scheme/controller.gd index 2a3ac78..834e4f0 100644 --- a/godot/control_scheme/controller.gd +++ b/godot/control_scheme/controller.gd @@ -13,12 +13,14 @@ var time_targets := Dictionary() func _ready(): set_target(initial_target, false) + time_targets[0] = target camera.set_as_top_level(true) ControllerEventBus.billiard_touched_billiard.connect(_on_billiard_touched_billiard) TAS_System.FrameIncremented.connect(frame_inc) TAS_System.FramesAdvanced.connect(frames_change) TAS_System.FramesRegressed.connect(frames_change) + TAS_System.FramesReset.connect(frames_reset) func frame_inc(frame: int): time_targets[frame] = target @@ -27,6 +29,10 @@ func frames_change(start: int, end: int): if time_targets[end] != target: set_target(time_targets[end].get_billiard()) +func frames_reset(): + time_targets = Dictionary() + time_targets[0] = target + func _on_billiard_touched_billiard(who: Billiard, touched: Billiard): diff --git a/godot/physics/billiard.gd b/godot/physics/billiard.gd index 69e7a69..83f53c9 100644 --- a/godot/physics/billiard.gd +++ b/godot/physics/billiard.gd @@ -5,6 +5,27 @@ class_name Billiard @export var power_max := 5.0 var can_hit = true +var can_hit_history := Dictionary() + +func _ready(): + can_hit_history[0] = can_hit + + TAS_System.FrameIncremented.connect(frame_inc) + TAS_System.FramesAdvanced.connect(frames_change) + TAS_System.FramesRegressed.connect(frames_change) + TAS_System.FramesReset.connect(frames_reset) + +func frame_inc(frame: int): + can_hit_history[frame] = can_hit + +func frames_change(start: int, end: int): + can_hit = can_hit_history[end] + +func frames_reset(): + can_hit_history = Dictionary() + can_hit_history[0] = can_hit + + func hit(impulse: Vector3, power: float): apply_central_impulse(impulse * lerp(power_min, power_max, power))