2022-03-12 03:15:15 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
using NaughtyBezierCurves;
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-10-29 19:44:47 +00:00
|
|
|
using HeavenStudio.InputSystem;
|
2022-03-12 03:15:15 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class CtrBearLoader
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
public static Minigame AddGame(EventCaller eventCaller)
|
|
|
|
{
|
|
|
|
return new Minigame("blueBear", "Blue Bear", "b4e6f6", "e7e7e7", "bf9d34", false, false, new List<GameAction>()
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("donut", "Donut")
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, false); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 3,
|
|
|
|
},
|
|
|
|
new GameAction("cake", "Cake")
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, true); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 4,
|
|
|
|
},
|
2023-03-27 03:10:38 +00:00
|
|
|
new GameAction("setEmotion", "Set Emotion")
|
|
|
|
{
|
|
|
|
function = delegate { var e = eventCaller.currentEntity; BlueBear.instance.SetEmotion(e.beat, e.length, e["type"]); },
|
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", BlueBear.EmotionType.ClosedEyes, "Type", "Which emotion should the blue bear use?")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("wind", "Wind")
|
|
|
|
{
|
|
|
|
function = delegate { BlueBear.instance.Wind(); },
|
|
|
|
defaultLength = 0.5f
|
|
|
|
},
|
|
|
|
new GameAction("crumb", "Set Crumb Threshold")
|
|
|
|
{
|
|
|
|
function = delegate { var e = eventCaller.currentEntity; BlueBear.instance.SetCrumbThreshold(e["right"], e["left"], e["reset"]); },
|
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("right", new EntityTypes.Integer(0, 500, 15), "Right Crumb", "How many treats should the bear eat before the right crumb can appear on his face?"),
|
|
|
|
new Param("left", new EntityTypes.Integer(0, 500, 30), "Left Crumb", "How many treats should the bear eat before the left crumb can appear on his face?"),
|
|
|
|
new Param("reset", false, "Reset Treats Eaten", "Should the numbers of treats eaten be reset?")
|
|
|
|
}
|
|
|
|
}
|
2023-05-28 17:34:44 +00:00
|
|
|
},
|
2023-10-29 19:44:47 +00:00
|
|
|
new List<string>() { "ctr", "normal" },
|
2023-05-28 17:34:44 +00:00
|
|
|
"ctrbear", "en",
|
2023-10-29 19:44:47 +00:00
|
|
|
new List<string>() { }
|
2023-05-28 17:34:44 +00:00
|
|
|
);
|
2022-04-12 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-03-12 03:15:15 +00:00
|
|
|
{
|
2022-03-12 14:14:41 +00:00
|
|
|
using Scripts_BlueBear;
|
2022-03-12 03:15:15 +00:00
|
|
|
public class BlueBear : Minigame
|
|
|
|
{
|
2023-03-27 03:10:38 +00:00
|
|
|
public enum EmotionType
|
|
|
|
{
|
|
|
|
Neutral,
|
|
|
|
ClosedEyes,
|
|
|
|
LookUp,
|
|
|
|
Smile,
|
|
|
|
Sad,
|
|
|
|
InstaSad,
|
|
|
|
Sigh
|
|
|
|
}
|
2022-03-12 14:14:41 +00:00
|
|
|
[Header("Animators")]
|
|
|
|
public Animator headAndBodyAnim; // Head and body
|
|
|
|
public Animator bagsAnim; // Both bags sprite
|
|
|
|
public Animator donutBagAnim; // Individual donut bag
|
|
|
|
public Animator cakeBagAnim; // Individual cake bag
|
2023-03-27 03:10:38 +00:00
|
|
|
[SerializeField] Animator windAnim;
|
2022-03-12 14:14:41 +00:00
|
|
|
|
|
|
|
[Header("References")]
|
2023-03-27 03:10:38 +00:00
|
|
|
[SerializeField] GameObject leftCrumb;
|
|
|
|
[SerializeField] GameObject rightCrumb;
|
2022-03-12 14:14:41 +00:00
|
|
|
public GameObject donutBase;
|
|
|
|
public GameObject cakeBase;
|
2022-03-27 12:08:26 +00:00
|
|
|
public GameObject crumbsBase;
|
2022-03-12 14:14:41 +00:00
|
|
|
public Transform foodHolder;
|
2022-03-27 12:08:26 +00:00
|
|
|
public Transform crumbsHolder;
|
2022-03-12 14:14:41 +00:00
|
|
|
public GameObject individualBagHolder;
|
|
|
|
|
2023-03-27 03:10:38 +00:00
|
|
|
[Header("Variables")]
|
|
|
|
static int rightCrumbAppearThreshold = 15;
|
|
|
|
static int leftCrumbAppearThreshold = 30;
|
|
|
|
static int eatenTreats = 0;
|
2023-06-10 19:13:29 +00:00
|
|
|
double emotionStartBeat;
|
2023-03-27 03:10:38 +00:00
|
|
|
float emotionLength;
|
|
|
|
string emotionAnimName;
|
|
|
|
bool crying;
|
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
[Header("Curves")]
|
|
|
|
public BezierCurve3D donutCurve;
|
|
|
|
public BezierCurve3D cakeCurve;
|
|
|
|
|
2022-03-27 12:08:26 +00:00
|
|
|
[Header("Gradients")]
|
|
|
|
public Gradient donutGradient;
|
|
|
|
public Gradient cakeGradient;
|
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
private bool squashing;
|
|
|
|
|
|
|
|
public static BlueBear instance;
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
const int IALeft = 0;
|
|
|
|
const int IARight = 1;
|
|
|
|
protected static bool IA_PadLeft(out double dt)
|
|
|
|
{
|
|
|
|
return PlayerInput.GetPadDown(InputController.ActionsPad.Up, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Down, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Left, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Right, out dt);
|
|
|
|
}
|
|
|
|
protected static bool IA_BatonLeft(out double dt)
|
|
|
|
{
|
|
|
|
return PlayerInput.GetBatonDown(InputController.ActionsBaton.West, out dt);
|
|
|
|
}
|
|
|
|
protected static bool IA_TouchLeft(out double dt)
|
|
|
|
{
|
|
|
|
bool want = PlayerInput.GetTouchDown(InputController.ActionsTouch.Left, out dt);
|
|
|
|
bool simul = false;
|
|
|
|
// if (!want)
|
|
|
|
// {
|
|
|
|
// simul = PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt)
|
|
|
|
// && instance.IsExpectingInputNow(InputAction_Left.inputLockCategory)
|
|
|
|
// && instance.IsExpectingInputNow(InputAction_Right.inputLockCategory);
|
|
|
|
// }
|
|
|
|
return want || simul;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static bool IA_PadRight(out double dt)
|
|
|
|
{
|
|
|
|
return PlayerInput.GetPadDown(InputController.ActionsPad.East, out dt);
|
|
|
|
}
|
|
|
|
protected static bool IA_BatonRight(out double dt)
|
|
|
|
{
|
|
|
|
return PlayerInput.GetBatonDown(InputController.ActionsBaton.East, out dt);
|
|
|
|
}
|
|
|
|
protected static bool IA_TouchRight(out double dt)
|
|
|
|
{
|
|
|
|
bool want = PlayerInput.GetTouchDown(InputController.ActionsTouch.Right, out dt);
|
|
|
|
bool simul = false;
|
|
|
|
// if (!want)
|
|
|
|
// {
|
|
|
|
// simul = PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt)
|
|
|
|
// && instance.IsExpectingInputNow(InputAction_Right.inputLockCategory)
|
|
|
|
// && instance.IsExpectingInputNow(InputAction_Left.inputLockCategory);
|
|
|
|
// }
|
|
|
|
return want || simul;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PlayerInput.InputAction InputAction_Left =
|
|
|
|
new("CtrBearLeft", new int[] { IALeft, IALeft, IALeft },
|
|
|
|
IA_PadLeft, IA_TouchLeft, IA_BatonLeft);
|
|
|
|
|
|
|
|
public static PlayerInput.InputAction InputAction_Right =
|
|
|
|
new("CtrBearRight", new int[] { IARight, IARight, IARight },
|
|
|
|
IA_PadRight, IA_TouchRight, IA_BatonRight);
|
|
|
|
|
2023-03-27 03:10:38 +00:00
|
|
|
void OnDestroy()
|
|
|
|
{
|
|
|
|
if (Conductor.instance.isPlaying || Conductor.instance.isPaused) return;
|
|
|
|
rightCrumbAppearThreshold = 15;
|
|
|
|
leftCrumbAppearThreshold = 30;
|
|
|
|
eatenTreats = 0;
|
2023-06-03 23:30:17 +00:00
|
|
|
foreach (var evt in scheduledInputs)
|
|
|
|
{
|
|
|
|
evt.Disable();
|
|
|
|
}
|
2023-03-27 03:10:38 +00:00
|
|
|
}
|
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
private void Awake()
|
2022-03-12 03:15:15 +00:00
|
|
|
{
|
2022-03-12 14:14:41 +00:00
|
|
|
instance = this;
|
2023-03-27 03:10:38 +00:00
|
|
|
if (Conductor.instance.isPlaying || Conductor.instance.isPaused) EatTreat(true);
|
2022-03-27 12:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-03-12 14:14:41 +00:00
|
|
|
headAndBodyAnim.SetBool("ShouldOpenMouth", foodHolder.childCount != 0);
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
if (PlayerInput.GetIsAction(InputAction_Left) && !IsExpectingInputNow(InputAction_Left.inputLockCategory))
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
2023-03-27 03:10:38 +00:00
|
|
|
Bite(true);
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
2023-10-29 19:44:47 +00:00
|
|
|
else if (PlayerInput.GetIsAction(InputAction_Right) && !IsExpectingInputNow(InputAction_Right.inputLockCategory))
|
2022-03-12 14:14:41 +00:00
|
|
|
{
|
2023-03-27 03:10:38 +00:00
|
|
|
Bite(false);
|
|
|
|
}
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
Conductor cond = Conductor.instance;
|
2023-03-27 03:10:38 +00:00
|
|
|
|
|
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
|
|
{
|
|
|
|
float normalizedBeat = cond.GetPositionFromBeat(emotionStartBeat, emotionLength);
|
|
|
|
if (normalizedBeat >= 0 && normalizedBeat <= 1f)
|
|
|
|
{
|
|
|
|
//headAndBodyAnim.DoNormalizedAnimation(emotionAnimName, normalizedBeat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Wind()
|
|
|
|
{
|
|
|
|
windAnim.Play("Wind", 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bite(bool left)
|
|
|
|
{
|
|
|
|
if (crying)
|
|
|
|
{
|
|
|
|
headAndBodyAnim.Play(left ? "CryBiteL" : "CryBiteR", 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headAndBodyAnim.Play(left ? "BiteL" : "BiteR", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCrumbThreshold(int rightThreshold, int leftThreshold, bool reset)
|
|
|
|
{
|
|
|
|
rightCrumbAppearThreshold = rightThreshold;
|
|
|
|
leftCrumbAppearThreshold = leftThreshold;
|
|
|
|
if (reset) eatenTreats = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EatTreat(bool onlyCheck = false)
|
|
|
|
{
|
|
|
|
if (!onlyCheck) eatenTreats++;
|
|
|
|
if (eatenTreats >= leftCrumbAppearThreshold)
|
|
|
|
{
|
|
|
|
leftCrumb.SetActive(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leftCrumb.SetActive(false);
|
|
|
|
}
|
|
|
|
if (eatenTreats >= rightCrumbAppearThreshold)
|
|
|
|
{
|
|
|
|
rightCrumb.SetActive(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rightCrumb.SetActive(false);
|
2022-03-12 14:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
{
|
|
|
|
if (squashing)
|
|
|
|
{
|
|
|
|
var dState = donutBagAnim.GetCurrentAnimatorStateInfo(0);
|
|
|
|
var cState = cakeBagAnim.GetCurrentAnimatorStateInfo(0);
|
|
|
|
|
|
|
|
bool noDonutSquash = dState.IsName("DonutIdle");
|
|
|
|
bool noCakeSquash = cState.IsName("CakeIdle");
|
|
|
|
|
|
|
|
if (noDonutSquash && noCakeSquash)
|
|
|
|
{
|
|
|
|
squashing = false;
|
|
|
|
bagsAnim.Play("Idle", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2022-03-12 03:15:15 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void SetEmotion(double beat, float length, int emotion)
|
2023-03-27 03:10:38 +00:00
|
|
|
{
|
|
|
|
switch (emotion)
|
|
|
|
{
|
|
|
|
case (int)EmotionType.Neutral:
|
|
|
|
if (emotionAnimName == "Smile")
|
|
|
|
{
|
|
|
|
headAndBodyAnim.Play("StopSmile", 0, 0);
|
|
|
|
emotionAnimName = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headAndBodyAnim.Play("Idle", 0, 0);
|
|
|
|
}
|
|
|
|
crying = false;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.ClosedEyes:
|
|
|
|
headAndBodyAnim.Play("EyesClosed", 0, 0);
|
|
|
|
crying = false;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.LookUp:
|
|
|
|
emotionStartBeat = beat;
|
|
|
|
emotionLength = length;
|
|
|
|
emotionAnimName = "OpenEyes";
|
|
|
|
headAndBodyAnim.Play(emotionAnimName, 0, 0);
|
|
|
|
crying = false;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.Smile:
|
|
|
|
emotionStartBeat = beat;
|
|
|
|
emotionLength = length;
|
|
|
|
emotionAnimName = "Smile";
|
|
|
|
headAndBodyAnim.Play(emotionAnimName, 0, 0);
|
|
|
|
crying = false;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.Sad:
|
|
|
|
emotionStartBeat = beat;
|
|
|
|
emotionLength = length;
|
|
|
|
emotionAnimName = "Sad";
|
|
|
|
headAndBodyAnim.Play(emotionAnimName, 0, 0);
|
|
|
|
crying = true;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.InstaSad:
|
|
|
|
headAndBodyAnim.Play("CryIdle", 0, 0);
|
|
|
|
crying = true;
|
|
|
|
break;
|
|
|
|
case (int)EmotionType.Sigh:
|
|
|
|
headAndBodyAnim.Play("Sigh", 0, 0);
|
|
|
|
crying = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void SpawnTreat(double beat, bool isCake)
|
2022-03-12 03:15:15 +00:00
|
|
|
{
|
2022-03-12 14:14:41 +00:00
|
|
|
var objectToSpawn = isCake ? cakeBase : donutBase;
|
|
|
|
var newTreat = GameObject.Instantiate(objectToSpawn, foodHolder);
|
2023-10-29 19:44:47 +00:00
|
|
|
|
2022-03-12 14:14:41 +00:00
|
|
|
var treatComp = newTreat.GetComponent<Treat>();
|
|
|
|
treatComp.startBeat = beat;
|
|
|
|
treatComp.curve = isCake ? cakeCurve : donutCurve;
|
|
|
|
|
|
|
|
newTreat.SetActive(true);
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame(isCake ? "blueBear/cake" : "blueBear/donut");
|
2022-03-12 14:14:41 +00:00
|
|
|
|
|
|
|
SquashBag(isCake);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SquashBag(bool isCake)
|
|
|
|
{
|
|
|
|
squashing = true;
|
|
|
|
bagsAnim.Play("Squashing", 0, 0);
|
|
|
|
|
|
|
|
individualBagHolder.SetActive(true);
|
|
|
|
|
|
|
|
if (isCake)
|
|
|
|
{
|
|
|
|
cakeBagAnim.Play("CakeSquash", 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
donutBagAnim.Play("DonutSquash", 0, 0);
|
|
|
|
}
|
2022-03-12 03:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|