mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-15 22:25:07 +00:00
b1fab52ad9
* add Jukebox library todo: - saving / loading of new format - inferrence of unknown data like past versions - move the temporary float casts to proper use of double - make sound related functions take double for timing - inform people that the Jukebox sound player was renamed to SoundByte lol * make sound, input scheduling, and super curve use double precision * successfully load charts * editor works again v1 riqs can be saved and loaded * first tempo and volume markers are unmovable fix loading of charts' easing values * use gsync / freesync * update Jukebox refs to SoundByte * game events use double part 1 Air Rally - Glee Club converted * don't load song if chart load fails * finish conversion of all minigames * remove editor waveform toggle * timeline now respects added song offset length clear cache files on app close prepped notes for dsp sync * update timeline length when offset changed * update to latest Jukebox * make error panel object in global game manager * improve conductor music scheduling * added error message box fix first game events sometimes not playing
139 lines
4.1 KiB
C#
139 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
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;
|
|
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();
|
|
}
|
|
}
|
|
|
|
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, InputType.STANDARD_DOWN, Just, Miss, Out);
|
|
stomp.countsForAccuracy = false;
|
|
}
|
|
}
|
|
|
|
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
|
|
{
|
|
game.bodyAnim.Play("Crouch", 0, 0);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
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, InputType.STANDARD_DOWN, Just, Miss, Out);
|
|
stomp.countsForAccuracy = false;
|
|
}
|
|
}
|
|
}
|