HeavenStudioPlus/Assets/Scripts/Games/CropStomp/Farmer.cs
minenice55 3002e48350
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

155 lines
5.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
using System;
namespace HeavenStudio.Games.Scripts_CropStomp
{
public class Farmer : MonoBehaviour
{
public double nextStompBeat;
private CropStomp game;
PlayerActionEvent stomp;
[SerializeField] private Transform collectedHolder;
[SerializeField] private GameObject plantLeftRef;
[SerializeField] private GameObject plantRightRef;
[SerializeField] private GameObject plantLastRef;
[SerializeField] private Sprite[] veggieSprites;
[SerializeField] private GameObject startPlant;
private List<GameObject> spawnedPlants = new List<GameObject>();
private int lastVeggieType;
[SerializeField] private float plantDistance = 0.5f;
[SerializeField] private float plantStartDistance = 0.1f;
[NonSerialized] public int plantThreshold = 8;
[NonSerialized] public int plantLimit = 80;
public static int collectedPlants = 0;
private void OnDestroy()
{
if (!Conductor.instance.isPlaying)
{
collectedPlants = 0;
UpdatePlants();
}
}
public void Init()
{
game = CropStomp.instance;
if (!Conductor.instance.isPlaying)
{
collectedPlants = 0;
}
UpdatePlants();
}
private void Update()
{
if (!game.isMarching)
return;
Conductor cond = Conductor.instance;
if (stomp == null && cond.isPlaying)
{
if (GameManager.instance.currentGame == "cropStomp")
{
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, CropStomp.InputAction_BasicPress, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
}
if (PlayerInput.GetIsAction(CropStomp.InputAction_BasicPress) && !game.IsExpectingInputNow(CropStomp.InputAction_BasicPress))
{
game.bodyAnim.Play("Crouch", 0, 0);
}
}
public void CollectPlant(int veggieType)
{
if (collectedPlants > plantLimit) return;
if (collectedPlants <= plantLimit - plantThreshold) lastVeggieType = veggieType;
collectedPlants++;
UpdatePlants();
}
public void UpdatePlants()
{
startPlant.SetActive(collectedPlants >= plantThreshold);
if (spawnedPlants.Count > 0)
{
foreach (var plant in spawnedPlants)
{
Destroy(plant);
}
spawnedPlants.Clear();
}
for (int i = 0; i <= collectedPlants - (plantThreshold * 2) && i <= plantLimit - (plantThreshold * 2); i += plantThreshold)
{
bool isLast = i == plantLimit - (plantThreshold * 2);
int realIndex = i / plantThreshold;
GameObject spawnedPlant;
if (isLast)
{
spawnedPlant = Instantiate(plantLastRef, collectedHolder);
spawnedPlant.GetComponent<SpriteRenderer>().sprite = veggieSprites[lastVeggieType];
}
else spawnedPlant = Instantiate((realIndex % 2 == 0) ? plantRightRef : plantLeftRef, collectedHolder);
spawnedPlant.transform.localPosition = new Vector3(0, (realIndex * plantDistance) + plantStartDistance, 0);
spawnedPlant.GetComponent<SpriteRenderer>().sortingOrder = -realIndex - 2;
spawnedPlant.SetActive(true);
spawnedPlants.Add(spawnedPlant);
}
}
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, CropStomp.InputAction_BasicPress, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
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
{
game.Stomp();
game.bodyAnim.Play("Stomp", 0, 0);
}
nextStompBeat += 2f;
stomp?.Disable();
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, CropStomp.InputAction_BasicPress, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
}
}