HeavenStudioPlus/Assets/Scripts/Games/RhythmTweezers/Tweezers.cs
minenice55 8fa4d74096 Alternate Control Styles Support (#554)
* add mouse controller

* support different control styles in options

deprecate old input check methods

* fully functional input actions system

* btsds InputAction

* blue bear InputAction

* more games

fix bugs with some input related systems

* coin toss re-toss

* cheer readers touch

* dog ninja touch

* multiple games

* last of the easy games' touch

* more specialized games

* specialized games 2

* finish ktb games

* remove legacy settings disclaimer

* "only" two games left

* karate man touch

* rockers touch

still needs fixes and bad judge strum

* DSGuy flicking animation

* playstyle chart property

* improve performance of minigame preloading

* improve look of cursor

make assetbundles use chunk-based compression
refactor assetbundle loading methods a bit

* prime conductor stream playback to stabilize seeking operations

* fix air rally swing on pad release

* use virtual mouse pointer

* add UniTask

* make BeatAction use UniTask

* implement UniTask to replace some coroutines

* add touch style UI elements and effects

games now support the ability to define two cursor colours if they need split screen touch inputs

* update plugins and buildscript

* implement thresholded pointer position clipping

* fix clamping

* instant show / hide

fix discord game SDK crashes
2023-10-29 19:44:47 +00:00

160 lines
No EOL
5.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using HeavenStudio.Util;
using Starpelly;
namespace HeavenStudio.Games.Scripts_RhythmTweezers
{
public class Tweezers : MonoBehaviour
{
public int hitOnFrame;
[NonSerialized] public Animator anim;
private Animator vegetableAnim;
private RhythmTweezers game;
private bool pluckingThisFrame;
private bool holdingHair;
public SpriteRenderer heldHairSprite;
public Transform tweezerSpriteTrans;
private double passTurnBeat = -1;
private double passTurnEndBeat = -1;
[NonSerialized] public int hairsLeft;
private int eyeSize = 0;
private void Awake()
{
anim = GetComponent<Animator>();
vegetableAnim = RhythmTweezers.instance.VegetableAnimator;
game = RhythmTweezers.instance;
}
public void Init(double beat, double endBeat)
{
passTurnBeat = beat;
passTurnEndBeat = endBeat;
Update();
}
private void Update()
{
if (passTurnBeat != -1)
{
// Set tweezer angle.
float tweezerTime = Conductor.instance.GetPositionFromBeat(passTurnBeat, Math.Max(passTurnEndBeat - 1f - passTurnBeat, 1));
var unclampedAngle = -58f + (116 * tweezerTime);
var tweezerAngle = Mathf.Clamp(unclampedAngle, -180f, 180f);
transform.eulerAngles = new Vector3(0, 0, tweezerAngle);
// Set tweezer to follow vegetable.
var currentTweezerPos = transform.localPosition;
var vegetablePos = game.Vegetable.transform.localPosition;
var vegetableHolderPos = game.VegetableHolder.transform.localPosition;
transform.localPosition = new Vector3(vegetableHolderPos.x, vegetablePos.y + 1f, currentTweezerPos.z);
if (tweezerAngle == 180)
{
Destroy(gameObject);
}
}
if (PlayerInput.GetIsAction(RhythmTweezers.InputAction_Press) && !game.IsExpectingInputNow(RhythmTweezers.InputAction_Press))
{
DropHeldHair();
anim.Play("Tweezers_Pluck", 0, 0);
}
}
private void LateUpdate()
{
}
public void Pluck(bool ace, Hair hair)
{
DropHeldHair();
if (ace)
{
SoundByte.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
hair.hairSprite.SetActive(false);
hair.stubbleSprite.SetActive(true);
hairsLeft--;
eyeSize = Mathf.Clamp(eyeSize + 1, 0, 10);
if (hairsLeft <= 0)
vegetableAnim.Play("HopFinal", 0, 0);
else
vegetableAnim.Play("Hop" + eyeSize.ToString(), 0, 0);
anim.Play("Tweezers_Pluck_Success", 0, 0);
}
else
{
SoundByte.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
SoundByte.PlayOneShot("miss");
hair.hairSprite.SetActive(false);
hair.missedSprite.SetActive(true);
vegetableAnim.Play("Blink", 0, 0);
anim.Play("Tweezers_Pluck_Fail", 0, 0);
}
// pluckingThisFrame = true; // Prevents standard pluck from playing in LateUpdate().
holdingHair = true;
}
public void LongPluck(bool ace, LongHair hair)
{
DropHeldHair();
if (ace)
{
SoundByte.PlayOneShotGame("rhythmTweezers/longPullEnd");
hair.hairSprite.SetActive(false);
hair.stubbleSprite.SetActive(true);
// Making transparent instead of disabling because animators are silly.
hair.loop.GetComponent<SpriteRenderer>().color = Color.clear;
hairsLeft--;
eyeSize = Mathf.Clamp(eyeSize + 1, 0, 10);
if (hairsLeft <= 0)
vegetableAnim.Play("HopFinal", 0, 0);
else
vegetableAnim.Play("Hop" + eyeSize.ToString(), 0, 0);
anim.Play("Tweezers_Pluck_Success", 0, 0);
}
// pluckingThisFrame = true;
holdingHair = true;
}
public void DropHeldHair()
{
if (!holdingHair) return;
var droppedHair = GameObject.Instantiate(game.pluckedHairBase, game.DroppedHairsHolder.transform).GetComponent<SpriteRenderer>();
droppedHair.gameObject.SetActive(true);
droppedHair.transform.position = heldHairSprite.transform.position;
droppedHair.transform.rotation = heldHairSprite.transform.rotation;
droppedHair.sprite = heldHairSprite.sprite;
// Make the hair spin.
// (The prefab has a Rigidbody2D component already so that it falls)
droppedHair.GetComponent<Rigidbody2D>().interpolation = RigidbodyInterpolation2D.Interpolate;
droppedHair.GetComponent<Rigidbody2D>().angularVelocity = UnityEngine.Random.Range(-120f, 120f);
holdingHair = false;
}
}
}