HeavenStudioPlus/Assets/Scripts/Games/KarateMan/Bomb.cs

143 lines
4.5 KiB
C#
Raw Normal View History

2022-01-01 18:54:17 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RhythmHeavenMania.Util;
2022-01-01 18:54:17 +00:00
namespace RhythmHeavenMania.Games.KarateMan
{
public class Bomb : PlayerActionObject
2022-01-01 18:54:17 +00:00
{
private Animator anim;
private float startBeat;
private float hitBeat;
2022-01-19 05:40:49 +00:00
private float missBeat;
2022-01-01 18:54:17 +00:00
public bool kicked;
2022-01-19 05:40:49 +00:00
private bool missed;
private bool eligible;
2022-01-01 18:54:17 +00:00
2022-01-19 05:40:49 +00:00
public GameObject Holder;
2022-01-03 15:15:48 +00:00
public GameObject RotHolder;
private Vector3 lastRot;
2022-01-19 05:40:49 +00:00
public GameObject shadow;
private float shadowY;
[Header("Curves")]
[SerializeField] private AnimationCurve outCurve;
[SerializeField] private AnimationCurve shadowHitCurve;
2022-01-01 18:54:17 +00:00
private void Start()
{
anim = GetComponent<Animator>();
startBeat = Conductor.instance.songPositionInBeats;
eligible = true;
PlayerActionInit(this.gameObject, startBeat);
2022-01-01 18:54:17 +00:00
}
2022-01-23 03:40:53 +00:00
public override void OnAce()
{
Hit();
}
2022-01-01 18:54:17 +00:00
private void Update()
{
2022-01-23 03:40:53 +00:00
shadow.transform.localPosition = new Vector3(Holder.transform.localPosition.x, shadow.transform.localPosition.y);
if (!kicked)
2022-01-01 18:54:17 +00:00
{
2022-01-19 05:40:49 +00:00
if (!missed)
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, 1.25f);
2022-01-01 18:54:17 +00:00
2022-01-19 05:40:49 +00:00
anim.Play("BombOut", 0, normalizedBeatAnim);
anim.speed = 0;
2022-01-19 05:40:49 +00:00
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, 0.75f);
2022-01-19 05:40:49 +00:00
StateCheckNoList(normalizedBeat);
2022-01-19 05:40:49 +00:00
RotHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(0, -90, outCurve.Evaluate(normalizedBeatAnim)));
lastRot = RotHolder.transform.eulerAngles;
2022-01-19 05:40:49 +00:00
shadowY = shadow.transform.localPosition.y;
2022-01-19 05:40:49 +00:00
if (normalizedBeat > 1.5f)
{
2022-01-19 05:40:49 +00:00
eligible = false;
// explode animation
if (normalizedBeat > 4)
Destroy(this.gameObject);
}
2022-01-19 05:40:49 +00:00
2022-01-23 03:40:53 +00:00
if (PlayerInput.PressedUp())
{
2022-01-19 05:40:49 +00:00
if (state.perfect)
{
Hit();
}
else
{
Miss();
}
}
}
else
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(missBeat, 1f);
anim.Play("BombMiss", 0, normalizedBeatAnim);
anim.speed = 0;
RotHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastRot.z, lastRot.z - 180, normalizedBeatAnim));
if (normalizedBeatAnim > 2)
{
Destroy(this.gameObject);
}
}
2022-01-01 18:54:17 +00:00
}
else
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 3f);
anim.Play("BombHit", 0, normalizedBeatAnim);
2022-01-01 18:54:17 +00:00
anim.speed = 0;
2022-01-19 05:40:49 +00:00
RotHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastRot.z, lastRot.z - 180, normalizedBeatAnim));
shadow.transform.localPosition = new Vector3(shadow.transform.localPosition.x, Mathf.Lerp(shadowY, 0.881f, shadowHitCurve.Evaluate(normalizedBeatAnim)));
shadow.transform.localScale = Holder.transform.localScale;
if (normalizedBeatAnim > 1)
{
Destroy(this.gameObject);
}
2022-01-01 18:54:17 +00:00
}
}
public void Hit()
{
2022-01-03 15:15:48 +00:00
KarateJoe.instance.HitEffectF(new Vector3(0.9f, 2.0549f));
Jukebox.PlayOneShotGame("karateman/bombKick");
hitBeat = Conductor.instance.songPositionInBeats;
kicked = true;
2022-01-03 15:15:48 +00:00
RotHolder.transform.eulerAngles = lastRot;
2022-01-23 03:40:53 +00:00
KarateJoe.instance.ResetKick();
KarateJoe.instance.AnimPlay("Kick");
2022-01-01 18:54:17 +00:00
}
2022-01-19 05:40:49 +00:00
public void Miss()
{
missBeat = Conductor.instance.songPositionInBeats;
missed = true;
Jukebox.PlayOneShot("miss");
2022-01-23 03:40:53 +00:00
KarateJoe.instance.ResetKick();
KarateJoe.instance.AnimPlay("Kick");
2022-01-19 05:40:49 +00:00
}
2022-01-01 18:54:17 +00:00
}
}