2021-12-25 12:16:40 +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 12:16:40 +00:00
|
|
|
|
2022-01-14 02:33:51 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_Spaceball
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
public class SpaceballBall : PlayerActionObject
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
|
|
|
public float startBeat;
|
2022-01-17 05:00:26 +00:00
|
|
|
public Animator anim;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2021-12-25 13:32:52 +00:00
|
|
|
public bool high;
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private Minigame.Eligible e = new Minigame.Eligible();
|
|
|
|
|
|
|
|
public GameObject Holder;
|
2021-12-26 01:04:23 +00:00
|
|
|
public SpriteRenderer Sprite;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
public bool hit;
|
|
|
|
public float hitBeat;
|
|
|
|
public Vector3 hitPos;
|
|
|
|
public float hitRot;
|
|
|
|
public float randomEndPosX;
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
|
|
|
anim = GetComponent<Animator>();
|
|
|
|
|
|
|
|
e.gameObject = this.gameObject;
|
2021-12-28 07:38:55 +00:00
|
|
|
|
|
|
|
float rot = Random.Range(0, 360);
|
|
|
|
Sprite.gameObject.transform.eulerAngles = new Vector3(0, 0, rot);
|
2022-01-17 05:00:26 +00:00
|
|
|
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
// PlayerActionInit(this.gameObject, startBeat, Spaceball.instance.EligibleHits);
|
2022-01-17 05:00:26 +00:00
|
|
|
|
|
|
|
isEligible = true;
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
public override void OnAce()
|
|
|
|
{
|
|
|
|
this.Hit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Hit()
|
|
|
|
{
|
|
|
|
hit = true;
|
|
|
|
hitBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
hitPos = Holder.transform.localPosition;
|
|
|
|
hitRot = Holder.transform.eulerAngles.z;
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/hit");
|
2022-05-06 22:14:01 +00:00
|
|
|
|
|
|
|
// jank fix for a bug with autoplay - freeform
|
|
|
|
if (GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput)
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/swing");
|
|
|
|
}
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
randomEndPosX = Random.Range(40f, 55f);
|
|
|
|
|
|
|
|
anim.enabled = false;
|
|
|
|
SpaceballPlayer.instance.Swing(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Miss()
|
|
|
|
{
|
|
|
|
Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -55;
|
|
|
|
|
|
|
|
enabled = false;
|
|
|
|
anim.enabled = false;
|
|
|
|
|
|
|
|
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>();
|
|
|
|
rb.bodyType = RigidbodyType2D.Dynamic;
|
|
|
|
rb.AddForce(transform.up * 1100);
|
|
|
|
rb.AddForce(transform.right * 400);
|
|
|
|
rb.gravityScale = 9;
|
|
|
|
|
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
if (hit)
|
2021-12-27 04:48:39 +00:00
|
|
|
{
|
2022-02-03 22:20:26 +00:00
|
|
|
float nba = Conductor.instance.GetPositionFromBeat(hitBeat, 14);
|
2022-01-17 05:00:26 +00:00
|
|
|
Holder.transform.localPosition = Vector3.Lerp(hitPos, new Vector3(randomEndPosX, 0f, -600f), nba);
|
|
|
|
Holder.transform.eulerAngles = Vector3.Lerp(new Vector3(0, 0, hitRot), new Vector3(0, 0, -2260), nba);
|
2021-12-27 04:48:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
float beatLength = 1f;
|
|
|
|
if (high) beatLength = 2f;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-02-03 22:20:26 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, beatLength + 0.15f);
|
2022-01-17 05:00:26 +00:00
|
|
|
// print(normalizedBeatAnim + " " + Time.frameCount);
|
2021-12-25 13:32:52 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
if (high)
|
2022-01-14 02:33:51 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
anim.Play("BallHigh", 0, normalizedBeatAnim);
|
2022-01-14 02:33:51 +00:00
|
|
|
}
|
2022-01-17 05:00:26 +00:00
|
|
|
else
|
2022-01-14 02:33:51 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
anim.Play("BallLow", 0, normalizedBeatAnim);
|
2022-01-14 02:33:51 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
anim.speed = 0;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-02-03 22:20:26 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, beatLength);
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
StateCheck(normalizedBeat);
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Hit();
|
|
|
|
}
|
|
|
|
else if (state.notPerfect())
|
|
|
|
{
|
|
|
|
Miss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
// too lazy to make a proper fix for this
|
|
|
|
float endTime = 1.2f;
|
|
|
|
if (high) endTime = 1.1f;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
if (normalizedBeat > endTime)
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/fall");
|
|
|
|
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:14:01 +00:00
|
|
|
}
|