2022-03-04 20:47:40 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2022-03-12 01:54:05 +00:00
|
|
|
using System.Linq;
|
2022-03-04 20:47:40 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
2022-03-12 04:10:13 +00:00
|
|
|
namespace RhythmHeavenMania.Games
|
2022-03-04 20:47:40 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_MrUpbeat;
|
|
|
|
|
2022-03-04 20:47:40 +00:00
|
|
|
public class MrUpbeat : Minigame
|
|
|
|
{
|
|
|
|
[Header("References")]
|
|
|
|
public GameObject metronome;
|
2022-03-04 22:03:57 +00:00
|
|
|
public UpbeatMan man;
|
2022-03-06 19:37:50 +00:00
|
|
|
public GameObject bt;
|
2022-03-08 04:46:49 +00:00
|
|
|
private static MultiSound beeps; //only used when this game isn't active.
|
2022-03-04 22:03:57 +00:00
|
|
|
|
2022-03-05 03:10:10 +00:00
|
|
|
public GameEvent beat = new GameEvent();
|
2022-03-04 22:03:57 +00:00
|
|
|
public bool canGo = false;
|
2022-03-06 17:34:54 +00:00
|
|
|
public int beatCount = 0;
|
2022-03-04 20:47:40 +00:00
|
|
|
|
2022-03-12 01:54:05 +00:00
|
|
|
public float beatOffset = 0f;
|
|
|
|
|
2022-03-04 20:47:40 +00:00
|
|
|
public static MrUpbeat instance;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
2022-03-06 17:34:54 +00:00
|
|
|
private void Start()
|
2022-03-04 22:03:57 +00:00
|
|
|
{
|
2022-03-06 17:34:54 +00:00
|
|
|
canGo = false;
|
|
|
|
man.stepTimes = 0;
|
|
|
|
SetInterval(0);
|
2022-03-06 19:37:50 +00:00
|
|
|
var pos = Conductor.instance.songPositionInBeats;
|
|
|
|
StartCoroutine(Upbeat(pos - Mathf.Round(pos)));
|
2022-03-12 01:54:05 +00:00
|
|
|
|
|
|
|
List<float> gos = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel == "mrUpbeat/go").Select(c => c.beat).ToList();
|
|
|
|
|
|
|
|
if (gos.Count > 0)
|
|
|
|
{
|
|
|
|
var nextInterval = gos.IndexOf(Mathp.GetClosestInList(gos, Conductor.instance.songPositionInBeats));
|
|
|
|
beatOffset = gos[nextInterval];
|
|
|
|
}
|
2022-03-06 17:34:54 +00:00
|
|
|
}
|
2022-03-05 03:10:10 +00:00
|
|
|
|
2022-03-06 17:34:54 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-03-04 22:03:57 +00:00
|
|
|
List<Beatmap.Entity> gos = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel == "mrUpbeat/go");
|
2022-03-06 19:37:50 +00:00
|
|
|
for (int i = 0; i < gos.Count; i++)
|
2022-03-04 22:03:57 +00:00
|
|
|
{
|
|
|
|
if ((gos[i].beat - 0.15f) <= Conductor.instance.songPositionInBeats && (gos[i].beat + gos[i].length) - 0.15f > Conductor.instance.songPositionInBeats)
|
|
|
|
{
|
|
|
|
canGo = true;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
canGo = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 17:34:54 +00:00
|
|
|
if (canGo)
|
|
|
|
{
|
2022-03-12 01:54:05 +00:00
|
|
|
var songPos = Conductor.instance.songPositionInBeats - beatOffset;
|
|
|
|
metronome.transform.eulerAngles = new Vector3(0, 0, 270 - Mathf.Cos(Mathf.PI * songPos) * 75);
|
2022-03-06 17:34:54 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 19:37:50 +00:00
|
|
|
if (Conductor.instance.ReportBeat(ref beat.lastReportedBeat))
|
2022-03-05 03:10:10 +00:00
|
|
|
{
|
2022-03-06 19:37:50 +00:00
|
|
|
StartCoroutine(Upbeat());
|
|
|
|
if (canGo)
|
|
|
|
{
|
|
|
|
if (beatCount % 2 == 0)
|
|
|
|
Jukebox.PlayOneShotGame("mrUpbeat/metronomeRight");
|
|
|
|
else
|
|
|
|
Jukebox.PlayOneShotGame("mrUpbeat/metronomeLeft");
|
2022-03-05 03:10:10 +00:00
|
|
|
|
2022-03-06 19:37:50 +00:00
|
|
|
Beat(Mathf.Round(Conductor.instance.songPositionInBeats));
|
|
|
|
}
|
2022-03-05 03:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-08 04:46:49 +00:00
|
|
|
public override void OnGameSwitch(float beat)
|
|
|
|
{
|
|
|
|
foreach (Beatmap.Entity entity in GameManager.instance.Beatmap.entities)
|
|
|
|
{
|
|
|
|
if (entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine.
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entity.datamodel != "mrUpbeat/prepare" || entity.beat + entity.length < beat) //check for prepares that happen before the switch
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SetInterval(entity.beat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(beeps != null)
|
|
|
|
{
|
|
|
|
beeps.Delete(); //the beeps are only for when the game isn't active
|
|
|
|
beeps = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 22:03:57 +00:00
|
|
|
public void SetInterval(float beat)
|
|
|
|
{
|
2022-03-05 03:10:10 +00:00
|
|
|
beatCount = 0;
|
|
|
|
man.targetBeat = beat + 320f;
|
|
|
|
man.Idle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Go(float beat)
|
|
|
|
{
|
|
|
|
beatCount = 0;
|
2022-03-04 22:03:57 +00:00
|
|
|
}
|
2022-03-04 20:47:40 +00:00
|
|
|
|
2022-03-06 19:48:39 +00:00
|
|
|
public void Ding(bool applause)
|
|
|
|
{
|
2022-03-07 17:10:50 +00:00
|
|
|
Jukebox.PlayOneShotGame("mrUpbeat/ding");
|
|
|
|
if (applause)
|
|
|
|
Jukebox.PlayOneShot("applause");
|
2022-03-06 19:48:39 +00:00
|
|
|
}
|
2022-03-06 19:37:50 +00:00
|
|
|
|
|
|
|
public void Beat(float beat)
|
|
|
|
{
|
|
|
|
beatCount++;
|
|
|
|
|
|
|
|
GameObject _beat = Instantiate(bt);
|
|
|
|
_beat.transform.parent = bt.transform.parent;
|
|
|
|
_beat.SetActive(true);
|
|
|
|
UpbeatStep s = _beat.GetComponent<UpbeatStep>();
|
|
|
|
s.startBeat = beat;
|
2022-03-12 01:54:05 +00:00
|
|
|
s.beatOffset = beatOffset;
|
2022-03-06 19:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator Upbeat(float offset = 0)
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset);
|
|
|
|
man.Blip();
|
|
|
|
}
|
2022-03-08 04:46:49 +00:00
|
|
|
|
|
|
|
public static void Beep(float beat, float length)
|
|
|
|
{
|
|
|
|
if(GameManager.instance.currentGame == "mrUpbeat") //this function is only meant for making beeps while the game is inactive
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (beeps != null)
|
|
|
|
{
|
|
|
|
beeps.Delete();
|
|
|
|
}
|
|
|
|
MultiSound.Sound[] beepSounds = new MultiSound.Sound[Mathf.CeilToInt(length)];
|
|
|
|
for(int i = 0; i < beepSounds.Length; i++)
|
|
|
|
{
|
|
|
|
beepSounds[i] = new MultiSound.Sound("mrUpbeat/blip", beat + 0.5f + i);
|
|
|
|
}
|
|
|
|
beeps = MultiSound.Play(beepSounds, forcePlay:true);
|
|
|
|
}
|
2022-03-04 20:47:40 +00:00
|
|
|
}
|
|
|
|
}
|