Spaceball swing + low ball throw + perspective camera

This commit is contained in:
Starpelly
2021-12-25 07:16:40 -05:00
parent 199abb7fd3
commit 866c8c80be
70 changed files with 4174 additions and 17 deletions

View File

@ -8,9 +8,46 @@ namespace RhythmHeavenMania.Games.Spaceball
{
public class Spaceball : Minigame
{
private void Start()
public GameObject Ball;
public GameObject Dispenser;
public GameObject Dust;
public static Spaceball instance { get; set; }
public override void OnGameSwitch()
{
Debug.Log("Spaceball");
GameManager.instance.GameCamera.orthographic = false;
}
private void Awake()
{
instance = this;
}
private void Update()
{
var allPlayerActions = EventCaller.GetAllPlayerEntities("spaceball");
int currentPlayerEvent = GameManager.instance.currentPlayerEvent - EventCaller.GetAllPlayerEntitiesExceptBeforeBeat("spaceball", Conductor.instance.songPositionInBeats).Count;
if (currentPlayerEvent < allPlayerActions.Count)
{
if (Conductor.instance.songPositionInBeats > allPlayerActions[currentPlayerEvent].beat - 1)
{
Dispenser.GetComponent<Animator>().Play("DispenserPrepare", 0, 0);
}
}
}
public void Shoot(float beat)
{
Jukebox.PlayOneShotGame("spaceball/shoot");
GameObject ball = Instantiate(Ball);
ball.transform.parent = Ball.transform.parent;
ball.SetActive(true);
ball.GetComponent<SpaceballBall>().startBeat = beat;
Dispenser.GetComponent<Animator>().Play("DispenserShoot", 0, 0);
}
}
}

View File

@ -0,0 +1,96 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.Spaceball
{
public class SpaceballBall : MonoBehaviour
{
public float startBeat;
private Animator anim;
private int lastState;
private bool inList = false;
private Minigame.Eligible e = new Minigame.Eligible();
public GameObject Holder;
private void Start()
{
anim = GetComponent<Animator>();
e.gameObject = this.gameObject;
}
private void Update()
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, 1.25f);
anim.Play("BallLow", -1, normalizedBeatAnim);
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, 1f);
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastState == 0)
{
MakeEligible(true, false, false);
lastState++;
}
// Perfect State
else if (normalizedBeat > Minigame.PerfectTime() && normalizedBeat < Minigame.LateTime() && lastState == 1)
{
MakeEligible(false, true, false);
lastState++;
}
// Late State
else if (normalizedBeat > Minigame.LateTime() && normalizedBeat < Minigame.EndTime() && lastState == 2)
{
MakeEligible(false, false, true);
lastState++;
}
else if (normalizedBeat < Minigame.EarlyTime() || normalizedBeat > Minigame.EndTime())
{
MakeInEligible();
}
if (normalizedBeat > 1.25f && lastState == 3)
{
lastState++;
Jukebox.PlayOneShotGame("spaceball/fall");
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
Destroy(this.gameObject);
}
}
public void MakeEligible(bool early, bool perfect, bool late)
{
// print($"{early}, {perfect}, {late}");
if (!inList)
{
e.early = early;
e.perfect = perfect;
e.late = late;
SpaceballPlayer.instance.EligibleHits.Add(e);
inList = true;
}
else
{
Minigame.Eligible es = SpaceballPlayer.instance.EligibleHits[SpaceballPlayer.instance.EligibleHits.IndexOf(e)];
es.early = early;
es.perfect = perfect;
es.late = late;
}
}
public void MakeInEligible()
{
if (!inList) return;
SpaceballPlayer.instance.EligibleHits.Remove(e);
inList = false;
}
}
}

View File

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

View File

@ -0,0 +1,85 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.Spaceball
{
public class SpaceballPlayer : MonoBehaviour
{
private Animator anim;
public List<Minigame.Eligible> EligibleHits = new List<Minigame.Eligible>();
[SerializeField] private int currentHitInList = 0;
public static SpaceballPlayer instance { get; set; }
private void Awake()
{
instance = this;
}
private void Start()
{
anim = GetComponent<Animator>();
}
private void Update()
{
if (EligibleHits.Count == 0)
currentHitInList = 0;
if (PlayerInput.Pressed())
{
Swing();
}
}
public void Swing()
{
bool canHit = (EligibleHits.Count > 0) && (currentHitInList < EligibleHits.Count);
if (canHit)
{
if (EligibleHits[currentHitInList].perfect)
{
Jukebox.PlayOneShotGame("spaceball/hit");
EligibleHits[currentHitInList].gameObject.GetComponent<SpaceballBall>().Holder.transform.DOMove(new Vector3(Random.Range(5, 25), 0, -600), 5f);
EligibleHits[currentHitInList].gameObject.GetComponent<SpaceballBall>().enabled = false;
EligibleHits[currentHitInList].gameObject.GetComponent<Animator>().enabled = false;
}
else
{
EligibleHits[currentHitInList].gameObject.GetComponent<SpaceballBall>().Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -55;
EligibleHits[currentHitInList].gameObject.GetComponent<SpaceballBall>().enabled = false;
EligibleHits[currentHitInList].gameObject.GetComponent<Animator>().enabled = false;
Rigidbody2D rb = EligibleHits[currentHitInList].gameObject.AddComponent<Rigidbody2D>();
rb.bodyType = RigidbodyType2D.Dynamic;
rb.AddForce(transform.up * 1100);
rb.AddForce(transform.right * 400);
rb.gravityScale = 9;
Jukebox.PlayOneShot("miss");
}
RemoveBall();
}
else
Jukebox.PlayOneShotGame("spaceball/swing");
anim.Play("Swing", 0, 0);
}
private void RemoveBall()
{
if (currentHitInList < EligibleHits.Count)
{
EligibleHits.Remove(EligibleHits[currentHitInList]);
currentHitInList++;
}
}
}
}

View File

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