reached a point where it's functional
This commit is contained in:
parent
bc9fae7e2a
commit
582fb8da83
File diff suppressed because it is too large
Load diff
|
@ -12,8 +12,12 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
|
|||
[System.NonSerialized] public double startBeat, lengthBeat;
|
||||
private double currentBeat;
|
||||
|
||||
[System.NonSerialized] public BezierCurve3D[] curve;
|
||||
private BezierCurve3D currentCurve;
|
||||
|
||||
public Color color;
|
||||
[System.NonSerialized] public bool goal;
|
||||
|
||||
private BouncyRoad game;
|
||||
|
||||
public void Init()
|
||||
|
@ -21,6 +25,7 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
|
|||
game = BouncyRoad.instance;
|
||||
|
||||
currentBeat = startBeat;
|
||||
GetComponent<SpriteRenderer>().color = color;
|
||||
Bounce();
|
||||
}
|
||||
void Update()
|
||||
|
@ -41,25 +46,82 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
|
|||
{
|
||||
sounds.Add(new MultiSound.Sound("bouncyRoad/ballBounce", startBeat + i * lengthBeat));
|
||||
}
|
||||
sounds.Add(new MultiSound.Sound("bouncyRoad/ballRight", startBeat + 12 * lengthBeat));
|
||||
sounds.Add(new MultiSound.Sound("bouncyRoad/ballLeft", startBeat + 13 * lengthBeat));
|
||||
sounds.Add(new MultiSound.Sound("bouncyRoad/goal", startBeat + 14 * lengthBeat));
|
||||
MultiSound.Play(sounds.ToArray());
|
||||
|
||||
var actions = new List<BeatAction.Action>();
|
||||
for (int i = 0; i < 15 ; i++)
|
||||
for (int i = 0; i < 12 ; i++)
|
||||
{
|
||||
int currentItr = i;
|
||||
actions.Add(new BeatAction.Action(startBeat + currentItr * lengthBeat, delegate {
|
||||
game.ThingsAnim[currentItr].Play("podium", 0, 0);
|
||||
currentCurve = game.curve[currentItr];
|
||||
currentCurve = curve[currentItr];
|
||||
currentBeat = startBeat + currentItr * lengthBeat;
|
||||
}));
|
||||
}
|
||||
actions.Add(new BeatAction.Action(startBeat + 15 * lengthBeat, delegate {
|
||||
Destroy(gameObject);
|
||||
}));
|
||||
BeatAction.New(game, actions);
|
||||
|
||||
game.ScheduleInput(startBeat + 11 * lengthBeat, lengthBeat, BouncyRoad.InputAction_Right, RightSuccess, RightMiss, Empty);
|
||||
}
|
||||
|
||||
public void RightSuccess(PlayerActionEvent caller, float state)
|
||||
{
|
||||
SoundByte.PlayOneShotGame("bouncyRoad/ballRight");
|
||||
game.ThingsAnim[12].Play("podium", 0, 0);
|
||||
currentCurve = curve[12];
|
||||
currentBeat = startBeat + 12 * lengthBeat;
|
||||
|
||||
game.ScheduleInput(startBeat + 12 * lengthBeat, lengthBeat, BouncyRoad.InputAction_Left, LeftSuccess, LeftMiss, Empty);
|
||||
}
|
||||
|
||||
public void RightMiss(PlayerActionEvent caller)
|
||||
{
|
||||
SoundByte.PlayOneShotGame("bouncyRoad/ballBounce");
|
||||
currentBeat = Conductor.instance.songPositionInBeats;
|
||||
BeatAction.New(game, new List<BeatAction.Action>()
|
||||
{
|
||||
new BeatAction.Action(startBeat + 13 * lengthBeat, delegate
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
public void LeftSuccess(PlayerActionEvent caller, float state)
|
||||
{
|
||||
SoundByte.PlayOneShotGame("bouncyRoad/ballLeft");
|
||||
game.ThingsAnim[13].Play("podium", 0, 0);
|
||||
currentCurve = curve[13];
|
||||
currentBeat = startBeat + 13 * lengthBeat;
|
||||
|
||||
if (goal) SoundByte.PlayOneShotGame("bouncyRoad/goal", startBeat + 14 * lengthBeat);
|
||||
BeatAction.New(game, new List<BeatAction.Action>()
|
||||
{
|
||||
new BeatAction.Action(startBeat + 14 * lengthBeat, delegate
|
||||
{
|
||||
game.ThingsAnim[14].Play("podium", 0, 0);
|
||||
currentCurve = curve[14];
|
||||
currentBeat = startBeat + 14 * lengthBeat;
|
||||
}),
|
||||
new BeatAction.Action(startBeat + 15 * lengthBeat, delegate
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
public void LeftMiss(PlayerActionEvent caller)
|
||||
{
|
||||
SoundByte.PlayOneShotGame("bouncyRoad/ballBounce");
|
||||
currentBeat = Conductor.instance.songPositionInBeats;
|
||||
BeatAction.New(game, new List<BeatAction.Action>()
|
||||
{
|
||||
new BeatAction.Action(startBeat + 14 * lengthBeat, delegate
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
public void Empty(PlayerActionEvent caller) { }
|
||||
}
|
||||
}
|
|
@ -22,9 +22,14 @@ namespace HeavenStudio.Games.Loaders
|
|||
{
|
||||
new GameAction("ball", "Ball")
|
||||
{
|
||||
function = delegate { var e = eventCaller.currentEntity; BouncyRoad.instance.SpawnBall(e.beat, e.length); },
|
||||
function = delegate { var e = eventCaller.currentEntity; BouncyRoad.instance.SpawnBall(e.beat, e.length, e["goal"], e["color"]); },
|
||||
defaultLength = 1f,
|
||||
resizable = true,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("goal", true, "Play Goal Sound"),
|
||||
new Param("color", Color.white, "Color", "Choose the color of the ball."),
|
||||
}
|
||||
},
|
||||
},
|
||||
new List<string>() { "agb", "normal" },
|
||||
|
@ -43,10 +48,11 @@ namespace HeavenStudio.Games
|
|||
{
|
||||
[SerializeField] GameObject baseBall;
|
||||
[SerializeField] GameObject baseBounceCurve;
|
||||
[SerializeField] Transform CurveHolder;
|
||||
|
||||
[SerializeField] Transform ThingsTrans;
|
||||
[System.NonSerialized] public Animator[] ThingsAnim;
|
||||
[System.NonSerialized] public BezierCurve3D[] curve;
|
||||
[System.NonSerialized] public Dictionary<float, BezierCurve3D[]> CurveCache;
|
||||
[SerializeField] BezierCurve3D PosCurve;
|
||||
|
||||
public static BouncyRoad instance;
|
||||
|
@ -96,24 +102,35 @@ namespace HeavenStudio.Games
|
|||
ThingsAnim[childIndex++] = child.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
curve = new BezierCurve3D[ThingsTrans.childCount];
|
||||
for (var i = 0; i < ThingsAnim.Length; ++i)
|
||||
var newCurves = new BezierCurve3D[ThingsTrans.childCount];
|
||||
// for (var i = 0; i < ThingsAnim.Length; ++i)
|
||||
// {
|
||||
// var prog1 = (float)i/(ThingsTrans.childCount-1);
|
||||
// var prog2 = (float)(i+1)/(ThingsTrans.childCount-1);
|
||||
// var pos1 = PosCurve.GetPoint(prog1);
|
||||
// var pos2 = PosCurve.GetPoint(prog2);
|
||||
|
||||
// var newCurve = GenerateInitCurve(pos1, pos2);
|
||||
|
||||
// newCurves[i] = newCurve.GetComponent<BezierCurve3D>();
|
||||
// }
|
||||
{
|
||||
var prog1 = (float)i/(ThingsTrans.childCount-1);
|
||||
var prog2 = (float)(i+1)/(ThingsTrans.childCount-1);
|
||||
var pos1 = PosCurve.GetPoint(prog1);
|
||||
var pos2 = PosCurve.GetPoint(prog2);
|
||||
float angle = Mathf.Atan2(pos1.z - pos2.z, pos1.x - pos2.x) * Mathf.Rad2Deg;
|
||||
for (var i = 0; i < ThingsAnim.Length-1; ++i)
|
||||
{
|
||||
var pos1 = ThingsTrans.GetChild(i).transform.localPosition;
|
||||
var pos2 = ThingsTrans.GetChild(i+1).transform.localPosition;
|
||||
|
||||
var newCurve = Instantiate(baseBounceCurve, transform).transform;
|
||||
var newCurve = GenerateInitCurve(pos1, pos2);
|
||||
|
||||
newCurve.GetChild(0).transform.localPosition = pos1;
|
||||
newCurve.GetChild(0).transform.localEulerAngles = new Vector3(0, -angle, 0);
|
||||
newCurve.GetChild(1).transform.localPosition = pos2;
|
||||
newCurve.GetChild(1).transform.localEulerAngles = new Vector3(0, -angle, 0);
|
||||
|
||||
curve[i] = newCurve.GetComponent<BezierCurve3D>();
|
||||
newCurves[i] = newCurve.GetComponent<BezierCurve3D>();
|
||||
}
|
||||
var posA = PosCurve.GetPoint(1);
|
||||
var posB = PosCurve.GetPoint((float)(ThingsAnim.Length)/(ThingsAnim.Length-1));
|
||||
|
||||
newCurves[ThingsAnim.Length-1] = GenerateInitCurve(posA, posB).GetComponent<BezierCurve3D>();
|
||||
}
|
||||
CurveCache = new Dictionary<float, BezierCurve3D[]>();
|
||||
CurveCache.Add(1, newCurves);
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
@ -131,13 +148,16 @@ namespace HeavenStudio.Games
|
|||
}
|
||||
}
|
||||
|
||||
public void SpawnBall(double beat, double length)
|
||||
public void SpawnBall(double beat, double length, bool goal, Color color)
|
||||
{
|
||||
|
||||
var newBall = Instantiate(baseBall, transform).GetComponent<Ball>();
|
||||
|
||||
newBall.startBeat = beat;
|
||||
newBall.lengthBeat = length;
|
||||
newBall.goal = goal;
|
||||
newBall.color = color;
|
||||
|
||||
newBall.curve = GetHeightCurve((float)length);
|
||||
|
||||
BeatAction.New(instance, new List<BeatAction.Action>()
|
||||
{
|
||||
|
@ -147,8 +167,55 @@ namespace HeavenStudio.Games
|
|||
newBall.gameObject.SetActive(true);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
private Transform GenerateInitCurve(Vector3 pos1, Vector3 pos2)
|
||||
{
|
||||
float dist = Vector3.Distance(pos1, pos2);
|
||||
float angle = Mathf.Atan2(pos1.z - pos2.z, pos1.x - pos2.x) * Mathf.Rad2Deg;
|
||||
|
||||
var newCurve = Instantiate(baseBounceCurve, CurveHolder).transform;
|
||||
|
||||
var point0 = newCurve.GetChild(0);
|
||||
var point1 = newCurve.GetChild(1);
|
||||
|
||||
point0.transform.localPosition = pos1;
|
||||
point0.transform.localEulerAngles = new Vector3(0, -angle, 0);
|
||||
point0.transform.localScale = new Vector3(dist, 1, 1);
|
||||
point1.transform.localPosition = pos2;
|
||||
point1.transform.localEulerAngles = new Vector3(0, -angle, 0);
|
||||
point1.transform.localScale = new Vector3(dist, 1, 1);
|
||||
|
||||
return newCurve;
|
||||
}
|
||||
|
||||
private BezierCurve3D[] GetHeightCurve(float length)
|
||||
{
|
||||
BezierCurve3D[] newCurves;
|
||||
CurveCache.TryGetValue(length, out newCurves);
|
||||
|
||||
if (newCurves is null)
|
||||
{
|
||||
var newCurveHolder = Instantiate(CurveHolder, transform);
|
||||
newCurveHolder.name = $"CurveHolder_{length}";
|
||||
var newCurvesTrans = newCurveHolder.transform;
|
||||
|
||||
newCurves = new BezierCurve3D[newCurvesTrans.childCount];
|
||||
int childIndex = 0;
|
||||
foreach (Transform child in newCurvesTrans)
|
||||
{
|
||||
var point0 = child.GetChild(0);
|
||||
var point1 = child.GetChild(1);
|
||||
|
||||
Vector3 scale = point0.transform.localScale;
|
||||
point0.transform.localScale = new Vector3(scale.x, length, scale.z);
|
||||
point1.transform.localScale = new Vector3(scale.x, length, scale.z);
|
||||
newCurves[childIndex++] = child.GetComponent<BezierCurve3D>();
|
||||
}
|
||||
CurveCache.Add(length, newCurves);
|
||||
}
|
||||
|
||||
return newCurves;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue