HeavenStudioPlus/Assets/Scripts/Games/DrummingPractice/DrummingPractice.cs

149 lines
4.0 KiB
C#
Raw Normal View History

2022-03-07 03:17:46 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Starpelly;
using RhythmHeavenMania.Util;
2022-03-12 04:10:13 +00:00
namespace RhythmHeavenMania.Games
2022-03-07 03:17:46 +00:00
{
2022-03-12 04:10:13 +00:00
using Scripts_DrummingPractice;
2022-03-07 03:17:46 +00:00
public class DrummingPractice : Minigame
{
2022-03-07 05:26:59 +00:00
public enum MiiType
{
Random = -1,
2022-03-07 05:26:59 +00:00
GuestA,
GuestB,
GuestC,
GuestD,
GuestE,
GuestF,
Matt,
Tsunku,
Marshal
}
2022-03-07 03:17:46 +00:00
[Header("References")]
public SpriteRenderer backgroundGradient;
public Drummer player;
public Drummer leftDrummer;
public Drummer rightDrummer;
2022-03-07 05:00:54 +00:00
public GameObject hitPrefab;
2022-03-07 03:17:46 +00:00
2022-03-07 05:00:54 +00:00
public GameEvent bop = new GameEvent();
public int count = 0;
2022-03-07 03:17:46 +00:00
public static DrummingPractice instance;
private void Awake()
{
instance = this;
}
2022-03-07 05:00:54 +00:00
// TODO: Move this to OnGameSwitch() when functional?
private void Start()
{
2022-03-11 18:24:24 +00:00
SetMiis();
2022-03-07 05:00:54 +00:00
}
2022-03-07 03:17:46 +00:00
private void Update()
{
2022-03-07 05:00:54 +00:00
if (Conductor.instance.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1))
{
if (Conductor.instance.songPositionInBeats >= bop.startBeat && Conductor.instance.songPositionInBeats < bop.startBeat + bop.length)
{
Bop();
}
}
}
public void SetBop(float beat, float length)
{
bop.startBeat = beat;
bop.length = length;
}
public void Bop()
{
player.Bop();
leftDrummer.Bop();
rightDrummer.Bop();
}
public void Prepare(float beat, bool applause)
2022-03-07 05:00:54 +00:00
{
int type = count % 2;
player.Prepare(type);
leftDrummer.Prepare(type);
rightDrummer.Prepare(type);
count++;
SetFaces(0);
Jukebox.PlayOneShotGame("drummingPractice/prepare");
GameObject hit = Instantiate(hitPrefab);
hit.transform.parent = hitPrefab.transform.parent;
hit.SetActive(true);
DrummerHit h = hit.GetComponent<DrummerHit>();
h.startBeat = beat;
h.applause = applause;
2022-03-07 05:00:54 +00:00
}
public void SetFaces(int type)
{
player.SetFace(type);
leftDrummer.SetFace(type);
rightDrummer.SetFace(type);
2022-03-07 03:17:46 +00:00
}
2022-03-11 18:24:24 +00:00
public void SetMiis(int playerFace = (int) MiiType.Random, int leftFace = (int) MiiType.Random, int rightFace = (int) MiiType.Random, bool all = false)
2022-03-07 05:26:59 +00:00
{
2022-03-11 18:24:24 +00:00
if (playerFace == (int) MiiType.Random)
{
do
{
player.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
}
while (player.mii == leftFace || player.mii == rightFace);
}
else
player.mii = playerFace;
2022-03-07 05:26:59 +00:00
if (all && playerFace != -1)
2022-03-07 05:26:59 +00:00
{
leftDrummer.mii = playerFace;
rightDrummer.mii = playerFace;
}
else
{
2022-03-11 18:24:24 +00:00
if (leftFace == (int) MiiType.Random)
2022-03-07 05:26:59 +00:00
{
do
{
leftDrummer.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
}
while (leftDrummer.mii == player.mii);
2022-03-07 05:26:59 +00:00
}
else
leftDrummer.mii = leftFace;
2022-03-11 18:24:24 +00:00
if (rightFace == (int) MiiType.Random)
2022-03-07 05:26:59 +00:00
{
do
{
rightDrummer.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
}
while (rightDrummer.mii == leftDrummer.mii || rightDrummer.mii == player.mii);
2022-03-07 05:26:59 +00:00
}
else
rightDrummer.mii = rightFace;
2022-03-07 05:26:59 +00:00
}
SetFaces(0);
}
2022-03-07 03:17:46 +00:00
}
}