2022-02-10 08:13:54 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-02-11 02:14:09 +00:00
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
2022-02-10 08:13:54 +00:00
|
|
|
namespace RhythmHeavenMania.Games.RhythmTweezers
|
|
|
|
{
|
|
|
|
public class LongHair : PlayerActionObject
|
|
|
|
{
|
|
|
|
public float createBeat;
|
2022-02-11 02:14:09 +00:00
|
|
|
public GameObject hairSprite;
|
|
|
|
public GameObject stubbleSprite;
|
2022-02-10 08:13:54 +00:00
|
|
|
private RhythmTweezers game;
|
|
|
|
private Tweezers tweezers;
|
|
|
|
|
2022-02-11 02:14:09 +00:00
|
|
|
private bool isHolding = false;
|
|
|
|
private float holdBeat = 0f;
|
|
|
|
|
|
|
|
public GameObject holder;
|
|
|
|
|
2022-02-10 08:13:54 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
game = RhythmTweezers.instance;
|
|
|
|
tweezers = game.Tweezers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
float stateBeat = Conductor.instance.GetPositionFromBeat(createBeat + game.tweezerBeatOffset, game.beatInterval);
|
|
|
|
StateCheck(stateBeat);
|
|
|
|
|
|
|
|
if (PlayerInput.Pressed() && tweezers.hitOnFrame == 0)
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
2022-02-11 02:14:09 +00:00
|
|
|
Jukebox.PlayOneShotGame($"rhythmTweezers/longPull{UnityEngine.Random.Range(1, 5)}");
|
|
|
|
isHolding = true;
|
|
|
|
holdBeat = Conductor.instance.songPositionInBeats;
|
2022-02-10 08:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-11 02:14:09 +00:00
|
|
|
|
|
|
|
if (isHolding && Conductor.instance.songPositionInBeats >= holdBeat + 0.5f)
|
|
|
|
{
|
|
|
|
Destroy(holder.transform.GetChild(0).gameObject);
|
|
|
|
isHolding = false;
|
|
|
|
Ace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isHolding)
|
|
|
|
{
|
|
|
|
holder.transform.eulerAngles = new Vector3(0, 0, tweezers.transform.eulerAngles.z * 1.056f);
|
|
|
|
holder.transform.GetChild(0).transform.localScale = Vector2.one / holder.transform.localScale;
|
|
|
|
|
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(holdBeat, 0.5f);
|
|
|
|
GetComponent<Animator>().Play("LoopPull", 0, normalizedBeat);
|
|
|
|
tweezers.anim.Play("Tweezers_LongPluck", 0, normalizedBeat);
|
|
|
|
// float angleBetweenTweezersAndHair = angleBtw2Points(tweezers.transform.position, holder.transform.position);
|
|
|
|
// holder.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angleBetweenTweezersAndHair));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float angleBtw2Points(Vector3 a, Vector3 b)
|
|
|
|
{
|
|
|
|
return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
|
2022-02-10 08:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Ace()
|
|
|
|
{
|
2022-02-11 02:14:09 +00:00
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/longPullEnd");
|
2022-02-10 08:13:54 +00:00
|
|
|
tweezers.LongPluck(true, this);
|
|
|
|
|
|
|
|
tweezers.hitOnFrame++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|