2022-03-04 20:47:40 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Games.MrUpbeat
|
|
|
|
{
|
|
|
|
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-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
|
|
|
|
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
metronome.transform.eulerAngles = new Vector3(0, 0, 270 - Mathf.Cos(Mathf.PI * Conductor.instance.songPositionInBeats) * 75);
|
|
|
|
}
|
|
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
if(applause)
|
|
|
|
Jukebox.PlayOneShotGame("mrUpbeat/applause");
|
|
|
|
else
|
|
|
|
Jukebox.PlayOneShotGame("mrUpbeat/ding");
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator Upbeat(float offset = 0)
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset);
|
|
|
|
man.Blip();
|
|
|
|
}
|
2022-03-04 20:47:40 +00:00
|
|
|
}
|
|
|
|
}
|