Merge branch 'master' of https://github.com/megaminerjenny/HeavenStudio into megaminerjenny-master

This commit is contained in:
Slaith
2022-03-07 20:53:30 -08:00
177 changed files with 15561 additions and 3728 deletions

View File

@ -62,7 +62,7 @@ namespace RhythmHeavenMania
sp.color = Color.black;
sp.sprite = Resources.Load<Sprite>("Sprites/GeneralPurpose/Square");
sp.sortingOrder = 30000;
this.gameObject.layer = 3;
gameObject.layer = LayerMask.NameToLayer("Flash");
GameObject fade = new GameObject();
this.fade = fade.AddComponent<Games.Global.Flash>();
@ -227,12 +227,13 @@ namespace RhythmHeavenMania
SetCurrentEventToClosest(beat);
}
for (int i = 0; i < SoundObjects.Count; i++) Destroy(SoundObjects[i].gameObject);
KillAllSounds();
}
public void Pause()
{
Conductor.instance.Pause();
KillAllSounds();
}
public void Stop(float beat)
@ -240,6 +241,15 @@ namespace RhythmHeavenMania
Conductor.instance.Stop(beat);
SetCurrentEventToClosest(beat);
onBeatChanged?.Invoke(beat);
KillAllSounds();
}
public void KillAllSounds()
{
for (int i = 0; i < SoundObjects.Count; i++)
Destroy(SoundObjects[i].gameObject);
SoundObjects.Clear();
}
#endregion

View File

