|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
using System.Linq; |
|
|
|
|
using UnityEngine; |
|
|
|
|
using UnityEngine.UIElements; |
|
|
|
|
|
|
|
|
|
namespace Game { |
|
|
|
|
|
|
|
|
@ -10,6 +11,8 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
private bool isApproaching; |
|
|
|
|
private float lastDirection; |
|
|
|
|
private bool lastGoingLeft, lastGoingRight; |
|
|
|
|
private Label leftButton, rightButton; |
|
|
|
|
|
|
|
|
|
public Difficulty Difficulty { get; set; } |
|
|
|
|
|
|
|
|
@ -19,25 +22,51 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
private float DistortAmount => 1 - 1 / ((float) Difficulty + 1); |
|
|
|
|
|
|
|
|
|
protected new void Start() { |
|
|
|
|
base.Start(); |
|
|
|
|
leftButton = GameUI.Singleton.GetGoButton(Side, "left"); |
|
|
|
|
rightButton = GameUI.Singleton.GetGoButton(Side, "right"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void FixedUpdate() { |
|
|
|
|
var dt = Time.fixedDeltaTime; |
|
|
|
|
var target = GetTargetPosition(); |
|
|
|
|
var h = Mathf.Max(Speed * dt, Width / 2); |
|
|
|
|
goingLeft = target < X - h; |
|
|
|
|
goingRight = target > X + h; |
|
|
|
|
if (goingLeft || goingRight) { |
|
|
|
|
goingLeftLinear = target < X - h; |
|
|
|
|
goingRightLinear = target > X + h; |
|
|
|
|
if (goingLeftLinear || goingRightLinear) { |
|
|
|
|
isApproaching = false; |
|
|
|
|
lastDirection = goingLeft ? -1 : 1; |
|
|
|
|
lastDirection = goingLeftLinear ? -1 : 1; |
|
|
|
|
TryLinearMove(dt); |
|
|
|
|
} else { |
|
|
|
|
if (!isApproaching) { |
|
|
|
|
isApproaching = true; |
|
|
|
|
currentSmoothV = Speed * lastDirection; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ApproachPosition(target); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool goingLeft = isApproaching ? currentSmoothV < 0 : goingLeftLinear; |
|
|
|
|
bool goingRight = isApproaching ? currentSmoothV > 0 : goingRightLinear; |
|
|
|
|
switch (lastGoingLeft) { |
|
|
|
|
case false when goingLeft: |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case true when !goingLeft: |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
switch (lastGoingRight) { |
|
|
|
|
case false when goingRight: |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case true when !goingRight: |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lastGoingLeft = goingLeft; |
|
|
|
|
lastGoingRight = goingRight; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// True if ball y velocity points towards player |
|
|
|
|