217 lines
7.8 KiB
C#
217 lines
7.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Util;
|
|
using HeavenStudio.InputSystem;
|
|
|
|
using Jukebox;
|
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
{
|
|
using static Minigames;
|
|
public static class RvlBasketLoader
|
|
{
|
|
public static Minigame AddGame(EventCaller eventCaller)
|
|
{
|
|
return new Minigame("basketballGirls", "Basketball Girls", "ffffff", false, false, new List<GameAction>()
|
|
{
|
|
new("bop", "Bop")
|
|
{
|
|
function = delegate { var e = eventCaller.currentEntity; BasketballGirls.instance.ToggleBop(e.beat, e.length, e["toggle"], e["auto"]);},
|
|
resizable = true,
|
|
parameters = new()
|
|
{
|
|
new("toggle", true, "Bop"),
|
|
new("auto", false, "Bop (Auto)")
|
|
}
|
|
},
|
|
new GameAction("ball", "Ball")
|
|
{
|
|
function = delegate {var e = eventCaller.currentEntity; BasketballGirls.instance.SpawnBall(e.beat); },
|
|
defaultLength = 2f,
|
|
},
|
|
new GameAction("background appearance", "Background Appearance")
|
|
{
|
|
function = delegate {
|
|
var e = eventCaller.currentEntity;
|
|
BasketballGirls.instance.BackgroundColorSet(e.beat, e.length, e["colorBGStart"], e["colorBGEnd"], e["ease"]);
|
|
},
|
|
defaultLength = 0.5f,
|
|
resizable = true,
|
|
parameters = new List<Param>()
|
|
{
|
|
new Param("colorBGStart", new Color(1f, 0.937f, 0.224f), "Start BG Color", "Set the color at the start of the event."),
|
|
new Param("colorBGEnd", new Color(1f, 0.937f, 0.224f), "End BG Color", "Set the color at the end of the event."),
|
|
new Param("ease", Util.EasingFunction.Ease.Instant, "Ease", "Set the easing of the action."),
|
|
}
|
|
},
|
|
},
|
|
new List<string>() { "rvl", "normal" },
|
|
"rvlbasket", "en",
|
|
new List<string>() {},
|
|
chronologicalSortKey: 105
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace HeavenStudio.Games
|
|
{
|
|
using Scripts_BasketballGirls;
|
|
public class BasketballGirls : Minigame
|
|
{
|
|
public Transform baseBall;
|
|
public Animator girlLeftAnim, girlRightAnim;
|
|
[NonSerialized] public List<Interval> girlLeftNoBopIntervals = new(),
|
|
girlRightNoBopIntervals = new();
|
|
public Animator goalAnim;
|
|
|
|
[SerializeField] private SpriteRenderer BGPlane;
|
|
|
|
private ColorEase bgColorEase = new(new Color(1f, 0.937f, 0.224f));
|
|
|
|
public static BasketballGirls instance;
|
|
|
|
const int IAAltDownCat = IAMAXCAT;
|
|
|
|
protected static bool IA_BatonAltPress(out double dt)
|
|
{
|
|
return PlayerInput.GetSqueezeDown(out dt);
|
|
}
|
|
|
|
public static PlayerInput.InputAction InputAction_Catch =
|
|
new("RvlBasketCatch", new int[] { IAPressCat, IAPressCat, IAAltDownCat },
|
|
IA_PadBasicPress, IA_TouchBasicPress, IA_BatonAltPress);
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
SetupBopRegion("basketballGirls", "bop", "auto");
|
|
HandleBops();
|
|
}
|
|
|
|
public override void OnLateBeatPulse(double beat)
|
|
{
|
|
if (BeatIsInBopRegion(beat)) { Bop(beat);}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var cond = Conductor.instance;
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
{
|
|
if (PlayerInput.GetIsAction(InputAction_Catch) && !IsExpectingInputNow(InputAction_Catch))
|
|
{
|
|
if (!girlRightAnim.IsPlayingAnimationNames("blank") && !girlRightNoBopIntervals.Any(x => x.Contains(cond.songPositionInBeatsAsDouble)))
|
|
{
|
|
SoundByte.PlayOneShotGame("basketballGirls/A");
|
|
girlRightAnim.DoScaledAnimationAsync("blank", 0.5f);
|
|
}
|
|
}
|
|
|
|
UpdateBackgroundColor();
|
|
}
|
|
}
|
|
|
|
private void HandleBops()
|
|
{
|
|
List<RiqEntity> events = EventCaller.GetAllInGameManagerList("basketballGirls", new string[] { "ball" });
|
|
|
|
foreach (var e in events)
|
|
{
|
|
girlLeftNoBopIntervals.Add(new Interval(e.beat, e.beat + 2));
|
|
}
|
|
}
|
|
public void ToggleBop(double beat, float length, bool bopOrNah, bool autoBop)
|
|
{
|
|
if (bopOrNah)
|
|
{
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
var currentBeat = beat + i;
|
|
BeatAction.New(instance, new List<BeatAction.Action>()
|
|
{
|
|
new BeatAction.Action(currentBeat, delegate { Bop(currentBeat);})
|
|
});
|
|
}
|
|
}
|
|
}
|
|
private void Bop(double beat)
|
|
{
|
|
if (!girlLeftNoBopIntervals.Any(x => x.Contains(beat)))
|
|
{
|
|
MultiSound.Play(
|
|
new MultiSound.Sound[] {
|
|
new MultiSound.Sound("basketballGirls/dribble" + UnityEngine.Random.Range(1,3).ToString(), beat),
|
|
new MultiSound.Sound("basketballGirls/dribbleEcho" + UnityEngine.Random.Range(1,4).ToString(), beat + 0.5),
|
|
}
|
|
);
|
|
girlLeftAnim.DoScaledAnimationAsync("dribble", 0.5f);
|
|
}
|
|
if (!girlRightNoBopIntervals.Any(x => x.Contains(beat)))
|
|
{
|
|
girlRightAnim.DoScaledAnimationAsync("bop", 0.5f);
|
|
}
|
|
}
|
|
|
|
public void SpawnBall(double beat)
|
|
{
|
|
var newBall = Instantiate(baseBall, transform).GetComponent<Ball>();
|
|
newBall.startBeat = beat;
|
|
|
|
SoundByte.PlayOneShotGame("basketballGirls/voice");
|
|
girlLeftAnim.DoScaledAnimationAsync("prepare", 0.5f);
|
|
BeatAction.New(instance, new List<BeatAction.Action>()
|
|
{
|
|
new BeatAction.Action(beat, delegate {
|
|
newBall.gameObject.SetActive(true);
|
|
newBall.Init();
|
|
}),
|
|
new BeatAction.Action(beat+2, delegate {
|
|
}),
|
|
});
|
|
}
|
|
|
|
public void BackgroundColorSet(double beat, float length, Color BGStart, Color BGEnd, int colorEaseSet)
|
|
{
|
|
bgColorEase = new(beat, length, BGStart, BGEnd, colorEaseSet);
|
|
|
|
UpdateBackgroundColor();
|
|
}
|
|
private void UpdateBackgroundColor()
|
|
{
|
|
BGPlane.color = bgColorEase.GetColor();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// How should Bop's on/off be managed?
|
|
namespace HeavenStudio.Games.Scripts_BasketballGirls
|
|
{
|
|
public class Interval
|
|
{
|
|
private readonly double _start;
|
|
private readonly double _end;
|
|
private readonly Func<double, double, bool> _leftComparer;
|
|
private readonly Func<double, double, bool> _rightComparer;
|
|
|
|
public double Start => _start;
|
|
public double End => _end;
|
|
|
|
public Interval(double start, double end, bool isLeftClosed = true, bool isRightClosed = false)
|
|
{
|
|
_start = start;
|
|
_end = end;
|
|
|
|
_leftComparer = isLeftClosed ? (value, boundary) => value >= boundary : (value, boundary) => value > boundary;
|
|
_rightComparer = isRightClosed ? (value, boundary) => value <= boundary : (value, boundary) => value < boundary;
|
|
}
|
|
|
|
public bool Contains(double value) => _leftComparer(value, _start) && _rightComparer(value, _end);
|
|
}
|
|
}
|