2022-03-12 14:14:41 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-03-12 14:14:41 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_BlueBear
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
|
|
|
public class Treat : PlayerActionObject
|
|
|
|
{
|
|
|
|
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;
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
2022-03-12 14:14:41 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
2022-03-12 14:14:41 +00:00
|
|
|
flyBeats = isCake ? 3f : 2f;
|
2023-01-15 04:33:37 +00:00
|
|
|
game.ScheduleInput(startBeat, flyBeats, isCake ? InputType.DIRECTION_DOWN : InputType.STANDARD_DOWN, Just, Out, Out);
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
void EatFood()
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
|
|
|
flying = false;
|
|
|
|
|
|
|
|
if (isCake)
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("blueBear/chompCake");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("blueBear/chompDonut");
|
|
|
|
}
|
|
|
|
|
2023-03-27 03:10:38 +00:00
|
|
|
game.Bite(isCake);
|
|
|
|
game.EatTreat();
|
|
|
|
|
2022-03-27 12:08:26 +00:00
|
|
|
SpawnCrumbs();
|
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
GameObject.Destroy(gameObject);
|
|
|
|
}
|
2022-03-27 12:08:26 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
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) {}
|
|
|
|
|
2022-03-27 12:08:26 +00:00
|
|
|
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();
|
|
|
|
}
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
}
|