Fully functional and animated Mr. Upbeat

This commit is contained in:
Carson Kompon
2022-03-06 14:37:50 -05:00
parent bc9bac4ab5
commit 3f2cc123cb
10 changed files with 504 additions and 79 deletions

View File

@ -13,9 +13,9 @@ namespace RhythmHeavenMania.Games.MrUpbeat
[Header("References")]
public GameObject metronome;
public UpbeatMan man;
public GameObject bt;
public GameEvent beat = new GameEvent();
public GameEvent offbeat = new GameEvent();
public bool canGo = false;
public int beatCount = 0;
@ -31,12 +31,14 @@ namespace RhythmHeavenMania.Games.MrUpbeat
canGo = false;
man.stepTimes = 0;
SetInterval(0);
var pos = Conductor.instance.songPositionInBeats;
StartCoroutine(Upbeat(pos - Mathf.Round(pos)));
}
private void Update()
{
List<Beatmap.Entity> gos = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel == "mrUpbeat/go");
for(int i=0; i<gos.Count; i++)
for (int i = 0; i < gos.Count; i++)
{
if ((gos[i].beat - 0.15f) <= Conductor.instance.songPositionInBeats && (gos[i].beat + gos[i].length) - 0.15f > Conductor.instance.songPositionInBeats)
{
@ -53,27 +55,24 @@ namespace RhythmHeavenMania.Games.MrUpbeat
metronome.transform.eulerAngles = new Vector3(0, 0, 270 - Mathf.Cos(Mathf.PI * Conductor.instance.songPositionInBeats) * 75);
}
if (Conductor.instance.ReportBeat(ref beat.lastReportedBeat) && canGo)
if (Conductor.instance.ReportBeat(ref beat.lastReportedBeat))
{
if(beatCount % 2 == 0)
Jukebox.PlayOneShotGame("mrUpbeat/metronomeRight");
else
Jukebox.PlayOneShotGame("mrUpbeat/metronomeLeft");
StartCoroutine(Upbeat());
if (canGo)
{
if (beatCount % 2 == 0)
Jukebox.PlayOneShotGame("mrUpbeat/metronomeRight");
else
Jukebox.PlayOneShotGame("mrUpbeat/metronomeLeft");
beatCount++;
}
if (Conductor.instance.ReportBeat(ref offbeat.lastReportedBeat, 0.25f, true))
{
man.Blip();
if(canGo) man.targetBeat = offbeat.lastReportedBeat + 1f;
Beat(Mathf.Round(Conductor.instance.songPositionInBeats));
}
}
}
public void SetInterval(float beat)
{
beatCount = 0;
offbeat.startBeat = beat;
man.targetBeat = beat + 320f;
man.Idle();
}
@ -82,7 +81,23 @@ namespace RhythmHeavenMania.Games.MrUpbeat
{
beatCount = 0;
}
public void Beat(float beat)
{
beatCount++;
GameObject _beat = Instantiate(bt);
_beat.transform.parent = bt.transform.parent;
_beat.SetActive(true);
UpbeatStep s = _beat.GetComponent<UpbeatStep>();
s.startBeat = beat;
}
private IEnumerator Upbeat(float offset = 0)
{
yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset);
man.Blip();
}
}
}

View File

@ -8,7 +8,7 @@ using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.MrUpbeat
{
public class UpbeatMan : PlayerActionObject
public class UpbeatMan : MonoBehaviour
{
[Header("References")]
public MrUpbeat game;
@ -19,48 +19,18 @@ namespace RhythmHeavenMania.Games.MrUpbeat
public float targetBeat = 0.25f;
public int stepTimes = 0;
private bool stepped = false;
private bool onGround = false;
public GameEvent blip = new GameEvent();
private void Update()
{
float normalizedBeat = Conductor.instance.GetPositionFromMargin(targetBeat, 0.5f);
StateCheck(normalizedBeat);
if(game.canGo && normalizedBeat > Minigame.LateTime())
{
if ((game.beatCount % 2 == 0 && stepTimes % 2 == 0) || (game.beatCount % 2 == 1 && stepTimes % 2 == 1))
{
Fall();
}
targetBeat += 100f;
return;
}
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Step();
}
else if(state.notPerfect())
{
Fall();
}
else
{
Step();
}
Step();
}
}
public override void OnAce()
{
if (!game.canGo) return;
Step();
}
public void Idle()
{
stepTimes = 0;
@ -75,6 +45,29 @@ namespace RhythmHeavenMania.Games.MrUpbeat
animator.Play("Step", 0, 0);
Jukebox.PlayOneShotGame("mrUpbeat/step");
onGround = false;
CheckShadows();
}
public void Fall()
{
animator.Play("Fall", 0, 0);
Jukebox.PlayOneShot("miss");
shadows[0].SetActive(false);
shadows[1].SetActive(false);
onGround = true;
}
public void Blip()
{
Jukebox.PlayOneShotGame("mrUpbeat/blip");
blipAnimator.Play("Blip", 0, 0);
}
private void CheckShadows()
{
if (onGround) return;
if (stepTimes % 2 == 1)
{
shadows[0].SetActive(false);
@ -87,18 +80,6 @@ namespace RhythmHeavenMania.Games.MrUpbeat
transform.localScale = new Vector3(1, 1);
}
}
public void Fall()
{
animator.Play("Fall", 0, 0);
Jukebox.PlayOneShot("miss");
}
public void Blip()
{
Jukebox.PlayOneShotGame("mrUpbeat/blip");
blipAnimator.Play("Blip", 0, 0);
}
}

View File

@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Starpelly;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.MrUpbeat
{
public class UpbeatStep : PlayerActionObject
{
public float startBeat;
private bool passedFirst = false;
private void Start()
{
PlayerActionInit(gameObject, startBeat);
}
public override void OnAce()
{
Hit(true, true);
}
private void Update()
{
if (Conductor.instance.GetPositionFromBeat(startBeat, 0.35f) >= 1 && !passedFirst)
{
if(MrUpbeat.instance.man.stepTimes % 2 != startBeat % 2)
Hit(false);
passedFirst = true;
}
if (Conductor.instance.GetPositionFromBeat(startBeat, 0.65f) >= 1)
Hit(false);
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, 0.5f);
StateCheck(normalizedBeat);
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Hit(true);
} else if (state.notPerfect())
{
Hit(false);
}
}
}
public void Hit(bool hit, bool force = false)
{
if (force) MrUpbeat.instance.man.Step();
else if (!hit) MrUpbeat.instance.man.Fall();
CleanUp();
}
public void CleanUp()
{
Destroy(this.gameObject);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 671722aab5d7ff34da139a076534caf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -374,7 +374,7 @@ namespace RhythmHeavenMania
new GameAction("start interval", delegate { WizardsWaltz.instance.SetIntervalStart(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); }, 4f, true),
new GameAction("plant", delegate { WizardsWaltz.instance.SpawnFlower(eventCaller.currentEntity.beat); }, 0.5f, false),
}),
new Minigame("mrUpbeat", "Mr. Upbeat \n<color=#eb5454>[WIP don't use]</color>", "FFFFFF", false, false, new List<GameAction>()
new Minigame("mrUpbeat", "Mr. Upbeat", "FFFFFF", false, false, new List<GameAction>()
{
new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true),
new GameAction("go", delegate { MrUpbeat.instance.Go(eventCaller.currentEntity.beat); }, 4f, true),