2022-03-01 06:38:38 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using NaughtyBezierCurves;
|
2022-03-01 20:57:37 +00:00
|
|
|
using DG.Tweening;
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_CropStomp
|
2022-03-01 06:38:38 +00:00
|
|
|
{
|
|
|
|
public class Veggie : PlayerActionObject
|
|
|
|
{
|
2022-03-01 20:57:37 +00:00
|
|
|
static float pickedRotationSpeed = -1080f;
|
|
|
|
|
2022-03-01 06:38:38 +00:00
|
|
|
public bool isMole;
|
|
|
|
public Sprite[] veggieSprites;
|
2022-03-03 10:43:01 +00:00
|
|
|
public Animator moleAnim;
|
2022-03-01 06:38:38 +00:00
|
|
|
public SpriteRenderer veggieSprite;
|
|
|
|
public Transform veggieTrans;
|
|
|
|
public BezierCurve3D curve;
|
2022-03-03 02:50:08 +00:00
|
|
|
private BezierCurve3D hitCurve;
|
2022-03-01 06:38:38 +00:00
|
|
|
|
|
|
|
public float targetBeat;
|
|
|
|
private float stompedBeat;
|
2022-03-01 20:57:37 +00:00
|
|
|
private float pickedBeat;
|
2022-03-03 02:50:08 +00:00
|
|
|
private float pickTime = 1f;
|
2022-03-01 06:38:38 +00:00
|
|
|
private int veggieState = 0;
|
|
|
|
private bool boinked; // Player got barely when trying to pick.
|
2023-01-15 04:33:37 +00:00
|
|
|
private bool pickEligible = true;
|
2022-03-01 06:38:38 +00:00
|
|
|
|
|
|
|
private float landBeat;
|
|
|
|
|
2022-03-01 20:57:37 +00:00
|
|
|
private Tween squashTween;
|
|
|
|
|
2022-03-01 06:38:38 +00:00
|
|
|
private CropStomp game;
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
public void Init()
|
2022-03-01 06:38:38 +00:00
|
|
|
{
|
|
|
|
game = CropStomp.instance;
|
2023-01-19 02:31:08 +00:00
|
|
|
|
|
|
|
if (Conductor.instance.isPlaying)
|
|
|
|
game.ScheduleInput(targetBeat - 1, 1f, InputType.STANDARD_DOWN, StompJust, StompMiss, Out);
|
2022-03-01 06:38:38 +00:00
|
|
|
|
|
|
|
if (!isMole)
|
|
|
|
{
|
|
|
|
veggieSprite.sprite = veggieSprites[UnityEngine.Random.Range(0, veggieSprites.Length)];
|
|
|
|
}
|
2022-03-03 02:50:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pickTime = 1.5f;
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool gotStomped; // Safeguard in case nested Update() call breaks.
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!game.isMarching)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Veggie missed. Handle missed state.
|
|
|
|
if (veggieState == -1)
|
|
|
|
{
|
|
|
|
MissedUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Veggie picked. Handle picked state.
|
|
|
|
if (veggieState == 2)
|
|
|
|
{
|
|
|
|
PickedUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
// In ground.
|
|
|
|
if (veggieState == 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// In air.
|
|
|
|
else if (veggieState == 1)
|
|
|
|
{
|
|
|
|
float airPosition = cond.GetPositionFromBeat(stompedBeat, landBeat - stompedBeat);
|
|
|
|
veggieTrans.position = curve.GetPoint(Mathf.Clamp(airPosition, 0, 1));
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (PlayerInput.PressedUp() && !game.IsExpectingInputNow(InputType.STANDARD_UP))
|
2022-03-01 06:38:38 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
pickEligible = false;
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void StompJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
if (GameManager.instance.autoplay)
|
|
|
|
{
|
|
|
|
StompVeggie(true);
|
|
|
|
return;
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (state >= 1f)
|
|
|
|
veggieState = -1;
|
|
|
|
else if (state > -1f)
|
|
|
|
StompVeggie(false);
|
|
|
|
}
|
2022-03-03 10:43:01 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void StompMiss(PlayerActionEvent caller)
|
|
|
|
{
|
|
|
|
veggieState = -1;
|
|
|
|
caller.Disable();
|
|
|
|
}
|
2022-03-03 10:43:01 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Out(PlayerActionEvent caller) {}
|
2022-03-03 10:43:01 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void PickJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
game.bodyAnim.Play("Pick", 0, 0);
|
|
|
|
game.isFlicking = true;
|
|
|
|
if (!pickEligible) return;
|
|
|
|
if (GameManager.instance.autoplay)
|
|
|
|
{
|
|
|
|
PickVeggie(true);
|
|
|
|
return;
|
|
|
|
}
|
2022-03-03 10:43:01 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (state <= -1f || state >= 1f)
|
|
|
|
{
|
|
|
|
veggieState = -1;
|
|
|
|
boinked = true;
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
curve.transform.localScale = Vector3.one; // Return curve to normal size in the case of mole curves.
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
var key1 = curve.KeyPoints[0];
|
|
|
|
var key1Pos = key1.Position;
|
|
|
|
key1.Position = new Vector3(key1Pos.x, veggieTrans.position.y, key1Pos.z);
|
|
|
|
|
|
|
|
var key2 = curve.KeyPoints[1];
|
|
|
|
var key2Pos = key2.Position;
|
|
|
|
key2.Position = new Vector3(key2Pos.x, veggieTrans.position.y + 2f, key2Pos.z);
|
|
|
|
|
|
|
|
pickedBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
|
|
|
|
MissedUpdate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PickVeggie(false);
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void PickMiss(PlayerActionEvent caller)
|
|
|
|
{
|
|
|
|
veggieState = -1;
|
|
|
|
|
|
|
|
if (!isMole)
|
|
|
|
Jukebox.PlayOneShotGame("cropStomp/veggieMiss");
|
|
|
|
caller.Disable();
|
|
|
|
}
|
|
|
|
|
2022-03-03 10:43:01 +00:00
|
|
|
bool moleLaughing;
|
2022-03-01 06:38:38 +00:00
|
|
|
private void MissedUpdate()
|
|
|
|
{
|
|
|
|
if (boinked)
|
|
|
|
{
|
2022-03-03 10:43:01 +00:00
|
|
|
float fallPosition = Conductor.instance.GetPositionFromBeat(pickedBeat, 1f);
|
|
|
|
fallPosition = Mathf.Clamp(fallPosition, 0, 1);
|
|
|
|
veggieTrans.position = curve.GetPoint(fallPosition);
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2022-03-03 10:43:01 +00:00
|
|
|
if (fallPosition < 1f)
|
|
|
|
{
|
|
|
|
var rotSpeed = isMole ? pickedRotationSpeed : -pickedRotationSpeed;
|
|
|
|
veggieTrans.rotation = Quaternion.Euler(0, 0, veggieTrans.rotation.eulerAngles.z + (rotSpeed * Time.deltaTime));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
veggieTrans.rotation = Quaternion.Euler(0, 0, 180f);
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-03 10:43:01 +00:00
|
|
|
if (isMole && !moleLaughing)
|
|
|
|
{
|
|
|
|
var distDiff = transform.position.x - game.farmerTrans.position.x;
|
|
|
|
if (distDiff > 1.5f)
|
|
|
|
{
|
|
|
|
moleAnim.Play("Chuckle", 0, 0);
|
|
|
|
moleLaughing = true;
|
|
|
|
}
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PickedUpdate()
|
|
|
|
{
|
2022-03-03 02:50:08 +00:00
|
|
|
float pickPosition = Conductor.instance.GetPositionFromBeat(pickedBeat, pickTime);
|
2022-03-01 20:57:37 +00:00
|
|
|
pickPosition = Mathf.Clamp(pickPosition, 0, 1);
|
2022-03-03 02:50:08 +00:00
|
|
|
veggieTrans.position = hitCurve.GetPoint(pickPosition);
|
2022-03-01 20:57:37 +00:00
|
|
|
|
2022-03-03 02:50:08 +00:00
|
|
|
var rotSpeed = isMole ? -pickedRotationSpeed : pickedRotationSpeed;
|
|
|
|
veggieTrans.rotation = Quaternion.Euler(0, 0, veggieTrans.rotation.eulerAngles.z + (rotSpeed * Time.deltaTime));
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2022-03-03 02:50:08 +00:00
|
|
|
if (!isMole)
|
|
|
|
{
|
|
|
|
var veggieScale = Mathf.Min(1.5f - pickPosition, 1f);
|
|
|
|
veggieTrans.localScale = Vector2.one * veggieScale;
|
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StompVeggie(bool autoTriggered)
|
|
|
|
{
|
|
|
|
// Juuuuuust in case.
|
|
|
|
if (gotStomped)
|
|
|
|
{
|
|
|
|
Debug.Log("Recursion moment?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gotStomped = true;
|
|
|
|
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
veggieState = 1;
|
2023-01-15 04:33:37 +00:00
|
|
|
game.ScheduleInput(targetBeat, isMole ? 0.5f : 1f, InputType.STANDARD_UP, PickJust, PickMiss, Out);
|
2022-03-01 06:38:38 +00:00
|
|
|
targetBeat = targetBeat + (isMole ? 0.5f : 1f);
|
|
|
|
|
|
|
|
stompedBeat = cond.songPositionInBeats;
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
landBeat = targetBeat + (float)cond.SecsToBeats(Minigame.EndTime()-1, cond.GetBpmAtBeat(targetBeat));
|
2022-03-01 06:38:38 +00:00
|
|
|
|
|
|
|
if (autoTriggered)
|
|
|
|
{
|
|
|
|
game.Stomp();
|
|
|
|
game.bodyAnim.Play("Stomp", 0, 0);
|
|
|
|
}
|
|
|
|
|
2022-03-01 20:57:37 +00:00
|
|
|
if (!isMole)
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
MultiSound.Play(
|
|
|
|
new MultiSound.Sound[] { new MultiSound.Sound("cropStomp/veggieOh", targetBeat - 0.5f) }
|
|
|
|
);
|
2022-03-01 20:57:37 +00:00
|
|
|
}
|
2022-03-03 10:43:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
moleAnim.Play("Idle", 0, 0);
|
|
|
|
}
|
2022-03-01 20:57:37 +00:00
|
|
|
|
|
|
|
var veggieScale = veggieTrans.localScale;
|
|
|
|
veggieTrans.localScale = new Vector3(veggieScale.x * 0.5f, veggieScale.y, veggieScale.z);
|
2022-03-22 18:29:15 +00:00
|
|
|
squashTween = veggieTrans.DOScaleX(veggieScale.x, cond.pitchedSecPerBeat * 0.5f);
|
2022-03-01 20:57:37 +00:00
|
|
|
|
2022-03-01 06:38:38 +00:00
|
|
|
Update(); // Update flying veggie state immediately.
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PickVeggie(bool autoTriggered)
|
|
|
|
{
|
|
|
|
veggieState = 2;
|
|
|
|
|
|
|
|
if (autoTriggered)
|
|
|
|
{
|
|
|
|
game.bodyAnim.Play("Pick", 0, 0);
|
|
|
|
game.isFlicking = true;
|
|
|
|
}
|
2022-03-01 20:57:37 +00:00
|
|
|
|
|
|
|
var key1 = game.pickCurve.KeyPoints[0];
|
|
|
|
var keyPos = key1.Position;
|
|
|
|
key1.Position = new Vector3(keyPos.x, veggieTrans.position.y, keyPos.z);
|
|
|
|
|
|
|
|
pickedBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
|
|
|
if (!isMole)
|
|
|
|
{
|
|
|
|
BeatAction.New(gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(pickedBeat + 0.5f, delegate { veggieSprite.sortingOrder = -1; }),
|
2022-03-03 02:50:08 +00:00
|
|
|
new BeatAction.Action(pickedBeat + pickTime, delegate { GameObject.Destroy(gameObject); })
|
2022-03-01 20:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("cropStomp/veggieKay");
|
2022-03-03 02:50:08 +00:00
|
|
|
|
|
|
|
hitCurve = game.pickCurve;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BeatAction.New(gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(pickedBeat + pickTime, delegate { GameObject.Destroy(gameObject); })
|
|
|
|
});
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("cropStomp/GEUH");
|
|
|
|
|
|
|
|
hitCurve = game.moleCurve;
|
2022-03-01 20:57:37 +00:00
|
|
|
}
|
2022-03-01 06:38:38 +00:00
|
|
|
|
2022-03-01 20:57:37 +00:00
|
|
|
if (squashTween != null)
|
|
|
|
squashTween.Kill(true);
|
2022-03-01 06:38:38 +00:00
|
|
|
|
|
|
|
PickedUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|