HeavenStudioPlus/Assets/Scripts/Games/Spaceball/Spaceball.cs

270 lines
9.5 KiB
C#
Raw Normal View History

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;
using Jukebox;
2021-12-25 06:22:09 +00:00
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
2023-02-20 05:48:50 +00:00
public static class AgbBatterLoader
{
public static Minigame AddGame(EventCaller eventCaller) {
return new Minigame("spaceball", "Spaceball", "000073", false, false, new List<GameAction>()
{
new GameAction("shoot", "Pitch Ball")
{
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,
defaultLength = 2,
parameters = new List<Param>()
{
new Param("type", Spaceball.BallType.Baseball, "Type", "The type of ball/object to shoot")
}
},
new GameAction("shootHigh", "Pitch High Ball")
{
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,
defaultLength = 3,
parameters = new List<Param>()
{
new Param("type", Spaceball.BallType.Baseball, "Type", "The type of ball/object to shoot")
}
},
new GameAction("costume", "Change Batter Costume")
{
function = delegate { Spaceball.instance.Costume(eventCaller.currentEntity["type"]); },
parameters = new List<Param>()
{
new Param("type", Spaceball.CostumeType.Standard, "Type", "The costume to change to")
}
},
new GameAction("alien", "Show Alien")
{
function = delegate { Spaceball.instance.alien.Show(eventCaller.currentEntity.beat, eventCaller.currentEntity["hide"]); },
parameters = new List<Param>()
{
new Param("hide", false, "Hide", "Should the alien be hidden?")
}
},
new GameAction("camera", "Zoom Camera")
{
defaultLength = 4,
resizable = true,
parameters = 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", Util.EasingFunction.Ease.Linear, "Ease", "The easing function to use while zooming")
}
},
new GameAction("prepare dispenser", "Dispenser Prepare")
{
function = delegate { Spaceball.instance.PrepareDispenser(); },
},
},
new List<string>() {"agb", "normal"},
"agbbatter", "en",
new List<string>() {}
);
}
}
}
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
{
public enum BallType {
2023-01-31 16:16:01 +00:00
Baseball = 0,
Onigiri = 1,
Alien = 2,
Tacobell = 3,
}
public enum CostumeType {
Standard,
Bunny,
SphereHead
}
[SerializeField] GameObject Ball;
[SerializeField] GameObject BallsHolder;
[SerializeField] GameObject Dispenser;
public GameObject Dust;
private float lastCamDistance;
private float currentZoomCamBeat;
private float currentZoomCamLength;
private float currentZoomCamDistance;
private int currentZoomIndex;
[SerializeField] Sprite[] BallSprites;
[SerializeField] Material[] CostumeColors;
private List<RiqEntity> _allCameraEvents = new List<RiqEntity>();
2021-12-28 07:38:55 +00:00
public Alien alien;
private Util.EasingFunction.Ease lastEase;
2022-02-04 22:16:22 +00:00
public static Spaceball instance { get; set; }
public override void OnGameSwitch(double beat)
{
for (int i = 1; i < BallsHolder.transform.childCount; i++)
Destroy(BallsHolder.transform.GetChild(i).gameObject);
}
public override void OnTimeChange()
{
UpdateCameraZoom();
}
private void Awake()
{
instance = this;
2022-02-04 22:16:22 +00:00
var camEvents = EventCaller.GetAllInGameManagerList("spaceball", new string[] { "camera" });
List<RiqEntity> tempEvents = new List<RiqEntity>();
2022-02-04 22:16:22 +00:00
for (int i = 0; i < camEvents.Count; i++)
{
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;
currentZoomCamDistance = -10;
}
private void Update()
2021-12-25 06:22:09 +00:00
{
2023-02-20 05:48:50 +00:00
if (_allCameraEvents.Count > 0)
{
2023-02-20 05:48:50 +00:00
if (currentZoomIndex < _allCameraEvents.Count && currentZoomIndex >= 0)
{
if (Conductor.instance.songPositionInBeatsAsDouble >= _allCameraEvents[currentZoomIndex].beat)
{
UpdateCameraZoom();
currentZoomIndex++;
}
}
2022-02-03 22:20:26 +00:00
float normalizedBeat = Conductor.instance.GetPositionFromBeat(currentZoomCamBeat, currentZoomCamLength);
2022-02-04 22:16:22 +00:00
if (normalizedBeat >= 0)
{
if (normalizedBeat > 1)
{
GameCamera.additionalPosition = new Vector3(0, 0, currentZoomCamDistance + 10);
}
else
{
2022-02-04 22:16:22 +00:00
if (currentZoomCamLength < 0)
{
GameCamera.additionalPosition = new Vector3(0, 0, currentZoomCamDistance + 10);
2022-02-04 22:16:22 +00:00
}
else
{
Util.EasingFunction.Function func = Util.EasingFunction.GetEasingFunction(lastEase);
2022-02-04 22:16:22 +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-02-04 22:16:22 +00:00
else
{
// ?
GameCamera.additionalPosition = new Vector3(0, 0, 0);
2022-02-04 22:16:22 +00:00
}
}
}
private void UpdateCameraZoom()
{
2023-02-20 05:48:50 +00:00
if (_allCameraEvents.Count == 0)
currentZoomCamDistance = -10;
2023-02-20 05:48:50 +00:00
if (currentZoomIndex < _allCameraEvents.Count && currentZoomIndex >= 0)
{
if (currentZoomIndex - 1 >= 0)
2023-02-20 05:48:50 +00:00
lastCamDistance = _allCameraEvents[currentZoomIndex - 1]["valA"] * -1;
else
{
if (currentZoomIndex == 0)
lastCamDistance = -10;
else
2023-02-20 05:48:50 +00:00
lastCamDistance = _allCameraEvents[0]["valA"] * -1;
}
currentZoomCamBeat = (float)_allCameraEvents[currentZoomIndex].beat;
2023-02-20 05:48:50 +00:00
currentZoomCamLength = _allCameraEvents[currentZoomIndex].length;
2023-02-20 05:48:50 +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 = (Util.EasingFunction.Ease) _allCameraEvents[currentZoomIndex]["ease"];
}
}
public void Shoot(double beat, bool high, int type)
{
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
if (high)
{
ball.GetComponent<SpaceballBall>().high = true;
SoundByte.PlayOneShotGame("spaceball/longShoot");
}
else
{
SoundByte.PlayOneShotGame("spaceball/shoot");
}
2023-01-31 16:16:01 +00:00
ball.GetComponent<SpaceballBall>().Sprite.sprite = BallSprites[type];
switch(type)
{
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;
}
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
}
2021-12-25 06:22:09 +00:00
}
}