2022-02-28 08:33:11 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-28 08:33:11 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_CropStomp
|
2022-02-28 08:33:11 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
public class Farmer : MonoBehaviour
|
2022-02-28 08:33:11 +00:00
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
public double nextStompBeat;
|
2022-02-28 08:33:11 +00:00
|
|
|
|
|
|
|
private CropStomp game;
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
PlayerActionEvent stomp;
|
|
|
|
|
2023-06-06 18:59:56 +00:00
|
|
|
[SerializeField] private Transform collectedHolder;
|
|
|
|
|
|
|
|
[SerializeField] private GameObject plantLeftRef;
|
|
|
|
[SerializeField] private GameObject plantRightRef;
|
|
|
|
private List<GameObject> spawnedPlants = new List<GameObject>();
|
|
|
|
|
|
|
|
[SerializeField] private float plantDistance = 0.5f;
|
|
|
|
|
|
|
|
public int plantThreshold = 8;
|
|
|
|
|
|
|
|
public int plantLimit = 80;
|
|
|
|
|
|
|
|
private static int collectedPlants = 0;
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
if (!Conductor.instance.isPlaying)
|
|
|
|
{
|
|
|
|
collectedPlants = 0;
|
|
|
|
UpdatePlants();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
public void Init()
|
2022-02-28 08:33:11 +00:00
|
|
|
{
|
|
|
|
game = CropStomp.instance;
|
2023-06-06 18:59:56 +00:00
|
|
|
if (!Conductor.instance.isPlaying)
|
|
|
|
{
|
|
|
|
collectedPlants = 0;
|
|
|
|
}
|
|
|
|
UpdatePlants();
|
2022-02-28 08:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!game.isMarching)
|
|
|
|
return;
|
2023-01-15 04:33:37 +00:00
|
|
|
Conductor cond = Conductor.instance;
|
2022-02-28 08:33:11 +00:00
|
|
|
|
2023-01-19 02:31:08 +00:00
|
|
|
if (stomp == null && cond.isPlaying)
|
2023-01-15 04:33:37 +00:00
|
|
|
{
|
|
|
|
if (GameManager.instance.currentGame == "cropStomp")
|
2023-01-25 03:54:19 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
|
2023-01-25 03:54:19 +00:00
|
|
|
stomp.countsForAccuracy = false;
|
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
2022-02-28 08:33:11 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
|
2022-02-28 08:33:11 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
game.bodyAnim.Play("Crouch", 0, 0);
|
2022-02-28 08:33:11 +00:00
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
2022-02-28 08:33:11 +00:00
|
|
|
|
2023-06-06 18:59:56 +00:00
|
|
|
public void CollectPlant()
|
|
|
|
{
|
|
|
|
if (collectedPlants >= plantLimit) return;
|
|
|
|
collectedPlants++;
|
|
|
|
UpdatePlants();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdatePlants()
|
|
|
|
{
|
|
|
|
if (spawnedPlants.Count > 0)
|
|
|
|
{
|
|
|
|
foreach (var plant in spawnedPlants)
|
|
|
|
{
|
|
|
|
Destroy(plant);
|
|
|
|
}
|
|
|
|
spawnedPlants.Clear();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < collectedPlants && i < plantLimit; i += plantThreshold)
|
|
|
|
{
|
|
|
|
GameObject spawnedPlant = Instantiate(((i / plantThreshold) % 2 == 0) ? plantRightRef : plantLeftRef, collectedHolder);
|
|
|
|
spawnedPlant.transform.localPosition = new Vector3(0, (i / plantThreshold) * plantDistance + plantDistance, 0);
|
|
|
|
spawnedPlant.GetComponent<SpriteRenderer>().sortingOrder = (i / plantThreshold) - 2;
|
|
|
|
spawnedPlant.SetActive(true);
|
|
|
|
spawnedPlants.Add(spawnedPlant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Just(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
// REMARK: does not count for performance
|
|
|
|
Stomp(state >= 1f || state <= -1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Miss(PlayerActionEvent caller)
|
|
|
|
{
|
|
|
|
if (GameManager.instance.currentGame != "cropStomp") return;
|
|
|
|
if (!game.isMarching)
|
|
|
|
return;
|
|
|
|
// REMARK: does not count for performance
|
|
|
|
nextStompBeat += 2f;
|
|
|
|
stomp?.Disable();
|
|
|
|
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
|
2023-01-25 03:54:19 +00:00
|
|
|
stomp.countsForAccuracy = false;
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Out(PlayerActionEvent caller) {}
|
|
|
|
|
|
|
|
void Stomp(bool ng)
|
|
|
|
{
|
|
|
|
if (GameManager.instance.currentGame != "cropStomp") return;
|
|
|
|
if (!game.isMarching)
|
|
|
|
return;
|
|
|
|
if (ng)
|
|
|
|
{
|
|
|
|
game.bodyAnim.Play("Crouch", 0, 0);
|
|
|
|
}
|
|
|
|
else
|
2022-02-28 08:33:11 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
game.Stomp();
|
|
|
|
game.bodyAnim.Play("Stomp", 0, 0);
|
2023-06-06 18:59:56 +00:00
|
|
|
|
2022-02-28 08:33:11 +00:00
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
nextStompBeat += 2f;
|
|
|
|
stomp?.Disable();
|
|
|
|
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
|
2023-01-25 03:54:19 +00:00
|
|
|
stomp.countsForAccuracy = false;
|
2022-02-28 08:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|