2021-12-25 06:22:09 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-06-10 19:13:29 +00:00
|
|
|
using Jukebox;
|
2021-12-25 06:22:09 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
2023-02-20 05:48:50 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
public static class AgbBatterLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
2023-04-02 02:28:23 +00:00
|
|
|
return new Minigame("spaceball", "Spaceball", "000073", false, false, new List<GameAction>()
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-20 23:03:51 +00:00
|
|
|
new GameAction("shoot", "Pitch Ball")
|
2022-08-13 07:53:32 +00:00
|
|
|
{
|
2023-02-18 22:12:49 +00:00
|
|
|
function = delegate { Spaceball.instance.Shoot(eventCaller.currentEntity.beat, false, eventCaller.currentEntity["type"]); },
|
|
|
|
preFunction = delegate { Spaceball.instance.PrepareDispenser(); },
|
|
|
|
preFunctionLength = 1,
|
2022-08-20 23:03:51 +00:00
|
|
|
defaultLength = 2,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("type", Spaceball.BallType.Baseball, "Type", "Set the object to shoot.")
|
2022-08-20 23:03:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("shootHigh", "Pitch High Ball")
|
2022-08-13 07:53:32 +00:00
|
|
|
{
|
2023-02-18 22:12:49 +00:00
|
|
|
function = delegate { Spaceball.instance.Shoot(eventCaller.currentEntity.beat, true, eventCaller.currentEntity["type"]); },
|
|
|
|
preFunction = delegate { Spaceball.instance.PrepareDispenser(); },
|
|
|
|
preFunctionLength = 1,
|
2022-08-20 23:03:51 +00:00
|
|
|
defaultLength = 3,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("type", Spaceball.BallType.Baseball, "Type", "Set the object to shoot.")
|
2022-08-20 23:03:51 +00:00
|
|
|
}
|
|
|
|
},
|
2024-01-15 02:04:10 +00:00
|
|
|
new GameAction("costume", "Batter Costume")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { Spaceball.instance.Costume(eventCaller.currentEntity["type"]); },
|
2022-08-20 23:03:51 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("type", Spaceball.CostumeType.Standard, "Type", "Set the costume for the batter to wear.")
|
2022-08-20 23:03:51 +00:00
|
|
|
}
|
|
|
|
},
|
2024-01-15 02:04:10 +00:00
|
|
|
new GameAction("alien", "Space Umpire Animation")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2023-05-28 18:48:41 +00:00
|
|
|
function = delegate { Spaceball.instance.alien.Show(eventCaller.currentEntity.beat, eventCaller.currentEntity["hide"]); },
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("hide", false, "Hide", "Toggle if Space Umpire should be hidden from the scene.")
|
2023-05-28 18:48:41 +00:00
|
|
|
}
|
2022-08-20 23:03:51 +00:00
|
|
|
},
|
|
|
|
new GameAction("camera", "Zoom Camera")
|
|
|
|
{
|
|
|
|
defaultLength = 4,
|
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("valA", new EntityTypes.Integer(1, 320, 10), "Zoom", "Set the level to zoom to."),
|
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing of the action.")
|
2022-08-20 23:03:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("prepare dispenser", "Dispenser Prepare")
|
|
|
|
{
|
|
|
|
function = delegate { Spaceball.instance.PrepareDispenser(); },
|
|
|
|
},
|
2024-05-10 12:32:04 +00:00
|
|
|
new GameAction("fade background", "Background Color")
|
|
|
|
{
|
|
|
|
function = delegate {var e = eventCaller.currentEntity; Spaceball.instance.BackgroundColor(e.beat, e.length, e["colorStart"], e["colorEnd"], e["ease"]); },
|
|
|
|
defaultLength = 4f,
|
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorStart", Spaceball.defaultBGColor, "Start Color", "Set the color at the start of the event."),
|
|
|
|
new Param("colorEnd", Spaceball.defaultBGColor, "End Color", "Set the color at the end of the event."),
|
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing of the action.")
|
|
|
|
}
|
|
|
|
},
|
2023-05-28 17:34:44 +00:00
|
|
|
},
|
|
|
|
new List<string>() {"agb", "normal"},
|
|
|
|
"agbbatter", "en",
|
|
|
|
new List<string>() {}
|
|
|
|
);
|
2022-04-12 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-08-13 07:53:32 +00:00
|
|
|
public enum BallType {
|
2023-01-31 16:16:01 +00:00
|
|
|
Baseball = 0,
|
|
|
|
Onigiri = 1,
|
|
|
|
Alien = 2,
|
2024-05-10 20:47:37 +00:00
|
|
|
Apple = 4,
|
|
|
|
Star = 5,
|
2023-01-31 16:16:01 +00:00
|
|
|
Tacobell = 3,
|
2022-08-13 07:53:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 13:31:55 +00:00
|
|
|
public enum CostumeType {
|
|
|
|
Standard,
|
|
|
|
Bunny,
|
|
|
|
SphereHead
|
|
|
|
}
|
|
|
|
|
2024-05-10 12:32:04 +00:00
|
|
|
[SerializeField] SpriteRenderer bg;
|
|
|
|
[SerializeField] SpriteRenderer square;
|
|
|
|
|
2023-06-04 04:30:42 +00:00
|
|
|
[SerializeField] GameObject Ball;
|
|
|
|
[SerializeField] GameObject BallsHolder;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2023-06-04 04:30:42 +00:00
|
|
|
[SerializeField] GameObject Dispenser;
|
2021-12-25 12:16:40 +00:00
|
|
|
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
|
|
|
|
2024-05-10 12:32:04 +00:00
|
|
|
public static Color defaultBGColor = new Color(0, 0f, 0.4509804f);
|
|
|
|
|
2023-06-04 04:30:42 +00:00
|
|
|
[SerializeField] Sprite[] BallSprites;
|
|
|
|
[SerializeField] Material[] CostumeColors;
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
private List<RiqEntity> _allCameraEvents = new List<RiqEntity>();
|
2021-12-26 05:11:54 +00:00
|
|
|
|
2021-12-28 07:38:55 +00:00
|
|
|
public Alien alien;
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
private Util.EasingFunction.Ease lastEase;
|
2022-02-04 22:16:22 +00:00
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
public static Spaceball instance { get; set; }
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public override void OnGameSwitch(double 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);
|
2024-05-10 12:32:04 +00:00
|
|
|
PersistColor(beat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPlay(double beat)
|
|
|
|
{
|
|
|
|
PersistColor(beat);
|
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" });
|
2023-06-10 19:13:29 +00:00
|
|
|
List<RiqEntity> tempEvents = new List<RiqEntity>();
|
2022-02-04 22:16:22 +00:00
|
|
|
for (int i = 0; i < camEvents.Count; i++)
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
if (camEvents[i].beat + camEvents[i].beat >= Conductor.instance.songPositionInBeatsAsDouble)
|
2022-02-04 22:16:22 +00:00
|
|
|
{
|
|
|
|
tempEvents.Add(camEvents[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
_allCameraEvents = tempEvents;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2023-06-04 04:30:42 +00:00
|
|
|
currentZoomCamDistance = -10;
|
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
|
|
|
{
|
2024-05-10 12:32:04 +00:00
|
|
|
BackgroundColorUpdate();
|
2023-02-20 05:48:50 +00:00
|
|
|
if (_allCameraEvents.Count > 0)
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
if (currentZoomIndex < _allCameraEvents.Count && currentZoomIndex >= 0)
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
if (Conductor.instance.songPositionInBeatsAsDouble >= _allCameraEvents[currentZoomIndex].beat)
|
2022-01-14 00:35:41 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2023-11-21 16:57:03 +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)
|
|
|
|
{
|
2023-11-21 16:57:03 +00:00
|
|
|
GameCamera.AdditionalPosition = new Vector3(0, 0, currentZoomCamDistance + 10);
|
2022-02-04 22:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
Util.EasingFunction.Function func = Util.EasingFunction.GetEasingFunction(lastEase);
|
2022-02-04 22:16:22 +00:00
|
|
|
|
2022-05-16 05:29:39 +00:00
|
|
|
float newPosZ = func(lastCamDistance + 10, currentZoomCamDistance + 10, normalizedBeat);
|
2023-11-21 16:57:03 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
// ?
|
2023-11-21 16:57:03 +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
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
if (_allCameraEvents.Count == 0)
|
2021-12-28 02:36:27 +00:00
|
|
|
currentZoomCamDistance = -10;
|
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
if (currentZoomIndex < _allCameraEvents.Count && currentZoomIndex >= 0)
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
|
|
|
if (currentZoomIndex - 1 >= 0)
|
2023-02-20 05:48:50 +00:00
|
|
|
lastCamDistance = _allCameraEvents[currentZoomIndex - 1]["valA"] * -1;
|
2021-12-26 05:11:54 +00:00
|
|
|
else
|
2021-12-30 12:17:22 +00:00
|
|
|
{
|
|
|
|
if (currentZoomIndex == 0)
|
|
|
|
lastCamDistance = -10;
|
|
|
|
else
|
2023-02-20 05:48:50 +00:00
|
|
|
lastCamDistance = _allCameraEvents[0]["valA"] * -1;
|
2021-12-30 12:17:22 +00:00
|
|
|
}
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
currentZoomCamBeat = (float)_allCameraEvents[currentZoomIndex].beat;
|
2023-02-20 05:48:50 +00:00
|
|
|
currentZoomCamLength = _allCameraEvents[currentZoomIndex].length;
|
2021-12-26 01:04:23 +00:00
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
float dist = _allCameraEvents[currentZoomIndex]["valA"] * -1;
|
2021-12-26 05:11:54 +00:00
|
|
|
|
|
|
|
if (dist > 0)
|
|
|
|
currentZoomCamDistance = 0;
|
|
|
|
else
|
|
|
|
currentZoomCamDistance = dist;
|
2022-02-04 22:16:22 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
lastEase = (Util.EasingFunction.Ease) _allCameraEvents[currentZoomIndex]["ease"];
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void Shoot(double 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;
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("spaceball/longShoot");
|
2021-12-25 13:32:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("spaceball/shoot");
|
2021-12-25 13:32:52 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2023-01-31 16:16:01 +00:00
|
|
|
ball.GetComponent<SpaceballBall>().Sprite.sprite = BallSprites[type];
|
|
|
|
switch(type)
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
2023-01-31 16:16:01 +00:00
|
|
|
case (int)BallType.Baseball:
|
|
|
|
break;
|
|
|
|
case (int)BallType.Onigiri:
|
|
|
|
ball.transform.localScale = new Vector3(1.2f, 1.2f, 1);
|
|
|
|
break;
|
|
|
|
case (int)BallType.Alien:
|
|
|
|
break;
|
|
|
|
case (int)BallType.Tacobell:
|
2023-02-20 05:48:50 +00:00
|
|
|
ball.transform.localScale = new Vector3(2f, 2f, 1);
|
2023-01-31 16:16:01 +00:00
|
|
|
ball.GetComponent<SpaceballBall>().isTacobell = true;
|
|
|
|
break;
|
2024-05-10 20:47:37 +00:00
|
|
|
case (int)BallType.Apple:
|
|
|
|
ball.transform.localScale = new Vector3(5f, 5f, 1);
|
|
|
|
break;
|
|
|
|
case (int)BallType.Star:
|
|
|
|
ball.transform.localScale = new Vector3(6f, 6f, 1);
|
|
|
|
break;
|
2021-12-26 01:04:23 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
SpaceballPlayer.instance.SetCostume(CostumeColors[type], type);
|
2021-12-26 07:25:17 +00:00
|
|
|
}
|
2024-05-10 12:32:04 +00:00
|
|
|
|
|
|
|
//color stuff
|
|
|
|
|
|
|
|
private ColorEase bgColorEase = new(defaultBGColor);
|
|
|
|
|
|
|
|
public void BackgroundColor(double beat, float length, Color startColor, Color endColor, int ease)
|
|
|
|
{
|
|
|
|
bgColorEase = new(beat, length, startColor, endColor, ease);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void BackgroundColorUpdate()
|
|
|
|
{
|
|
|
|
bg.color = bgColorEase.GetColor();
|
|
|
|
square.color = bgColorEase.GetColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PersistColor(double beat)
|
|
|
|
{
|
|
|
|
var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("spaceball", new string[] { "fade background" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeat.Count > 0)
|
|
|
|
{
|
|
|
|
allEventsBeforeBeat.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case
|
|
|
|
var lastEvent = allEventsBeforeBeat[^1];
|
|
|
|
BackgroundColor(lastEvent.beat, lastEvent.length, lastEvent["colorStart"], lastEvent["colorEnd"], lastEvent["ease"]);
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 06:22:09 +00:00
|
|
|
}
|
|
|
|
}
|