2021-12-25 06:22:09 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2021-12-25 06:22:09 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class AgbBatterLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
|
|
|
return new Minigame("spaceball", "Spaceball", "00A518", false, false, new List<GameAction>()
|
|
|
|
{
|
|
|
|
new GameAction("shoot", delegate { Spaceball.instance.Shoot(eventCaller.currentEntity.beat, false, eventCaller.currentEntity.type); }, 2, false),
|
|
|
|
new GameAction("shootHigh", delegate { Spaceball.instance.Shoot(eventCaller.currentEntity.beat, true, eventCaller.currentEntity.type); }, 3),
|
|
|
|
new GameAction("costume", delegate { Spaceball.instance.Costume(eventCaller.currentEntity.type); }, 1f, false, new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", Spaceball.CostumeType.Standard, "Type", "The costume to change to")
|
|
|
|
} ),
|
|
|
|
new GameAction("alien", delegate { Spaceball.instance.alien.Show(eventCaller.currentEntity.beat); } ),
|
|
|
|
new GameAction("camera", delegate { Spaceball.instance.OverrideCurrentZoom(); }, 4, true, new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("valA", new EntityTypes.Integer(1, 320, 10), "Zoom", "The camera's zoom level (Lower value = Zoomed in)"),
|
|
|
|
new Param("ease", EasingFunction.Ease.Linear, "Ease", "The easing function to use while zooming")
|
|
|
|
} ),
|
|
|
|
new GameAction("prepare dispenser", delegate { Spaceball.instance.PrepareDispenser(); }, 1 ),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2021-12-25 06:22:09 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_Spaceball;
|
|
|
|
|
2021-12-25 06:22:09 +00:00
|
|
|
public class Spaceball : Minigame
|
|
|
|
{
|
2022-02-20 13:31:55 +00:00
|
|
|
public enum CostumeType {
|
|
|
|
Standard,
|
|
|
|
Bunny,
|
|
|
|
SphereHead
|
|
|
|
}
|
|
|
|
|
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-28 07:38:55 +00:00
|
|
|
public Alien alien;
|
|
|
|
|
2022-02-04 22:16:22 +00:00
|
|
|
private EasingFunction.Ease lastEase;
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
public static Spaceball instance { get; set; }
|
|
|
|
|
2022-03-08 04:46:49 +00:00
|
|
|
public override void OnGameSwitch(float beat)
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2021-12-25 13:32:52 +00:00
|
|
|
for (int i = 1; i < BallsHolder.transform.childCount; i++)
|
|
|
|
Destroy(BallsHolder.transform.GetChild(i).gameObject);
|
2022-02-03 02:09:50 +00:00
|
|
|
GameCamera.instance.camera.orthographic = false;
|
2022-01-17 05:00:26 +00:00
|
|
|
|
|
|
|
if (EligibleHits.Count > 0)
|
|
|
|
EligibleHits.RemoveRange(0, 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;
|
2022-02-04 22:16:22 +00:00
|
|
|
var camEvents = EventCaller.GetAllInGameManagerList("spaceball", new string[] { "camera" });
|
|
|
|
List<Beatmap.Entity> tempEvents = new List<Beatmap.Entity>();
|
|
|
|
for (int i = 0; i < camEvents.Count; i++)
|
|
|
|
{
|
|
|
|
if (camEvents[i].beat + camEvents[i].beat >= Conductor.instance.songPositionInBeats)
|
|
|
|
{
|
|
|
|
tempEvents.Add(camEvents[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allCameraEvents = tempEvents;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
|
|
|
UpdateCameraZoom(); // can't believe this shit actually works
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private void Update()
|
2021-12-25 06:22:09 +00:00
|
|
|
{
|
2022-02-04 03:25:18 +00:00
|
|
|
if (allCameraEvents.Count > 0)
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2022-01-14 00:35:41 +00:00
|
|
|
if (currentZoomIndex < allCameraEvents.Count && currentZoomIndex >= 0)
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
2022-01-14 00:35:41 +00:00
|
|
|
if (Conductor.instance.songPositionInBeats >= allCameraEvents[currentZoomIndex].beat)
|
|
|
|
{
|
|
|
|
UpdateCameraZoom();
|
|
|
|
currentZoomIndex++;
|
|
|
|
}
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2022-02-03 22:20:26 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(currentZoomCamBeat, currentZoomCamLength);
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2022-02-04 22:16:22 +00:00
|
|
|
if (normalizedBeat >= 0)
|
2021-12-30 12:17:22 +00:00
|
|
|
{
|
2022-02-20 11:59:36 +00:00
|
|
|
if (normalizedBeat > 1)
|
2022-01-14 00:35:41 +00:00
|
|
|
{
|
2022-05-16 05:29:39 +00:00
|
|
|
GameCamera.additionalPosition = new Vector3(0, 0, currentZoomCamDistance + 10);
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-04 22:16:22 +00:00
|
|
|
if (currentZoomCamLength < 0)
|
|
|
|
{
|
2022-05-16 05:29:39 +00:00
|
|
|
GameCamera.additionalPosition = new Vector3(0, 0, currentZoomCamDistance + 10);
|
2022-02-04 22:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EasingFunction.Function func = EasingFunction.GetEasingFunction(lastEase);
|
|
|
|
|
2022-05-16 05:29:39 +00:00
|
|
|
float newPosZ = func(lastCamDistance + 10, currentZoomCamDistance + 10, normalizedBeat);
|
|
|
|
GameCamera.additionalPosition = new Vector3(0, 0, newPosZ);
|
2022-02-04 22:16:22 +00:00
|
|
|
}
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
2022-02-04 22:16:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// ?
|
2022-05-16 05:29:39 +00:00
|
|
|
GameCamera.additionalPosition = new Vector3(0, 0, 0);
|
2022-02-04 22:16:22 +00:00
|
|
|
}
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateCameraZoom()
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
2021-12-28 02:36:27 +00:00
|
|
|
if (allCameraEvents.Count == 0)
|
|
|
|
currentZoomCamDistance = -10;
|
|
|
|
|
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
|
2021-12-30 12:17:22 +00:00
|
|
|
{
|
|
|
|
if (currentZoomIndex == 0)
|
|
|
|
lastCamDistance = -10;
|
|
|
|
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;
|
2022-02-04 22:16:22 +00:00
|
|
|
|
|
|
|
lastEase = allCameraEvents[currentZoomIndex].ease;
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 03:25:18 +00:00
|
|
|
public void OverrideCurrentZoom()
|
|
|
|
{
|
|
|
|
// lastCamDistance = GameCamera.instance.camera.transform.localPosition.z;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-02-03 22:20:26 +00:00
|
|
|
public void PrepareDispenser()
|
|
|
|
{
|
|
|
|
Dispenser.GetComponent<Animator>().Play("DispenserPrepare", 0, 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|