Crop Stomp Fix + Fork Lifter Animation Tweak (#588)

* fork lifter weird reset thingy fixed

* crop stomp code review

im gonna be fixing that weird bug where inputs aren't scheduled if crop stomp is the first game (or if you start on it) but first
some of the code in this is nearly two years old. it needed a lot of check-ups.

* oh okay that bug was really easy to fix

* convert animation playing to beat scaled playing

* crop stomp fix
This commit is contained in:
AstrlJelly 2023-12-05 17:38:55 -05:00 committed by GitHub
parent 2abfaf87bb
commit c18113de99
5 changed files with 152 additions and 278 deletions

View file

@ -98,6 +98,15 @@ AnimationClip:
- serializedVersion: 3 - serializedVersion: 3
time: 0.35 time: 0.35
value: {x: 0.017, y: 0.261, z: 74.52776} value: {x: 0.017, y: 0.261, z: 74.52776}
inSlope: {x: 2.7443511, y: -2.188788, z: 0}
outSlope: {x: 2.7443511, y: -2.188788, z: 0}
tangentMode: 0
weightedMode: 0
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 0.4
value: {x: 0.1744351, y: 0.1891212, z: 74.52776}
inSlope: {x: 0, y: 0, z: 0} inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0 tangentMode: 0
@ -192,59 +201,6 @@ AnimationClip:
classID: 1 classID: 1
script: {fileID: 0} script: {fileID: 0}
m_PPtrCurves: m_PPtrCurves:
- curve:
- time: 0
value: {fileID: 0}
- time: 0.016666668
value: {fileID: 0}
- time: 0.033333335
value: {fileID: 0}
- time: 0.05
value: {fileID: 0}
- time: 0.06666667
value: {fileID: 0}
- time: 0.083333336
value: {fileID: 0}
- time: 0.1
value: {fileID: 0}
- time: 0.11666667
value: {fileID: 0}
- time: 0.13333334
value: {fileID: 0}
- time: 0.15
value: {fileID: 0}
- time: 0.16666667
value: {fileID: 0}
- time: 0.18333334
value: {fileID: 0}
- time: 0.2
value: {fileID: 0}
- time: 0.21666667
value: {fileID: 0}
- time: 0.23333333
value: {fileID: 0}
- time: 0.25
value: {fileID: 0}
- time: 0.26666668
value: {fileID: 0}
- time: 0.28333333
value: {fileID: 0}
- time: 0.3
value: {fileID: 0}
- time: 0.31666666
value: {fileID: 0}
- time: 0.33333334
value: {fileID: 0}
- time: 0.35
value: {fileID: 0}
- time: 0.36666667
value: {fileID: 0}
- time: 0.38333333
value: {fileID: 0}
attribute: m_Sprite
path: Fork_Lifter_Gameplay
classID: 212
script: {fileID: 0}
- curve: - curve:
- time: 0 - time: 0
value: {fileID: -4922902375269903740, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3} value: {fileID: -4922902375269903740, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3}
@ -307,13 +263,6 @@ AnimationClip:
typeID: 1 typeID: 1
customType: 0 customType: 0
isPPtrCurve: 0 isPPtrCurve: 0
- serializedVersion: 2
path: 345648135
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
- serializedVersion: 2 - serializedVersion: 2
path: 3267382320 path: 3267382320
attribute: 0 attribute: 0
@ -336,30 +285,6 @@ AnimationClip:
customType: 0 customType: 0
isPPtrCurve: 0 isPPtrCurve: 0
pptrCurveMapping: pptrCurveMapping:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: -4922902375269903740, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3} - {fileID: -4922902375269903740, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3}
- {fileID: -3456084564025576355, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3} - {fileID: -3456084564025576355, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3}
- {fileID: -3456084564025576355, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3} - {fileID: -3456084564025576355, guid: 52117e1d5cd298c42adfea952676c7d6, type: 3}
@ -688,6 +613,15 @@ AnimationClip:
- serializedVersion: 3 - serializedVersion: 3
time: 0.35 time: 0.35
value: 0.017 value: 0.017
inSlope: 2.7443511
outSlope: 2.7443511
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.4
value: 0.1744351
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -716,6 +650,15 @@ AnimationClip:
- serializedVersion: 3 - serializedVersion: 3
time: 0.35 time: 0.35
value: 0.261 value: 0.261
inSlope: -2.188788
outSlope: -2.188788
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.4
value: 0.1891212
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136

