HeavenStudio/Assets/Scripts/Games/FlipperFlop/FlipperFlopFlipper.cs
minenice55 bb2ae74339
Integration of Jukebox Library (#451)
* add Jukebox library

todo:
- saving / loading of new format
- inferrence of unknown data like past versions
- move the temporary float casts to proper use of double
- make sound related functions take double for timing
- inform people that the Jukebox sound player was renamed to SoundByte lol

* make sound, input scheduling, and super curve use double precision

* successfully load charts

* editor works again

v1 riqs can be saved and loaded

* first tempo and volume markers are unmovable

fix loading of charts' easing values

* use gsync / freesync

* update Jukebox refs to SoundByte

* game events use double part 1

Air Rally - Glee Club converted

* don't load song if chart load fails

* finish conversion of all minigames

* remove editor waveform toggle

* timeline now respects added song offset length

clear cache files on app close
prepped notes for dsp sync

* update timeline length when offset changed

* update to latest Jukebox

* make error panel object in global game manager

* improve conductor music scheduling

* added error message box

fix first game events sometimes not playing
2023-06-10 15:13:29 -04:00

159 lines
5.6 KiB
C#

using HeavenStudio.Util;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace HeavenStudio.Games.Scripts_FlipperFlop
{
public class FlipperFlopFlipper : MonoBehaviour
{
[SerializeField] Animator anim;
[SerializeField] Animator faceAnim;
[SerializeField] GameObject leftImpact;
[SerializeField] GameObject rightImpact;
public bool player;
public bool left;
bool up;
bool canBlink = true;
private FlipperFlop game;
private void Awake()
{
faceAnim.Play("FaceNormal", 0, 0);
game = FlipperFlop.instance;
}
private void Update()
{
if (UnityEngine.Random.Range(1, 600) == 1 && canBlink && !isPlaying(faceAnim, "FlipperBlink"))
{
faceAnim.DoScaledAnimationAsync("FlipperBlink", 0.5f);
}
}
public void Impact(bool enableRight)
{
if (enableRight)
{
rightImpact.SetActive(true);
}
else
{
leftImpact.SetActive(true);
}
faceAnim.Play("FaceAngry", 0, 0);
BeatAction.New(game.gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(Conductor.instance.songPositionInBeatsAsDouble + 0.1f, delegate { leftImpact.SetActive(false); rightImpact.SetActive(false); }),
new BeatAction.Action(Conductor.instance.songPositionInBeatsAsDouble + 0.3f, delegate { faceAnim.Play("FaceAnnoyed", 0, 0); })
});
}
public void PrepareFlip()
{
anim.DoScaledAnimationAsync("PrepareFlop", 0.5f);
}
public void Flip(bool roll, bool hit, bool barely = false, bool dontSwitch = false)
{
if (roll)
{
if (player && hit && !barely)
{
SoundByte.PlayOneShotGame("flipperFlop/roll" + (left ? "L" : "R"));
faceAnim.Play("FaceNormal", 0, 0);
canBlink = true;
}
else if (player && barely && hit)
{
SoundByte.PlayOneShotGame("flipperFlop/tink");
faceAnim.Play("FaceBarely", 0, 0);
canBlink = false;
}
else if (player && !hit)
{
faceAnim.Play("FaceOw");
canBlink = false;
SoundByte.PlayOneShotGame("flipperFlop/failgroan");
game.BumpIntoOtherSeal(!left);
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(Conductor.instance.songPositionInBeatsAsDouble + 0.3f, delegate { faceAnim.Play("FaceGoofy"); }),
});
}
up = !up;
}
else
{
if (player && hit)
{
if (up && !barely)
{
faceAnim.Play("FaceNormal", 0, 0);
SoundByte.PlayOneShotGame($"flipperFlop/flipB{UnityEngine.Random.Range(1, 3)}");
canBlink = true;
}
else if (!barely)
{
SoundByte.PlayOneShotGame($"flipperFlop/flip{UnityEngine.Random.Range(1, 3)}");
faceAnim.Play("FaceNormal", 0, 0);
canBlink = true;
}
else
{
SoundByte.PlayOneShotGame("flipperFlop/tink");
faceAnim.Play("FaceBarely", 0, 0);
canBlink = false;
}
}
else if (player)
{
faceAnim.Play("FaceOw");
canBlink = false;
string shouldReverse = up ? "Reverse" : "";
string leftOrRight = left ? "Left" : "Right";
SoundByte.PlayOneShotGame("flipperFlop/failgroan", -1, 1, 0.5f);
SoundByte.PlayOneShotGame("flipperFlop/punch", -1, 1, 0.5f);
anim.DoScaledAnimationAsync(shouldReverse + "MissFlop" + leftOrRight, 0.5f);
game.BumpIntoOtherSeal(!left);
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(Conductor.instance.songPositionInBeatsAsDouble + 0.3f, delegate { faceAnim.Play("FaceGoofy"); }),
});
}
}
if (hit || barely || roll)
{
string shouldReverse = up ? "Reverse" : "";
if (roll) shouldReverse = !up ? "Reverse" : "";
string leftOrRight = left ? "Left" : "Right";
string rollOrFlop = roll ? "Roll" : "Flop";
anim.DoScaledAnimationAsync(shouldReverse + rollOrFlop + leftOrRight, roll ? 0.8f : 0.5f);
}
if (!dontSwitch) left = !left;
}
public void Bop()
{
anim.DoScaledAnimationAsync("FlipperBop", 0.5f);
faceAnim.Play("FaceNormal", 0, 0);
canBlink = true;
}
bool isPlaying(Animator anim, string stateName)
{
if (anim.GetCurrentAnimatorStateInfo(0).IsName(stateName) &&
anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f)
return true;
else
return false;
}
}
}