2023-03-27 03:30:11 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-10-29 19:44:47 +00:00
|
|
|
using HeavenStudio.InputSystem;
|
2023-05-28 04:33:02 +00:00
|
|
|
using System;
|
2023-03-27 03:30:11 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_OctopusMachine
|
|
|
|
{
|
|
|
|
public class Octopus : MonoBehaviour
|
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
[SerializeField] SpriteRenderer[] sr;
|
|
|
|
[SerializeField] SpriteRenderer[] srAll;
|
2023-03-27 03:30:11 +00:00
|
|
|
[SerializeField] bool player;
|
2023-05-28 04:33:02 +00:00
|
|
|
public Animator anim;
|
|
|
|
|
|
|
|
public bool cantBop;
|
|
|
|
public bool isSqueezed;
|
|
|
|
public bool isPreparing;
|
2023-10-27 20:19:11 +00:00
|
|
|
public double queuePrepare;
|
2023-06-10 19:13:29 +00:00
|
|
|
double lastSqueezeBeat;
|
2023-05-28 04:33:02 +00:00
|
|
|
bool isActive = true;
|
2023-03-27 03:30:11 +00:00
|
|
|
|
|
|
|
private OctopusMachine game;
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
game = OctopusMachine.instance;
|
2023-10-27 20:19:11 +00:00
|
|
|
queuePrepare = double.MaxValue;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
if (queuePrepare <= Conductor.instance.songPositionInBeatsAsDouble && Conductor.instance.NotStopped()) {
|
2023-12-06 01:59:36 +00:00
|
|
|
if (!(isPreparing || isSqueezed || anim.IsPlayingAnimationNames("Release", "Pop")))
|
2023-05-28 04:33:02 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
anim.DoScaledAnimationFromBeatAsync("Prepare", 0.5f, queuePrepare);
|
2023-05-28 04:33:02 +00:00
|
|
|
isPreparing = true;
|
2023-10-27 20:19:11 +00:00
|
|
|
queuePrepare = double.MaxValue;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-29 19:44:47 +00:00
|
|
|
|
2023-05-28 04:33:02 +00:00
|
|
|
if (isActive && player)
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
if (PlayerInput.GetIsAction(OctopusMachine.InputAction_BasicPress) && !game.IsExpectingInputNow(OctopusMachine.InputAction_BasicPress))
|
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
OctoAction("Squeeze");
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("nearMiss");
|
2023-06-04 04:30:42 +00:00
|
|
|
game.hasMissed = true;
|
|
|
|
}
|
2023-03-27 03:30:11 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
if (PlayerInput.GetIsAction(OctopusMachine.InputAction_BasicRelease) && !game.IsExpectingInputNow(OctopusMachine.InputAction_BasicRelease))
|
|
|
|
{
|
|
|
|
OctoAction("Release");
|
|
|
|
SoundByte.PlayOneShotGame("nearMiss");
|
|
|
|
game.hasMissed = true;
|
|
|
|
}
|
|
|
|
else if (PlayerInput.CurrentControlStyle == InputController.ControlStyles.Touch
|
|
|
|
&& PlayerInput.GetIsAction(OctopusMachine.InputAction_FlickRelease) && !game.IsExpectingInputNow(OctopusMachine.InputAction_FlickRelease))
|
|
|
|
{
|
|
|
|
OctoAction("Pop");
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("nearMiss");
|
2023-06-04 04:30:42 +00:00
|
|
|
game.hasMissed = true;
|
2023-05-28 04:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 16:19:39 +00:00
|
|
|
public void RequestBop()
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-12-06 01:59:36 +00:00
|
|
|
if (!anim.IsPlayingAnimationNames("Bop", "Happy", "Angry", "Oops", "Release", "Pop") && !isPreparing && !isSqueezed && !cantBop)
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
PlayAnimation(game.bopStatus);
|
|
|
|
}
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 04:33:02 +00:00
|
|
|
public void PlayAnimation(int whichBop)
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
if (whichBop == 2 && player) whichBop = 3;
|
2023-10-29 19:44:47 +00:00
|
|
|
anim.DoScaledAnimationAsync(whichBop switch
|
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
0 => "Bop",
|
|
|
|
1 => "Happy",
|
|
|
|
2 => "Angry",
|
|
|
|
3 => "Oops",
|
2023-06-10 19:13:29 +00:00
|
|
|
_ => "Bop"
|
2023-05-28 04:33:02 +00:00
|
|
|
}, 0.5f);
|
2023-06-04 04:30:42 +00:00
|
|
|
isPreparing =
|
|
|
|
isSqueezed = false;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 04:33:02 +00:00
|
|
|
public void ForceSqueeze()
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
anim.DoScaledAnimationAsync("ForceSqueeze", 0.5f);
|
|
|
|
isSqueezed = true;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 04:33:02 +00:00
|
|
|
public void OctopusModifiers(float x, float y, bool enable)
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
gameObject.transform.position = new Vector3(x, y, 0);
|
|
|
|
foreach (var sprite in srAll) sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, enable ? 1 : 0);
|
|
|
|
isActive = enable;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
public void OctoAction(string action)
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
if (action != "Release" || (Conductor.instance.songPositionInBeatsAsDouble - lastSqueezeBeat) > 0.15f) SoundByte.PlayOneShotGame($"octopusMachine/{action.ToLower()}");
|
|
|
|
if (action == "Squeeze") lastSqueezeBeat = Conductor.instance.songPositionInBeatsAsDouble;
|
2023-03-27 03:30:11 +00:00
|
|
|
|
2023-05-28 04:33:02 +00:00
|
|
|
anim.DoScaledAnimationAsync(action, 0.5f);
|
2023-10-27 20:19:11 +00:00
|
|
|
isSqueezed = action == "Squeeze";
|
|
|
|
isPreparing = false;
|
|
|
|
queuePrepare = double.MaxValue;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
public void AnimationColor(int poppingColor)
|
2023-03-27 03:30:11 +00:00
|
|
|
{
|
2023-05-28 04:33:02 +00:00
|
|
|
foreach (var sprite in sr) sprite.material.SetColor("_ColorAlpha", (poppingColor == 0 ? OctopusMachine.octopodesColor : OctopusMachine.octopodesSqueezedColor));
|
|
|
|
if (poppingColor == 1) isSqueezed = true;
|
2023-03-27 03:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|