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
|
|
|
{
|
2023-11-22 01:07:35 +00:00
|
|
|
public class Treat : SuperCurveObject
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
2023-11-22 01:07:35 +00:00
|
|
|
const float barelyDistX = 1.5f;
|
|
|
|
const float barelyDistY = -6f;
|
|
|
|
const float barelyHeight = 4f;
|
|
|
|
const float rotSpeed = 360f * 3;
|
2022-03-12 14:14:41 +00:00
|
|
|
|
|
|
|
public bool isCake;
|
2023-06-10 19:13:29 +00:00
|
|
|
public double startBeat;
|
|
|
|
double flyBeats;
|
2022-03-12 14:14:41 +00:00
|
|
|
|
2023-11-22 01:07:35 +00:00
|
|
|
private Path path;
|
2022-03-12 14:14:41 +00:00
|
|
|
|
|
|
|
private BlueBear game;
|
2023-10-29 19:44:47 +00:00
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
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-11-22 01:07:35 +00:00
|
|
|
Path pathToCopy = isCake ? game.GetPath("Cake") : game.GetPath("Donut");
|
|
|
|
path = new();
|
|
|
|
path.positions = new PathPos[2];
|
|
|
|
path.positions[0].pos = pathToCopy.positions[0].pos;
|
|
|
|
path.positions[0].duration = pathToCopy.positions[0].duration;
|
|
|
|
path.positions[0].height = pathToCopy.positions[0].height;
|
|
|
|
path.positions[1].pos = pathToCopy.positions[1].pos;
|
2023-10-29 19:44:47 +00:00
|
|
|
game.ScheduleInput(startBeat, flyBeats, isCake ? BlueBear.InputAction_Left : BlueBear.InputAction_Right, Just, Out, Out);
|
2023-11-22 01:07:35 +00:00
|
|
|
Update();
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-11-22 01:07:35 +00:00
|
|
|
var cond = Conductor.instance;
|
|
|
|
transform.localPosition = GetPathPositionFromBeat(path, cond.songPositionInBeatsAsDouble, startBeat);
|
2022-03-12 14:14:41 +00:00
|
|
|
|
2023-11-22 01:07:35 +00:00
|
|
|
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
|
|
|
|
if (flyPos > 2f)
|
|
|
|
{
|
|
|
|
Destroy(gameObject);
|
|
|
|
return;
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
2023-11-22 01:07:35 +00:00
|
|
|
|
|
|
|
float rot = isCake ? rotSpeed : -rotSpeed;
|
|
|
|
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (rot * Time.deltaTime * cond.pitchedSecPerBeat));
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
void EatFood()
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
|
|
|
if (isCake)
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("blueBear/chompCake");
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("blueBear/chompDonut");
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 22:38:52 +00:00
|
|
|
game.Bite(Conductor.instance.songPositionInBeatsAsDouble, isCake);
|
2023-03-27 03:10:38 +00:00
|
|
|
game.EatTreat();
|
|
|
|
|
2022-03-27 12:08:26 +00:00
|
|
|
SpawnCrumbs();
|
|
|
|
|
2023-11-22 01:07:35 +00:00
|
|
|
Destroy(gameObject);
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
2022-03-27 12:08:26 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Just(PlayerActionEvent caller, float state)
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
if (state >= 1f || state <= -1f)
|
2023-11-22 01:07:35 +00:00
|
|
|
{
|
|
|
|
SoundByte.PlayOneShot("miss");
|
2023-01-15 04:33:37 +00:00
|
|
|
if (isCake)
|
|
|
|
{
|
2023-11-22 01:07:35 +00:00
|
|
|
game.headAndBodyAnim.DoScaledAnimationAsync("BiteL", 0, 0);
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-22 01:07:35 +00:00
|
|
|
game.headAndBodyAnim.DoScaledAnimationAsync("BiteR", 0, 0);
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
2023-11-22 01:07:35 +00:00
|
|
|
path.positions[0].pos = transform.localPosition;
|
|
|
|
path.positions[0].height = barelyHeight;
|
|
|
|
path.positions[0].duration = 1;
|
|
|
|
path.positions[1].pos = new Vector3(path.positions[0].pos.x + (isCake ? -barelyDistX : barelyDistX), path.positions[0].pos.y + barelyDistY);
|
|
|
|
startBeat = Conductor.instance.songPositionInBeatsAsDouble;
|
|
|
|
Update();
|
2023-10-29 19:44:47 +00:00
|
|
|
return;
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
|
|
|
EatFood();
|
|
|
|
}
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
private void Out(PlayerActionEvent caller) { }
|
2023-01-15 04:33:37 +00:00
|
|
|
|
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;
|
2023-11-22 01:07:35 +00:00
|
|
|
ps.PlayScaledAsync(1);
|
2022-03-27 12:08:26 +00:00
|
|
|
}
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
}
|