2021-12-25 06:22:09 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Games.Spaceball
|
|
|
|
{
|
|
|
|
public class Spaceball : Minigame
|
|
|
|
{
|
2021-12-25 12:16:40 +00:00
|
|
|
public GameObject Ball;
|
2021-12-25 13:32:52 +00:00
|
|
|
public GameObject BallsHolder;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
|
|
|
public GameObject Dispenser;
|
|
|
|
public GameObject Dust;
|
|
|
|
|
2021-12-26 01:04:23 +00:00
|
|
|
private float lastCamDistance;
|
2021-12-26 05:11:54 +00:00
|
|
|
private float currentZoomCamBeat;
|
|
|
|
private float currentZoomCamLength;
|
|
|
|
private float currentZoomCamDistance;
|
|
|
|
|
|
|
|
private int currentZoomIndex;
|
2021-12-26 01:04:23 +00:00
|
|
|
|
|
|
|
public Sprite[] Balls;
|
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
private List<Beatmap.Entity> allCameraEvents = new List<Beatmap.Entity>();
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
public static Spaceball instance { get; set; }
|
|
|
|
|
|
|
|
public override void OnGameSwitch()
|
|
|
|
{
|
2021-12-25 13:32:52 +00:00
|
|
|
for (int i = 1; i < BallsHolder.transform.childCount; i++)
|
|
|
|
Destroy(BallsHolder.transform.GetChild(i).gameObject);
|
2021-12-25 12:16:40 +00:00
|
|
|
GameManager.instance.GameCamera.orthographic = false;
|
2021-12-26 01:04:23 +00:00
|
|
|
SpaceballPlayer.instance.EligibleHits.RemoveRange(0, SpaceballPlayer.instance.EligibleHits.Count);
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
public override void OnTimeChange()
|
|
|
|
{
|
|
|
|
UpdateCameraZoom();
|
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
UpdateCameraZoom();
|
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private void Update()
|
2021-12-25 06:22:09 +00:00
|
|
|
{
|
2021-12-25 12:16:40 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
if (currentZoomIndex < allCameraEvents.Count && currentZoomIndex >= 0)
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
2021-12-26 05:11:54 +00:00
|
|
|
if (Conductor.instance.songPositionInBeats >= allCameraEvents[currentZoomIndex].beat)
|
|
|
|
{
|
|
|
|
UpdateCameraZoom();
|
|
|
|
currentZoomIndex++;
|
|
|
|
}
|
2021-12-26 01:04:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(currentZoomCamBeat, currentZoomCamLength);
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
if (normalizedBeat > Minigame.EndTime())
|
|
|
|
{
|
|
|
|
lastCamDistance = GameManager.instance.GameCamera.transform.localPosition.z;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (currentZoomCamLength <= 0)
|
|
|
|
GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, currentZoomCamDistance);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float newPosZ = Mathf.Lerp(lastCamDistance, currentZoomCamDistance, normalizedBeat);
|
|
|
|
GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, newPosZ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateCameraZoom()
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
2021-12-26 05:11:54 +00:00
|
|
|
allCameraEvents = EventCaller.GetAllInGameManagerList("spaceball", new string[] { "cameraZoom" });
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
if (currentZoomIndex < allCameraEvents.Count && currentZoomIndex >= 0)
|
|
|
|
{
|
|
|
|
if (currentZoomIndex - 1 >= 0)
|
|
|
|
lastCamDistance = allCameraEvents[currentZoomIndex - 1].valA * -1;
|
|
|
|
else
|
|
|
|
lastCamDistance = allCameraEvents[0].valA * -1;
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
currentZoomCamBeat = allCameraEvents[currentZoomIndex].beat;
|
|
|
|
currentZoomCamLength = allCameraEvents[currentZoomIndex].length;
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
float dist = allCameraEvents[currentZoomIndex].valA * -1;
|
|
|
|
|
|
|
|
if (dist > 0)
|
|
|
|
currentZoomCamDistance = 0;
|
|
|
|
else
|
|
|
|
currentZoomCamDistance = dist;
|
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 07:25:17 +00:00
|
|
|
public void Shoot(float beat, bool high, int type)
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
|
|
|
GameObject ball = Instantiate(Ball);
|
|
|
|
ball.transform.parent = Ball.transform.parent;
|
|
|
|
ball.SetActive(true);
|
|
|
|
ball.GetComponent<SpaceballBall>().startBeat = beat;
|
2021-12-26 07:25:17 +00:00
|
|
|
|
2021-12-26 01:04:23 +00:00
|
|
|
if (high)
|
2021-12-25 13:32:52 +00:00
|
|
|
{
|
|
|
|
ball.GetComponent<SpaceballBall>().high = true;
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/longShoot");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/shoot");
|
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2021-12-26 07:25:17 +00:00
|
|
|
if (type == 1)
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
|
|
|
ball.GetComponent<SpaceballBall>().Sprite.sprite = Balls[1];
|
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
Dispenser.GetComponent<Animator>().Play("DispenserShoot", 0, 0);
|
2021-12-25 06:22:09 +00:00
|
|
|
}
|
2021-12-26 07:25:17 +00:00
|
|
|
|
|
|
|
public void Costume(int type)
|
|
|
|
{
|
|
|
|
SpaceballPlayer.instance.SetCostume(type);
|
|
|
|
}
|
2021-12-25 06:22:09 +00:00
|
|
|
}
|
|
|
|
}
|