@ -184,5 +184,16 @@ namespace RhythmHeavenMania.Games.BuiltToScaleDS
shooterAnim.Play("Shoot", 0, 0);
elevatorAnim.Play("MakeRod", 0, 0);
}
public void PlayPiano(float beat, float length, int semiTones)
{
var pianoPitch = Mathf.Pow(2f, (1f / 12f) * semiTones) *Conductor.instance.musicSource.pitch;
var pianoSource = Jukebox.PlayOneShotGame("builtToScaleDS/Piano", -1, pianoPitch, 0.8f, true);
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(beat + length, delegate { Jukebox.KillLoop(pianoSource, 0.1f); })
});
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 39009c40d5d76d24e8f1afa560d30ea8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,88 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Starpelly;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.DrummingPractice
{
public class Drummer : MonoBehaviour
{
[Header("References")]
public Animator animator;
public List<MiiFace> miiFaces;
public SpriteRenderer face;
public bool player = false;
public int mii = 0;
public int count = 0;
private bool hitting = false;
[System.Serializable]
public class MiiFace
{
public List<Sprite> Sprites;
}
private void Update()
{
if (player && PlayerInput.Pressed())
{
Hit(false);
}
}
public void SetFace(int type)
{
face.sprite = miiFaces[mii].Sprites[type];
}
public void Bop()
{
if (animator.IsAnimationNotPlaying())
animator.Play("Bop", 0, 0);
}
public void Prepare(int type)
{
count = type;
if (count % 2 == 0)
animator.Play("PrepareLeft", 0, 0);
else
animator.Play("PrepareRight", 0, 0);
}
public void Hit(bool hit)
{
if (!hitting)
{
if (count % 2 == 0)
animator.Play("HitLeft", 0, 0);
else
animator.Play("HitRight", 0, 0);
count++;
if (player)
{
if (hit)
Jukebox.PlayOneShotGame("drummingPractice/hit");
else
Jukebox.PlayOneShotGame("drummingPractice/miss");
}
hitting = true;
}
}
public void EndHit()
{
hitting = false;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 78423096340cc9740b0a87870976098f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.DrummingPractice
{
public class DrummerHit : PlayerActionObject
{
public float startBeat;
private bool hit = false;
private bool hasHit = false;
// Start is called before the first frame update
void Start()
{
PlayerActionInit(gameObject, startBeat);
}
public override void OnAce()
{
Hit(true);
}
// Update is called once per frame
void Update()
{
if (Conductor.instance.GetPositionFromBeat(startBeat, 2) >= 1)
{
DrummingPractice.instance.SetFaces(0);
CleanUp();
}
if (!hit && Conductor.instance.GetPositionFromBeat(startBeat, 1) >= 1)
{
Jukebox.PlayOneShotGame("drummingPractice/drum");
DrummingPractice.instance.leftDrummer.Hit(true);
DrummingPractice.instance.rightDrummer.Hit(true);
hit = true;
if (hasHit) CleanUp();
}
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, 1f);
StateCheck(normalizedBeat);
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Hit(true);
} else if (state.notPerfect())
{
Hit(false);
}
}
}
public void Hit(bool _hit)
{
if (!hasHit)
{
DrummingPractice.instance.player.Hit(_hit);
DrummingPractice.instance.SetFaces(_hit ? 1 : 2);
hasHit = true;
if (hit) CleanUp();
}
}
public void CleanUp()
{
Destroy(gameObject);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a4698fb27db1ad4995391c5b6cd1ddb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,125 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Starpelly;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.DrummingPractice
{
public class DrummingPractice : Minigame
{
public enum MiiType
{
GuestA,
GuestB,
GuestC,
GuestD,
GuestE,
GuestF,
Matt,
Tsunku,
Marshal
}
[Header("References")]
public SpriteRenderer backgroundGradient;
public Drummer player;
public Drummer leftDrummer;
public Drummer rightDrummer;
public GameObject hitPrefab;
public GameEvent bop = new GameEvent();
public int count = 0;
public static DrummingPractice instance;
private void Awake()
{
instance = this;
}
// TODO: Move this to OnGameSwitch() when functional?
private void Start()
{
SetMiis(UnityEngine.Random.Range(0, player.miiFaces.Count));
}
private void Update()
{
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)
{
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;
}
public void SetFaces(int type)
{
player.SetFace(type);
leftDrummer.SetFace(type);
rightDrummer.SetFace(type);
}
public void SetMiis(int playerFace, bool all = false)
{
player.mii = playerFace;
if (all)
{
leftDrummer.mii = playerFace;
rightDrummer.mii = playerFace;
}
else
{
do
{
leftDrummer.mii = UnityEngine.Random.Range(0, leftDrummer.miiFaces.Count);
}
while (leftDrummer.mii == player.mii);
do
{
rightDrummer.mii = UnityEngine.Random.Range(0, rightDrummer.miiFaces.Count);
}
while (rightDrummer.mii == leftDrummer.mii || rightDrummer.mii == player.mii);
}
SetFaces(0);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c7db5828bf6ab644c92395762a28c7a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -27,7 +27,7 @@ namespace RhythmHeavenMania.Games.Global
private void Start()
{
this.gameObject.transform.SetParent(GameManager.instance.gameObject.transform);
this.gameObject.layer = 3;
gameObject.layer = LayerMask.NameToLayer("Flash");
this.gameObject.transform.localScale = new Vector3(1, 1);
spriteRenderer = this.gameObject.AddComponent<SpriteRenderer>();

View File

@ -18,6 +18,7 @@ using RhythmHeavenMania.Games.TapTrial;
using RhythmHeavenMania.Games.CropStomp;
using RhythmHeavenMania.Games.WizardsWaltz;
using RhythmHeavenMania.Games.MrUpbeat;
using RhythmHeavenMania.Games.DrummingPractice;
namespace RhythmHeavenMania
{
@ -369,9 +370,13 @@ namespace RhythmHeavenMania
new Param("type2", RotateMode.Fast, "Rotation Mode", "The rotation mode to use")
} ),
}),
new Minigame("builtToScaleDS", "Built To Scale (DS) \n<color=#eb5454>[WIP don't use]</color>", "00BB00", true, false, new List<GameAction>()
new Minigame("builtToScaleDS", "Built To Scale (DS)", "00BB00", true, false, new List<GameAction>()
{
new GameAction("spawn blocks", delegate { }, 1f, true)
new GameAction("spawn blocks", delegate { }, 1f, true),
new GameAction("play piano", delegate { BuiltToScaleDS.instance.PlayPiano(eventCaller.currentEntity.beat, eventCaller.currentEntity.length, eventCaller.currentEntity.type); }, 1f, true, new List<Param>()
{
new Param("type", new EntityTypes.Integer(-24, 24, 0), "Semitones", "The number of semitones up or down this note should be pitched")
} ),
}),
new Minigame("tapTrial", "Tap Trial \n<color=#eb5454>[WIP don't use]</color>", "93ffb3", false, false, new List<GameAction>()
{
@ -401,6 +406,17 @@ namespace RhythmHeavenMania
new Param("toggle", false, "Applause")
}),
}),
new Minigame("drummingPractice", "Drumming Practice", "2BCF33", false, false, new List<GameAction>()
{
new GameAction("bop", delegate { var e = eventCaller.currentEntity; DrummingPractice.instance.SetBop(e.beat, e.length); }, 0.5f, true),
new GameAction("drum", delegate { DrummingPractice.instance.Prepare(eventCaller.currentEntity.beat); }, 2f),
new GameAction("set mii", delegate { var e = eventCaller.currentEntity; DrummingPractice.instance.SetMiis(e.type, e.toggle); }, 0.5f, parameters: new List<Param>()
{
new Param("type", DrummingPractice.MiiType.GuestA, "Mii", "The Mii that the player will control"),
new Param("toggle", false, "Set All", "Whether all Miis should be set")
}),
}),
/*new Minigame("spaceDance", "Space Dance", "B888F8", new List<GameAction>()
{
}),

View File

@ -40,7 +40,7 @@ namespace RhythmHeavenMania.Util
FindJukebox().GetComponent<AudioSource>().volume = volume;
}
public static AudioSource PlayOneShot(string name, float beat = -1)
public static AudioSource PlayOneShot(string name, float beat = -1, float pitch = 1f, float volume = 1f, bool looping = false)
{
GameObject oneShot = new GameObject("oneShot");
@ -52,6 +52,9 @@ namespace RhythmHeavenMania.Util
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
snd.clip = clip;
snd.beat = beat;
snd.pitch = pitch;
snd.volume = volume;
snd.looping = looping;
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
GameManager.instance.SoundObjects.Add(oneShot);
@ -59,7 +62,7 @@ namespace RhythmHeavenMania.Util
return audioSource;
}
public static AudioSource PlayOneShotScheduled(string name, double targetTime)
public static AudioSource PlayOneShotScheduled(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false)
{
GameObject oneShot = new GameObject("oneShotScheduled");
@ -71,6 +74,9 @@ namespace RhythmHeavenMania.Util
var clip = Resources.Load<AudioClip>($"Sfx/{name}");
audioSource.clip = clip;
snd.clip = clip;
snd.pitch = pitch;
snd.volume = volume;
snd.looping = looping;
snd.scheduled = true;
snd.scheduledTime = targetTime;
@ -81,25 +87,34 @@ namespace RhythmHeavenMania.Util
return audioSource;
}
public static AudioSource PlayOneShotGame(string name, float beat = -1, bool forcePlay = false)
public static AudioSource PlayOneShotGame(string name, float beat = -1, bool forcePlay = false , float pitch = 1f, float volume = 1f, bool looping = false)
{
if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay)
{
return PlayOneShot($"games/{name}", beat);
return PlayOneShot($"games/{name}", beat, pitch, volume, looping);
}
return null;
}
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, bool forcePlay = false)
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, bool forcePlay = false, float pitch = 1f, float volume = 1f, bool looping = false)
{
if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay)
{
return PlayOneShotScheduled($"games/{name}", targetTime);
return PlayOneShotScheduled($"games/{name}", targetTime, pitch, volume, looping);
}
return null;
}
public static void KillLoop(AudioSource source, float fadeTime)
{
// Safeguard against previously-destroyed sounds.
if (source == null)
return;
source.GetComponent<Sound>().KillLoop(fadeTime);
}
}
}

View File

@ -8,11 +8,14 @@ namespace RhythmHeavenMania.Util
{
public AudioClip clip;
public float pitch = 1;
public float volume = 1;
// For use with PlayOneShotScheduled
public bool scheduled;
public double scheduledTime;
public bool looping;
private AudioSource audioSource;
private int pauseTimes = 0;
@ -29,6 +32,8 @@ namespace RhythmHeavenMania.Util
audioSource = GetComponent<AudioSource>();
audioSource.clip = clip;
audioSource.pitch = pitch;
audioSource.volume = volume;
audioSource.loop = looping;
if (beat == -1 && !scheduled)
{
@ -43,34 +48,40 @@ namespace RhythmHeavenMania.Util
startTime = Conductor.instance.songPosition;
if (!scheduled)
if (!scheduled && !looping)
StartCoroutine(NotRelyOnBeatSound());
}
private void Update()
{
if (scheduled)
if (playIndex < 1)
{
if (AudioSettings.dspTime > scheduledTime && playIndex < 1)
if (scheduled)
{
StartCoroutine(NotRelyOnBeatSound());
playIndex++;
if (AudioSettings.dspTime > scheduledTime)
{
StartCoroutine(NotRelyOnBeatSound());
playIndex++;
}
}
}
else if (!playInstant)
{
if (Conductor.instance.songPositionInBeats > beat && playIndex < 1)
else if (!playInstant)
{
audioSource.PlayScheduled(Time.time);
playIndex++;
if (Conductor.instance.songPositionInBeats > beat)
{
audioSource.PlayScheduled(Time.time);
playIndex++;
}
}
}
}
IEnumerator NotRelyOnBeatSound()
{
yield return new WaitForSeconds(clip.length);
Delete();
if (!looping) // Looping sounds are destroyed manually.
{
yield return new WaitForSeconds(clip.length);
Delete();
}
}
public void Delete()
@ -78,5 +89,25 @@ namespace RhythmHeavenMania.Util
GameManager.instance.SoundObjects.Remove(gameObject);
Destroy(gameObject);
}
public void KillLoop(float fadeTime)
{
StartCoroutine(FadeLoop(fadeTime));
}
float loopFadeTimer = 0f;
IEnumerator FadeLoop(float fadeTime)
{
float startingVol = audioSource.volume;
while (loopFadeTimer < fadeTime)
{
loopFadeTimer += Time.deltaTime;
audioSource.volume = Mathf.Max((1f - (loopFadeTimer / fadeTime)) * startingVol, 0f);
yield return null;
}
Delete();
}
}
}