View file

@ -16,13 +16,13 @@ namespace HeavenStudio.Games.Loaders
{ {
new GameAction("start marching", "Start Marching") new GameAction("start marching", "Start Marching")
{ {
function = delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, function = delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); },
defaultLength = 2f, defaultLength = 2f,
inactiveFunction = delegate { CropStomp.MarchInactive(eventCaller.currentEntity.beat); } inactiveFunction = delegate { CropStomp.MarchInactive(eventCaller.currentEntity.beat); }
}, },
new GameAction("veggies", "Veggies") new GameAction("veggies", "Veggies")
{ {
defaultLength = 4f, defaultLength = 4f,
resizable = true resizable = true
}, },
new GameAction("mole", "Mole") new GameAction("mole", "Mole")
@ -49,7 +49,8 @@ namespace HeavenStudio.Games.Loaders
new GameAction("plantCollect", "Veggie Collection Values") new GameAction("plantCollect", "Veggie Collection Values")
{ {
function = delegate { var e = eventCaller.currentEntity; function = delegate { var e = eventCaller.currentEntity;
CropStomp.instance.SetCollectThresholds(e["threshold"], e["limit"], e["force"], e["forceAmount"]); }, CropStomp.instance.SetCollectThresholds(e["threshold"], e["limit"], e["force"], e["forceAmount"]);
},
defaultLength = 0.5f, defaultLength = 0.5f,
parameters = new List<Param>() parameters = new List<Param>()
{ {
@ -125,43 +126,34 @@ namespace HeavenStudio.Games
private void Awake() private void Awake()
{ {
instance = this;// Finding grass sprite width for grass scrolling. instance = this; // Finding grass sprite width for grass scrolling.
farmer.Init(); farmer.Init();
var grassSprite = grass.sprite; Sprite sprite = grass.sprite;
var borderLeft = grassSprite.rect.xMin + grassSprite.border.x; float borderLeft = sprite.rect.xMin + sprite.border.x;
var borderRight = grassSprite.rect.xMax - grassSprite.border.z; float borderRight = sprite.rect.xMax - sprite.border.z;
var borderWidthPixels = borderRight - borderLeft; float borderWidthPixels = borderRight - borderLeft;
grassWidth = borderWidthPixels / grassSprite.pixelsPerUnit; grassWidth = borderWidthPixels / sprite.pixelsPerUnit;
legsAnim.Play("LiftFront", 0, 1); // Start with leg up. legsAnim.Play("LiftFront", 0, 1); // Start with leg up.
}
// Initialize vegetables. public override void OnGameSwitch(double beat)
var cond = Conductor.instance; {
var entities = GameManager.instance.Beatmap.Entities; double startBeat;
double startBeat = cond.songPositionInBeatsAsDouble;
double endBeat = double.MaxValue; double endBeat = double.MaxValue;
var entities = GameManager.instance.Beatmap.Entities;
if (inactiveStart == -1f) if (inactiveStart == -1f)
{ {
// Find the beat of the closest "start marching" event. // Find the beat of the closest "start marching" event.
var marchStarts = entities.FindAll(m => m.datamodel == "cropStomp/start marching"); var lastMarch = entities.Find(c => c.datamodel == "cropStomp/start marching" && beat <= c.beat);
for (int i = 0; i < marchStarts.Count; i++) startBeat = lastMarch?.beat ?? beat;
{
var sampleBeat = marchStarts[i].beat;
if (cond.songPositionInBeatsAsDouble <= sampleBeat + 0.25f) // 0.25-beat buffer in case the start marching event is directly next to the game switch event.
{
startBeat = sampleBeat;
break;
}
}
} }
else else
{ {
// Find the beat of the next step, assuming marching started at inactiveStart. // Find the beat of the next step, assuming marching started at inactiveStart.
int stepsPassed = 0; int stepsPassed = 0;
while (inactiveStart + (stepsPassed * 2f) < cond.songPositionInBeatsAsDouble) while (inactiveStart + (stepsPassed * 2f) < beat)
{ {
stepsPassed++; stepsPassed++;
@ -175,54 +167,31 @@ namespace HeavenStudio.Games
startBeat = inactiveStart + (stepsPassed * 2f); startBeat = inactiveStart + (stepsPassed * 2f);
// Cue the marching proper to begin when applicable. // Cue the marching proper to begin when applicable.
BeatAction.New(this, new List<BeatAction.Action>() BeatAction.New(this, new() { new(startBeat - 0.25f, delegate { StartMarching(startBeat); }) });
{
new BeatAction.Action(startBeat - 0.25f, delegate { StartMarching(startBeat); })
});
inactiveStart = -1f; inactiveStart = -1f;
} }
// find out when the next game switch (or remix end) happens // find out when the next game switch (or remix end) happens
var allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }); RiqEntity firstEnd = entities.Find(c => c.datamodel is "gameManager/switchGame/cropStomp" or "gameManager/end" && c.beat > startBeat);
if (allEnds.Count == 0) endBeat = firstEnd?.beat ?? double.MaxValue;
{
endBeat = double.MaxValue;
}
else
{
allEnds.Sort((x, y) => x.beat.CompareTo(y.beat));
//get the beat of the closest end event
foreach (var end in allEnds)
{
if (end.datamodel != "gameManager/end" && end.datamodel.Split(2) == "cropStomp") continue;
if (end.beat > startBeat)
{
endBeat = end.beat;
break;
}
}
}
// Veggie and mole events. // Veggie and mole events.
var vegEvents = entities.FindAll(v => v.datamodel == "cropStomp/veggies"); List<RiqEntity> vegEvents = entities.FindAll(v => v.datamodel == "cropStomp/veggies");
var moleEvents = entities.FindAll(m => m.datamodel == "cropStomp/mole"); List<RiqEntity> moleEvents = entities.FindAll(m => m.datamodel == "cropStomp/mole");
// Spawn veggies. // Spawn veggies.
for (int i = 0; i < vegEvents.Count; i++) for (int i = 0; i < vegEvents.Count; i++) {
{
var vegBeat = vegEvents[i].beat; var vegBeat = vegEvents[i].beat;
var vegLength = vegEvents[i].length; var vegLength = vegEvents[i].length;
// Only consider veggie events that aren't past the start point. // Only consider veggie events that aren't past the start point.
if (startBeat <= vegBeat + vegLength) if (startBeat <= vegBeat + vegLength) {
{
int veggiesInEvent = Mathf.CeilToInt(vegLength + 1) / 2; int veggiesInEvent = Mathf.CeilToInt(vegLength + 1) / 2;
for (int b = 0; b < veggiesInEvent; b++) for (int b = 0; b < veggiesInEvent; b++)
{ {
var targetVeggieBeat = vegBeat + 2f * b; var targetVeggieBeat = vegBeat + (2f * b);
if (startBeat <= targetVeggieBeat && targetVeggieBeat < endBeat) if (startBeat <= targetVeggieBeat && targetVeggieBeat < endBeat)
{ {
SpawnVeggie(targetVeggieBeat, startBeat, false); SpawnVeggie(targetVeggieBeat, startBeat, false);
@ -232,52 +201,40 @@ namespace HeavenStudio.Games
} }
// Spawn moles. // Spawn moles.
for (int i = 0; i < moleEvents.Count; i++) for (int i = 0; i < moleEvents.Count; i++) {
{
var moleBeat = moleEvents[i].beat; var moleBeat = moleEvents[i].beat;
if (startBeat <= moleBeat && moleBeat < endBeat) if (startBeat <= moleBeat && moleBeat < endBeat) {
{
SpawnVeggie(moleBeat, startBeat, true); SpawnVeggie(moleBeat, startBeat, true);
} }
} }
}
List<RiqEntity> cuedMoleSounds = new List<RiqEntity>();
public override void OnGameSwitch(double beat)
{
SetInitTresholds(beat); SetInitTresholds(beat);
SetMarchEndBeat(beat); SetMarchEndBeat(beat);
} }
public override void OnPlay(double beat) public override void OnPlay(double beat)
{ {
SetInitTresholds(beat); OnGameSwitch(beat);
SetMarchEndBeat(beat);
} }
private void SetMarchEndBeat(double beat) private void SetMarchEndBeat(double beat)
{ {
double nextEndBeat = double.MaxValue;
var nextEnd = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }).Find(e => e.beat > beat); var nextEnd = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }).Find(e => e.beat > beat);
if (nextEnd != null) nextEndBeat = nextEnd.beat; double nextEndBeat = nextEnd?.beat ?? double.MaxValue;
var allEnds = EventCaller.GetAllInGameManagerList("cropStomp", new string[] { "end" }); var firstEnd = GameManager.instance.Beatmap.Entities.Find(c => c.datamodel == "cropStomp/end" && c.beat >= beat && c.beat < nextEndBeat);
var tempEnds = allEnds.FindAll(x => x.beat >= beat && x.beat < nextEndBeat); if (firstEnd != null) {
if (tempEnds.Count == 0) return; marchEndBeat = firstEnd.beat;
willNotHum = firstEnd["mute"];
marchEndBeat = tempEnds[0].beat; }
willNotHum = tempEnds[0]["mute"];
} }
public static void MoleSound(double beat) public static void MoleSound(double beat)
{ {
MultiSound.Play(new MultiSound.Sound[] MultiSound.Play(new MultiSound.Sound[] {
{ new MultiSound.Sound("cropStomp/moleNyeh", beat - 2, offset: 0.134),
new MultiSound.Sound("cropStomp/moleNyeh", beat - 2, 1, 1, false, 0.134), new MultiSound.Sound("cropStomp/moleHeh1", beat - 1.5, offset: 0.05),
new MultiSound.Sound("cropStomp/moleHeh1", beat - 1.5, 1, 1, false, 0.05), new MultiSound.Sound("cropStomp/moleHeh2", beat - 1, offset: 0.061)
new MultiSound.Sound("cropStomp/moleHeh2", beat - 1, 1, 1, false, 0.061)
}, forcePlay: true); }, forcePlay: true);
} }
@ -285,11 +242,8 @@ namespace HeavenStudio.Games
{ {
var cond = Conductor.instance; var cond = Conductor.instance;
if (!cond.isPlaying) if (!cond.isPlaying || !isMarching) return;
return;
if (!isMarching)
return;
// Debug.Log(newBeat); // Debug.Log(newBeat);
bool cameraLocked = cond.songPositionInBeats >= marchEndBeat; bool cameraLocked = cond.songPositionInBeats >= marchEndBeat;
@ -308,11 +262,11 @@ namespace HeavenStudio.Games
if (PlayerInput.GetIsAction(InputAction_BasicRelease) && !IsExpectingInputNow(InputAction_BasicRelease)) if (PlayerInput.GetIsAction(InputAction_BasicRelease) && !IsExpectingInputNow(InputAction_BasicRelease))
{ {
bodyAnim.Play("Raise"); bodyAnim.DoScaledAnimationAsync("Raise", 0.5f);
} }
if (PlayerInput.GetIsAction(InputAction_Flick) && !IsExpectingInputNow(InputAction_FlickRelease)) if (PlayerInput.GetIsAction(InputAction_Flick) && !IsExpectingInputNow(InputAction_FlickRelease))
{ {
bodyAnim.Play("Pick"); bodyAnim.DoScaledAnimationAsync("Pick", 0.5f);
} }
if (cameraLocked) return; if (cameraLocked) return;
@ -326,7 +280,7 @@ namespace HeavenStudio.Games
var grassPos = grassTrans.localPosition; var grassPos = grassTrans.localPosition;
var newGrassX = grassPos.x + (scrollRate * Time.deltaTime); var newGrassX = grassPos.x + (scrollRate * Time.deltaTime);
newGrassX = (newGrassX % (grassWidth * 4.5f)); newGrassX %= grassWidth * 4.5f;
grassTrans.localPosition = new Vector3(newGrassX, grassPos.y, grassPos.z); grassTrans.localPosition = new Vector3(newGrassX, grassPos.y, grassPos.z);
@ -334,16 +288,14 @@ namespace HeavenStudio.Games
var dotsPos = dotsTrans.localPosition; var dotsPos = dotsTrans.localPosition;
var newDotsX = dotsPos.x + (scrollRate * Time.deltaTime); var newDotsX = dotsPos.x + (scrollRate * Time.deltaTime);
newDotsX = (newDotsX % dotsWidth); newDotsX %= dotsWidth;
dotsTrans.localPosition = new Vector3(newDotsX, dotsPos.y, dotsPos.z); dotsTrans.localPosition = new Vector3(newDotsX, dotsPos.y, dotsPos.z);
} }
private void LateUpdate() private void LateUpdate()
{ {
if (!isMarching) if (!isMarching) return;
return;
isFlicking = false; isFlicking = false;
} }
@ -357,12 +309,9 @@ namespace HeavenStudio.Games
private void SetInitTresholds(double beat) private void SetInitTresholds(double beat)
{ {
var allCollects = EventCaller.GetAllInGameManagerList("cropStomp", new string[] { "plantCollect" }); var lastCollect = GameManager.instance.Beatmap.Entities.FindLast(c => c.datamodel == "cropStomp/plantCollect" && c.beat < beat);
if (allCollects.Count == 0) return; if (lastCollect == null) return;
SetCollectThresholds(lastCollect["threshold"], lastCollect["limit"], lastCollect["force"], lastCollect["forceAmount"]);
var tempCollect = allCollects.FindLast(x => x.beat < beat);
if (tempCollect == null) return;
SetCollectThresholds(tempCollect["threshold"], tempCollect["limit"], tempCollect["force"], tempCollect["forceAmount"]);
} }
public void CollectPlant(int veggieType) public void CollectPlant(int veggieType)
@ -379,19 +328,18 @@ namespace HeavenStudio.Games
if (!isStepping) if (!isStepping)
{ {
stepCount += 1; stepCount += 1;
var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack");
legsAnim.Play(stepAnim, 0, 0); var stepAnim = (stepCount % 2 != 0) ? "StepFront" : "StepBack";
legsAnim.DoScaledAnimationAsync(stepAnim, 0.5f);
isStepping = true; isStepping = true;
} }
} }
// Lift. // Lift.
else else
{ {
var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront"); var liftAnim = (stepCount % 2 != 0) ? "LiftBack" : "LiftFront";
legsAnim.Play(liftAnim, 0, 0); legsAnim.DoScaledAnimationAsync(liftAnim, 0.5f);
var farmerPos = farmerTrans.localPosition; var farmerPos = farmerTrans.localPosition;
farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z); farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z);
@ -413,27 +361,28 @@ namespace HeavenStudio.Games
public void Stomp() public void Stomp()
{ {
// Don't increment step counter if autostep stepped already. // Don't increment step counter if autostep stepped already.
if (!isStepping) if (!isStepping) stepCount += 1;
stepCount += 1;
var stompAnim = (stepCount % 2 != 0 ? "StompFront" : "StompBack"); var stompAnim = (stepCount % 2 != 0) ? "StompFront" : "StompBack";
legsAnim.Play(stompAnim, 0, 0); legsAnim.DoScaledAnimationAsync(stompAnim, 0.5f);
SoundByte.PlayOneShotGame("cropStomp/stomp"); SoundByte.PlayOneShotGame("cropStomp/stomp");
if (shakeTween != null) if (shakeTween != null) shakeTween.Kill(true);
shakeTween.Kill(true);
DOTween.Punch(() => GameCamera.AdditionalPosition, x => GameCamera.AdditionalPosition = x, new Vector3(0, 0.75f, 0), DOTween.Punch(() =>
Conductor.instance.pitchedSecPerBeat*0.5f, 18, 1f); GameCamera.AdditionalPosition,
x => GameCamera.AdditionalPosition = x,
new Vector3(0, 0.75f, 0), Conductor.instance.pitchedSecPerBeat * 0.5f, 18, 1f
);
isStepping = true; isStepping = true;
} }
private void SpawnVeggie(double beat, double startBeat, bool isMole) private void SpawnVeggie(double beat, double startBeat, bool isMole)
{ {
var newVeggie = GameObject.Instantiate(isMole ? baseMole : baseVeggie, veggieHolder).GetComponent<Veggie>(); var newVeggie = Instantiate(isMole ? baseMole : baseVeggie, veggieHolder).GetComponent<Veggie>();
newVeggie.targetBeat = beat; newVeggie.targetBeat = beat;
@ -445,21 +394,16 @@ namespace HeavenStudio.Games
public static void MarchInactive(double beat) public static void MarchInactive(double beat)
{ {
if (GameManager.instance.currentGame == "cropStomp") //this function is only meant for making march sounds while the game is inactive if (GameManager.instance.currentGame == "cropStomp") return;
{
return;
}
inactiveStart = beat; inactiveStart = beat;
RiqEntity gameSwitch = GameManager.instance.Beatmap.Entities.Find(c => c.beat >= beat && c.datamodel == "gameManager/switchGame/cropStomp"); RiqEntity gameSwitch = GameManager.instance.Beatmap.Entities.Find(c => c.beat >= beat && c.datamodel == "gameManager/switchGame/cropStomp");
if (gameSwitch == null) if (gameSwitch == null) return;
return; int length = (int)Math.Ceiling((gameSwitch.beat - beat) / 2);
int length = (int)Math.Ceiling((gameSwitch.beat - beat)/2);
MultiSound.Sound[] sounds = new MultiSound.Sound[length]; MultiSound.Sound[] sounds = new MultiSound.Sound[length];
for(int i = 0; i < length; i++) for(int i = 0; i < length; i++) {
{ sounds[i] = new MultiSound.Sound("cropStomp/hmm", beat + (i * 2));
sounds[i] = new MultiSound.Sound("cropStomp/hmm", beat + i*2);
} }
MultiSound.Play(sounds, forcePlay:true); MultiSound.Play(sounds, forcePlay: true);
} }
} }
} }

View file

@ -70,7 +70,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
if (PlayerInput.GetIsAction(CropStomp.InputAction_BasicPress) && !game.IsExpectingInputNow(CropStomp.InputAction_BasicPress)) if (PlayerInput.GetIsAction(CropStomp.InputAction_BasicPress) && !game.IsExpectingInputNow(CropStomp.InputAction_BasicPress))
{ {
game.bodyAnim.Play("Crouch", 0, 0); game.bodyAnim.DoScaledAnimationAsync("Crouch", 0.5f);
} }
} }
@ -87,8 +87,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
startPlant.SetActive(collectedPlants >= plantThreshold); startPlant.SetActive(collectedPlants >= plantThreshold);
if (spawnedPlants.Count > 0) if (spawnedPlants.Count > 0)
{ {
foreach (var plant in spawnedPlants) foreach (var plant in spawnedPlants) {
{
Destroy(plant); Destroy(plant);
} }
spawnedPlants.Clear(); spawnedPlants.Clear();
@ -102,8 +101,9 @@ namespace HeavenStudio.Games.Scripts_CropStomp
{ {
spawnedPlant = Instantiate(plantLastRef, collectedHolder); spawnedPlant = Instantiate(plantLastRef, collectedHolder);
spawnedPlant.GetComponent<SpriteRenderer>().sprite = veggieSprites[lastVeggieType]; spawnedPlant.GetComponent<SpriteRenderer>().sprite = veggieSprites[lastVeggieType];
} else {
spawnedPlant = Instantiate((realIndex % 2 == 0) ? plantRightRef : plantLeftRef, collectedHolder);
} }
else spawnedPlant = Instantiate((realIndex % 2 == 0) ? plantRightRef : plantLeftRef, collectedHolder);
spawnedPlant.transform.localPosition = new Vector3(0, (realIndex * plantDistance) + plantStartDistance, 0); spawnedPlant.transform.localPosition = new Vector3(0, (realIndex * plantDistance) + plantStartDistance, 0);
spawnedPlant.GetComponent<SpriteRenderer>().sortingOrder = -realIndex - 2; spawnedPlant.GetComponent<SpriteRenderer>().sortingOrder = -realIndex - 2;
spawnedPlant.SetActive(true); spawnedPlant.SetActive(true);
@ -119,9 +119,8 @@ namespace HeavenStudio.Games.Scripts_CropStomp
private void Miss(PlayerActionEvent caller) private void Miss(PlayerActionEvent caller)
{ {
if (GameManager.instance.currentGame != "cropStomp") return; if (GameManager.instance.currentGame != "cropStomp" || !game.isMarching) return;
if (!game.isMarching)
return;
// REMARK: does not count for performance // REMARK: does not count for performance
nextStompBeat += 2f; nextStompBeat += 2f;
stomp?.Disable(); stomp?.Disable();
@ -133,18 +132,12 @@ namespace HeavenStudio.Games.Scripts_CropStomp
void Stomp(bool ng) void Stomp(bool ng)
{ {
if (GameManager.instance.currentGame != "cropStomp") return; if (GameManager.instance.currentGame != "cropStomp" || !game.isMarching) return;
if (!game.isMarching) if (ng) {
return; game.bodyAnim.DoScaledAnimationAsync("Crouch", 0.5f);
if (ng) } else {
{
game.bodyAnim.Play("Crouch", 0, 0);
}
else
{
game.Stomp(); game.Stomp();
game.bodyAnim.Play("Stomp", 0, 0); game.bodyAnim.DoScaledAnimationAsync("Stomp", 0.5f);
} }
nextStompBeat += 2f; nextStompBeat += 2f;
stomp?.Disable(); stomp?.Disable();

View file

@ -39,7 +39,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
{ {
game = CropStomp.instance; game = CropStomp.instance;
if (Conductor.instance.isPlaying) // if (Conductor.instance.isPlaying)
game.ScheduleInput(targetBeat - 1, 1f, CropStomp.InputAction_BasicPress, StompJust, StompMiss, Out); game.ScheduleInput(targetBeat - 1, 1f, CropStomp.InputAction_BasicPress, StompJust, StompMiss, Out);
if (!isMole) if (!isMole)
@ -56,38 +56,23 @@ namespace HeavenStudio.Games.Scripts_CropStomp
private bool gotStomped; // Safeguard in case nested Update() call breaks. private bool gotStomped; // Safeguard in case nested Update() call breaks.
private void Update() private void Update()
{ {
if (!game.isMarching) if (!game.isMarching) return;
return;
// Veggie missed. Handle missed state. switch (veggieState)
if (veggieState == -1)
{ {
MissedUpdate(); case -1: MissedUpdate(); return;
return; // case 0:
} case 2: PickedUpdate(); return;
case 1:
float airPosition = Conductor.instance.GetPositionFromBeat(stompedBeat, landBeat - stompedBeat);
veggieTrans.position = curve.GetPoint(Mathf.Clamp(airPosition, 0, 1));
// Veggie picked. Handle picked state. if (PlayerInput.GetIsAction(CropStomp.InputAction_FlickRelease) && !game.IsExpectingInputNow(CropStomp.InputAction_FlickRelease))
if (veggieState == 2) {
{ pickEligible = false;
PickedUpdate(); }
return; break;
} // default:
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));
if (PlayerInput.GetIsAction(CropStomp.InputAction_FlickRelease) && !game.IsExpectingInputNow(CropStomp.InputAction_FlickRelease))
{
pickEligible = false;
}
} }
} }
@ -105,17 +90,17 @@ namespace HeavenStudio.Games.Scripts_CropStomp
StompVeggie(false); StompVeggie(false);
} }
private void StompMiss(PlayerActionEvent caller) private void StompMiss(PlayerActionEvent caller)
{ {
veggieState = -1; veggieState = -1;
caller.Disable(); caller.Disable();
} }
private void Out(PlayerActionEvent caller) {} private void Out(PlayerActionEvent caller) { }
private void PickJust(PlayerActionEvent caller, float state) private void PickJust(PlayerActionEvent caller, float state)
{ {
game.bodyAnim.Play("Pick", 0, 0); game.bodyAnim.DoScaledAnimationAsync("Pick", 0.5f);
game.isFlicking = true; game.isFlicking = true;
if (!pickEligible) return; if (!pickEligible) return;
if (GameManager.instance.autoplay) if (GameManager.instance.autoplay)
@ -131,13 +116,20 @@ namespace HeavenStudio.Games.Scripts_CropStomp
curve.transform.localScale = Vector3.one; // Return curve to normal size in the case of mole curves. curve.transform.localScale = Vector3.one; // Return curve to normal size in the case of mole curves.
var key1 = curve.KeyPoints[0]; for (int i = 0; i < 2; i++)
var key1Pos = key1.Position; {
key1.Position = new Vector3(key1Pos.x, veggieTrans.position.y, key1Pos.z); var key = curve.KeyPoints[i];
var keyPos = key.Position;
key.Position = new Vector3(keyPos.x, veggieTrans.position.y + (i * 2), keyPos.z);
}
var key2 = curve.KeyPoints[1]; // var key1 = curve.KeyPoints[0];
var key2Pos = key2.Position; // var key1Pos = key1.Position;
key2.Position = new Vector3(key2Pos.x, veggieTrans.position.y + 2f, key2Pos.z); // 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.songPositionInBeatsAsDouble; pickedBeat = Conductor.instance.songPositionInBeatsAsDouble;
@ -154,9 +146,8 @@ namespace HeavenStudio.Games.Scripts_CropStomp
private void PickMiss(PlayerActionEvent caller) private void PickMiss(PlayerActionEvent caller)
{ {
veggieState = -1; veggieState = -1;
if (!isMole) if (!isMole) SoundByte.PlayOneShotGame("cropStomp/veggieMiss");
SoundByte.PlayOneShotGame("cropStomp/veggieMiss");
caller.Disable(); caller.Disable();
} }
@ -186,7 +177,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
var distDiff = transform.position.x - game.farmerTrans.position.x; var distDiff = transform.position.x - game.farmerTrans.position.x;
if (distDiff > 1.5f) if (distDiff > 1.5f)
{ {
moleAnim.Play("Chuckle", 0, 0); moleAnim.DoScaledAnimationAsync("Chuckle", 0.5f);
moleLaughing = true; moleLaughing = true;
} }
} }
@ -223,6 +214,8 @@ namespace HeavenStudio.Games.Scripts_CropStomp
} }
gotStomped = true; gotStomped = true;
Debug.Log("Stomped!");
var cond = Conductor.instance; var cond = Conductor.instance;
ParticleSystem spawnedHit = Instantiate(game.hitParticle, game.hitParticle.transform.parent); ParticleSystem spawnedHit = Instantiate(game.hitParticle, game.hitParticle.transform.parent);
@ -235,12 +228,12 @@ namespace HeavenStudio.Games.Scripts_CropStomp
stompedBeat = cond.songPositionInBeatsAsDouble; stompedBeat = cond.songPositionInBeatsAsDouble;
landBeat = targetBeat + (float)cond.SecsToBeats(Minigame.NgLateTime()-1, cond.GetBpmAtBeat(targetBeat)); landBeat = targetBeat + (float)cond.SecsToBeats(Minigame.NgLateTime() - 1, cond.GetBpmAtBeat(targetBeat));
if (autoTriggered) if (autoTriggered)
{ {
game.Stomp(); game.Stomp();
game.bodyAnim.Play("Stomp", 0, 0); game.bodyAnim.DoScaledAnimationAsync("Stomp", 0.5f);
} }
if (!isMole) if (!isMole)
@ -251,7 +244,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
} }
else else
{ {
moleAnim.Play("Idle", 0, 0); moleAnim.DoScaledAnimationAsync("Idle", 0.5f);
} }
var veggieScale = veggieTrans.localScale; var veggieScale = veggieTrans.localScale;
@ -267,7 +260,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
if (autoTriggered) if (autoTriggered)
{ {
game.bodyAnim.Play("Pick", 0, 0); game.bodyAnim.DoScaledAnimationAsync("Pick", 0.5f);
game.isFlicking = true; game.isFlicking = true;
} }

View file

@ -124,6 +124,12 @@ namespace HeavenStudio.Games
BackgroundColorUpdate(); BackgroundColorUpdate();
} }
public override void OnPlay(double beat)
{
base.OnPlay(beat);
OnGameSwitch(beat);
}
public override void OnGameSwitch(double beat) public override void OnGameSwitch(double beat)
{ {
base.OnGameSwitch(beat); base.OnGameSwitch(beat);
@ -247,10 +253,5 @@ namespace HeavenStudio.Games
BackgroundColorGrad(lastEventGrad.beat, lastEventGrad.length, lastEventGrad["start"], lastEventGrad["end"], lastEventGrad["ease"]); BackgroundColorGrad(lastEventGrad.beat, lastEventGrad.length, lastEventGrad["start"], lastEventGrad["end"], lastEventGrad["ease"]);
} }
} }
public override void OnPlay(double beat)
{
PersistColor(beat);
}
} }
} }