HeavenStudio/Assets/Scripts/Games/Flockstep/Flockstep.cs

171 lines
5.6 KiB
C#

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
using HeavenStudio.InputSystem;
using Jukebox;
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
/// Minigame loaders handle the setup of your minigame.
/// Here, you designate the game prefab, define entities, and mark what AssetBundle to load
/// Names of minigame loaders follow a specific naming convention of `PlatformcodeNameLoader`, where:
/// `Platformcode` is a three-leter platform code with the minigame's origin
/// `Name` is a short internal name
/// `Loader` is the string "Loader"
/// Platform codes are as follows:
/// Agb: Gameboy Advance ("Advance Gameboy")
/// Ntr: Nintendo DS ("Nitro")
/// Rvl: Nintendo Wii ("Revolution")
/// Ctr: Nintendo 3DS ("Centrair")
/// Mob: Mobile
/// Pco: PC / Other
/// Fill in the loader class label, "*prefab name*", and "*Display Name*" with the relevant information
/// For help, feel free to reach out to us on our discord, in the #development channel.
public static class RvlFlockstepLoader
{
public static Minigame AddGame(EventCaller eventCaller)
{
return new Minigame("flockstep", "Flock-Step", "ffffff", false, false, new List<GameAction>()
{
new GameAction("bop", "Bop")
{
function = delegate { var e = eventCaller.currentEntity; Flockstep.instance.Bop(e.beat, e.length, e["toggle2"], e["toggle"]); },
resizable = true,
parameters = new List<Param>()
{
new Param("toggle2", true, "Bop", "Toggle if the the Hue Birds should bop for the duration of this event."),
new Param("toggle", false, "Bop (Auto)", "Toggle if the Hue Birds should automatically bop until another Bop event is reached.")
}
},
new GameAction("march", "Stepping")
{
function = delegate {var e = eventCaller.currentEntity; Flockstep.instance.StartStep(e.beat); }, //open to adding more stuff eventually
defaultLength = 1,
},
new GameAction("jump", "Jump")
{
defaultLength = 4f,
},
new GameAction("color", "Birds Color")
{
defaultLength = 0.5f,
},
new GameAction("force", "Force Stepping")
{
resizable = true,
},
}
);
}
}
}
namespace HeavenStudio.Games
{
/// This class handles the minigame logic.
/// Minigame inherits directly from MonoBehaviour, and adds Heaven Studio specific methods to override.
public class Flockstep : Minigame
{
public static Flockstep instance;
bool goBop;
public GameEvent bop = new GameEvent();
[SerializeField] Animator[] allThemOtherBirbs;
[SerializeField] Animator birbPlayer;
int marchIterator;
public override void OnBeatPulse(double beat)
{
if (goBop)
{
PlayBirbAnim("bop", true, 0.5f);
}
}
void PlayBirbAnim(string animName, bool player, float timescale = 1f, float startpos = 0f, int layer = -1)
{
if (player) birbPlayer.DoScaledAnimationAsync(animName, timescale, startpos, layer);
foreach(Animator birb in allThemOtherBirbs)
{
birb.DoScaledAnimationAsync(animName, timescale, startpos, layer);
}
}
public void Bop(double beat, float length, bool shouldBop, bool autoBop)
{
goBop = autoBop;
if (shouldBop)
{
for (int i = 0; i < length; i++)
{
BeatAction.New(instance, new List<BeatAction.Action>()
{
new BeatAction.Action(beat + i, delegate
{
PlayBirbAnim("bop", true, 0.5f);
})
});
}
}
}
public void StartStep(double beat)
{
PlayBirbAnim("startStep", true, 1f);
ScheduleStep(beat);
RecursiveMarching(beat);
}
public void RecursiveMarching(double beat)
{
marchIterator++;
ScheduleStep(beat);
if(marchIterator > 1)
{
print("stop!!");
PlayBirbAnim("marching2", true, 1f);
marchIterator = 0;
}
BeatAction.New(this, new List<BeatAction.Action>() {
new(beat + 1, delegate { RecursiveMarching(beat + 1); })
});
}
// Start is called before the first frame update
void Awake()
{
instance = this;
SetupBopRegion("flockstep", "bop", "toggle");
}
private void ScheduleStep(double beat)
{
PlayerActionEvent input = ScheduleInput(beat, 1f, InputAction_BasicPress, Success, Miss, Nothing);
}
public void Success(PlayerActionEvent caller, float state)
{
// man.Step();
// if (state is >= 1f or <= -1f) SoundByte.PlayOneShot("nearMiss");
}
public void Miss(PlayerActionEvent caller)
{
// man.Fall();
}
public void Nothing(PlayerActionEvent caller) { }
}
}