HeavenStudioPlus/Assets/Scripts/Games/BlueBear/Treat.cs
minenice55 caf7d9465f
Play Mode Features Part 1 (#413)
* add pause menu assets

* layout and animation for pause

* make play mode prefab function

re-assign unused class inheritance

* remove filepath

* don't init medals twice

* remove PlayerActionObject

* initial attempt at anti-note lock

TODO: circumvent inputs clearing themselves making the functionality not work

* properly implement input lock prevention

* fix error on editor open

* functional pause menu

* bugfix

* make unpausing not reset current play statistics

* serialize initializer components in inspector instead of procedurally generating

* sanity check

* note for fade

* make flashes in the camera prefabs instead of in world space

remove / reorganize script files
address issue #411

* fix bug with perfect campaign

make minigame transitions hide the game canvas
adjust animation of the song credits textbox

* fully functional intro scene (placeholder for future title screen)

refactored entire game loading procedure
re-organized some files

* add interaction query to disclaimer text

* reword legal

* anchor section medals to section display

more tempo change placement controls

* operation order bugfix

* prep for future ratings and stats

* loading text

* autoload opening scene

* splash screen adjustments

added setting to force enable splash screen

* adjust setting entry
2023-05-07 20:33:15 +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 float startBeat;
bool flying = true;
float 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)
{
Jukebox.PlayOneShotGame("blueBear/chompCake");
}
else
{
Jukebox.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();
}
}
}