HeavenStudioPlus/Assets/Scripts/Games/BlueBear/Treat.cs
minenice55 afc665ed61 Integration of Jukebox Library (#451) (#457)
* 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 19:17:06 +00:00

111 lines
3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using NaughtyBezierCurves;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_BlueBear
{
public class Treat : MonoBehaviour
{
const float rotSpeed = 360f;
public bool isCake;
public double startBeat;
bool flying = true;
double flyBeats;
[NonSerialized] public BezierCurve3D curve;
private BlueBear game;
private void Awake()
{
game = BlueBear.instance;
}
private void Start()
{
flyBeats = isCake ? 3f : 2f;
game.ScheduleInput(startBeat, flyBeats, isCake ? InputType.DIRECTION_DOWN : InputType.STANDARD_DOWN, Just, Out, Out);
}
private void Update()
{
if (flying)
{
var cond = Conductor.instance;
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
flyPos *= isCake ? 0.75f : 0.6f;
transform.position = curve.GetPoint(flyPos);
if (flyPos > 1f)
{
GameObject.Destroy(gameObject);
return;
}
float rot = isCake ? rotSpeed : -rotSpeed;
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (rot * Time.deltaTime));
}
}
void EatFood()
{
flying = false;
if (isCake)
{
SoundByte.PlayOneShotGame("blueBear/chompCake");
}
else
{
SoundByte.PlayOneShotGame("blueBear/chompDonut");
}
game.Bite(isCake);
game.EatTreat();
SpawnCrumbs();
GameObject.Destroy(gameObject);
}
private void Just(PlayerActionEvent caller, float state)
{
if (state >= 1f || state <= -1f) { //todo: proper near miss feedback
if (isCake)
{
game.headAndBodyAnim.Play("BiteL", 0, 0);
}
else
{
game.headAndBodyAnim.Play("BiteR", 0, 0);
}
return;
}
EatFood();
}
private void Miss(PlayerActionEvent caller) {}
private void Out(PlayerActionEvent caller) {}
void SpawnCrumbs()
{
var crumbsGO = GameObject.Instantiate(game.crumbsBase, game.crumbsHolder);
crumbsGO.SetActive(true);
crumbsGO.transform.position = transform.position;
var ps = crumbsGO.GetComponent<ParticleSystem>();
var main = ps.main;
var newGradient = new ParticleSystem.MinMaxGradient(isCake ? game.cakeGradient : game.donutGradient);
newGradient.mode = ParticleSystemGradientMode.RandomColor;
main.startColor = newGradient;
ps.Play();
}
}
}