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

374 lines
14 KiB
C#
Raw Normal View History

2021-12-29 06:52:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-01-23 03:40:53 +00:00
using RhythmHeavenMania.Util;
2021-12-29 06:52:48 +00:00
namespace RhythmHeavenMania.Games.KarateMan
{
public class Pot : PlayerActionObject
{
public float startBeat;
2021-12-30 08:26:18 +00:00
public float createBeat;
[HideInInspector] public Animator anim;
2021-12-29 06:52:48 +00:00
2021-12-30 08:26:18 +00:00
public GameObject Holder;
private GameObject newHolder;
public GameObject Sprite;
2022-01-19 05:40:49 +00:00
public GameObject Shadow;
2021-12-30 08:26:18 +00:00
public bool isThrown;
public bool isHit = false;
public float hitBeat;
private Vector3 lastPos;
private float lastShadowX;
public AnimationCurve hitCurve;
2022-01-19 05:40:49 +00:00
public AnimationCurve hitCurveY;
2021-12-30 08:26:18 +00:00
public AnimationCurve hitCurveX;
2022-01-01 18:54:17 +00:00
public AnimationCurve missCurve;
2022-01-19 05:40:49 +00:00
public AnimationCurve shadowCurve;
public AnimationCurve shadowCurveScale;
2021-12-30 08:26:18 +00:00
public int type;
public string hitSnd;
private float hitLength;
2021-12-29 06:52:48 +00:00
2022-01-01 18:54:17 +00:00
private float lastRot;
public bool kick;
2022-01-19 05:40:49 +00:00
public float lastPotRot;
2022-01-20 01:48:52 +00:00
public string throwAnim;
public bool combo;
public int comboIndex;
public Vector2 endShadowThrowPos;
2022-01-26 17:02:44 +00:00
private int missTimes = 0;
2021-12-29 06:52:48 +00:00
private void Start()
{
anim = GetComponent<Animator>();
Sprite.transform.eulerAngles = new Vector3(0, 0, Random.Range(0, 360));
2021-12-30 08:26:18 +00:00
if (type == 2)
2022-01-19 05:40:49 +00:00
hitLength = 14f;
2021-12-30 08:26:18 +00:00
else
2022-01-19 05:40:49 +00:00
hitLength = 14f;
2022-01-23 03:40:53 +00:00
/*if (combo)
2022-01-20 01:48:52 +00:00
{
if (comboIndex == 0)
{
isEligible = true;
2022-01-23 03:40:53 +00:00
// PlayerActionInit(this.gameObject, createBeat, KarateMan.instance.EligibleCombos);
2022-01-20 01:48:52 +00:00
}
else if (comboIndex == 5)
{
isEligible = true;
}
}
else
{
isEligible = true;
2022-01-23 03:40:53 +00:00
// PlayerActionInit(this.gameObject, createBeat, KarateMan.instance.EligibleHits);
}*/
2022-01-20 01:48:52 +00:00
PlayerActionInit(this.gameObject, createBeat);
2022-01-20 01:48:52 +00:00
Sprite.GetComponent<SpriteRenderer>().enabled = false;
2021-12-29 06:52:48 +00:00
}
2022-01-23 03:40:53 +00:00
public override void OnAce()
{
if (combo)
{
if (comboIndex == 0)
{
KarateJoe.instance.Combo(this);
}
else if (comboIndex == 5)
{
KarateJoe.instance.ComboPow(this, true);
}
}
else
{
this.Hit();
}
// KarateJoe.instance.Swing(state);
}
2021-12-29 06:52:48 +00:00
private void Update()
{
2022-01-20 01:48:52 +00:00
if (Conductor.instance.songPositionInBeats >= createBeat)
Sprite.GetComponent<SpriteRenderer>().enabled = true;
else
Sprite.GetComponent<SpriteRenderer>().enabled = false;
2021-12-30 08:26:18 +00:00
float time2Destroy = Conductor.instance.GetLoopPositionFromBeat(createBeat, 4);
if (time2Destroy >= 1)
Destroy(this.gameObject);
if (isThrown)
{
2022-01-20 01:48:52 +00:00
float animTime = 2.22000000002f;
float beatTime = 1f;
if (comboIndex == 5)
{
animTime = 2.27777777777f;
}
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, animTime);
anim.Play(throwAnim, 0, normalizedBeatAnim);
2021-12-30 08:26:18 +00:00
anim.speed = 0;
2022-01-20 01:48:52 +00:00
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, beatTime);
2021-12-30 08:26:18 +00:00
2022-01-19 05:40:49 +00:00
Shadow.transform.localScale = Vector3.Lerp(new Vector3(4.12f, 4.12f), new Vector3(0.34f, 0.34f), shadowCurveScale.Evaluate(normalizedBeatAnim));
2022-01-20 01:48:52 +00:00
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(7.63f, endShadowThrowPos.x, shadowCurve.Evaluate(normalizedBeatAnim)), Mathf.Lerp(-12.26f, endShadowThrowPos.y, shadowCurve.Evaluate(normalizedBeatAnim)));
2022-01-19 05:40:49 +00:00
2021-12-30 08:26:18 +00:00
lastPos = Holder.transform.localPosition;
2022-01-19 05:40:49 +00:00
lastPotRot = Holder.transform.eulerAngles.z;
2021-12-30 08:26:18 +00:00
lastShadowX = Shadow.transform.localPosition.x;
2022-01-01 18:54:17 +00:00
lastRot = Holder.transform.GetChild(0).eulerAngles.z;
2022-01-20 01:48:52 +00:00
if (combo && comboIndex == 0 || !combo)
2022-01-26 17:02:44 +00:00
{
if (!KarateJoe.instance.hitCombo)
{
if (normalizedBeat >= 2 && missTimes == 0)
{
if (KarateJoe.instance.missC != null) StopCoroutine(KarateJoe.instance.missC);
KarateJoe.instance.missC = KarateJoe.instance.StartCoroutine(KarateJoe.instance.Miss());
missTimes = 1;
}
}
2022-01-26 17:02:44 +00:00
}
2022-01-20 01:48:52 +00:00
StateCheck(normalizedBeat);
2022-01-21 01:24:30 +00:00
2022-01-23 03:40:53 +00:00
if (!combo)
{
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Hit();
}
else if (state.notPerfect())
{
Miss();
}
}
}
else
{
if (comboIndex == 0)
{
if (PlayerInput.AltPressed())
{
if (state.perfect)
{
KarateJoe.instance.Combo(this);
}
}
}
else if (comboIndex == 5)
{
if (KarateJoe.instance.comboNormalizedBeat >= 2.05f)
if (PlayerInput.AltPressedUp())
{
KarateJoe.instance.ComboPow(this);
}
}
}
2022-01-21 01:24:30 +00:00
if (normalizedBeat > 1)
{
Sprite.GetComponent<SpriteRenderer>().sortingOrder = -20;
Shadow.GetComponent<SpriteRenderer>().sortingOrder = -30;
}
2021-12-30 08:26:18 +00:00
}
2022-01-01 18:54:17 +00:00
if (!isHit && !isThrown)
2021-12-30 08:26:18 +00:00
{
2022-01-01 18:54:17 +00:00
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 1.5f);
2021-12-30 08:26:18 +00:00
newHolder.transform.localPosition = new Vector3(transform.localPosition.x, Mathf.Lerp(0, 0.55f, Conductor.instance.GetLoopPositionFromBeat(hitBeat, 0.45f)));
2022-01-01 18:54:17 +00:00
Holder.transform.localPosition = new Vector3(Mathf.Lerp(lastPos.x, 0.9f, normalizedBeatAnim), Mathf.Lerp(lastPos.y, -3.43f, missCurve.Evaluate(normalizedBeatAnim)));
Holder.transform.GetChild(0).transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastRot, lastRot - 523.203f, normalizedBeatAnim));
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(lastShadowX, 0.9f, normalizedBeatAnim), Shadow.transform.localPosition.y);
}
if (kick == false)
{
if (isHit)
{
2022-01-19 05:40:49 +00:00
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 1.5f);
2022-01-01 18:54:17 +00:00
var y = Mathf.Lerp(lastPos.y, -3.27f, hitCurve.Evaluate(normalizedBeatAnim));
var x = Mathf.Lerp(lastPos.x, hitLength, hitCurveX.Evaluate(normalizedBeatAnim));
2022-01-19 05:40:49 +00:00
newHolder.transform.localPosition = new Vector3(transform.localPosition.x, Mathf.Lerp(0, 0.45f, hitCurveY.Evaluate(normalizedBeatAnim)));
2022-01-01 18:54:17 +00:00
Holder.transform.localPosition = new Vector3(x, y);
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(lastShadowX, hitLength, hitCurveX.Evaluate(normalizedBeatAnim)), Shadow.transform.localPosition.y);
2022-01-19 05:40:49 +00:00
Holder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastPotRot, lastPotRot - 360, normalizedBeatAnim));
2022-01-01 18:54:17 +00:00
// anim.Play("PotHit", 0, normalizedBeatAnim);
// anim.speed = 0;
}
2021-12-30 08:26:18 +00:00
}
2022-01-19 05:40:49 +00:00
else
{
if (isHit)
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 1.5f);
newHolder.transform.localPosition = new Vector3(transform.localPosition.x, Mathf.Lerp(0, 0.55f, Conductor.instance.GetLoopPositionFromBeat(hitBeat, 0.45f)));
Holder.transform.localPosition = new Vector3(Mathf.Lerp(lastPos.x, 0.9f, normalizedBeatAnim), Mathf.Lerp(lastPos.y, -3.43f, missCurve.Evaluate(normalizedBeatAnim)));
Holder.transform.GetChild(0).transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastRot, lastRot - 523.203f, normalizedBeatAnim));
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(lastShadowX, 0.9f, normalizedBeatAnim), Shadow.transform.localPosition.y);
}
}
2021-12-30 08:26:18 +00:00
}
public void Hit()
2022-01-01 18:54:17 +00:00
{
2022-01-23 03:40:53 +00:00
Jukebox.PlayOneShotGame(hitSnd);
KarateJoe.instance.Swing(this);
NewHolder();
switch (type)
{
case 0:
// HitParticle.Play();
break;
case 1:
GameObject bulbHit = Instantiate(KarateJoe.instance.BulbHit);
bulbHit.transform.parent = KarateJoe.instance.BulbHit.transform.parent;
bulbHit.SetActive(true);
Destroy(bulbHit, 0.7f);
break;
case 2:
// RockParticle.Play();
break;
case 4:
BarrelDestroy(false);
break;
}
2022-01-01 18:54:17 +00:00
if (!kick)
{
2022-01-23 03:40:53 +00:00
2022-01-01 18:54:17 +00:00
}
else if (kick)
{
2022-01-19 05:40:49 +00:00
KarateMan.instance.CreateBomb(this.transform.parent, Holder.transform.localScale, ref Shadow);
2022-01-01 18:54:17 +00:00
Destroy(this.gameObject);
}
2022-01-19 05:40:49 +00:00
hitBeat = Conductor.instance.songPositionInBeats;
anim.enabled = false;
isThrown = false;
isHit = true;
Sprite.GetComponent<SpriteRenderer>().sortingOrder = 49;
2022-01-01 18:54:17 +00:00
}
public void Miss()
2021-12-30 08:26:18 +00:00
{
2022-01-23 03:40:53 +00:00
Jukebox.PlayOneShot("miss");
2022-01-26 17:02:44 +00:00
KarateJoe.instance.SetHead(3);
2022-01-19 05:40:49 +00:00
NewHolder();
2021-12-30 08:26:18 +00:00
Holder.transform.parent = newHolder.transform;
hitBeat = Conductor.instance.songPositionInBeats;
2022-01-01 18:54:17 +00:00
isHit = false;
2021-12-30 08:26:18 +00:00
isThrown = false;
2022-01-01 18:54:17 +00:00
anim.enabled = false;
2021-12-30 08:26:18 +00:00
Sprite.GetComponent<SpriteRenderer>().sortingOrder = 49;
2021-12-29 06:52:48 +00:00
}
2022-01-19 05:40:49 +00:00
private void NewHolder()
{
newHolder = new GameObject();
newHolder.transform.parent = this.gameObject.transform;
Holder.transform.parent = newHolder.transform;
}
2022-01-23 03:40:53 +00:00
public void BarrelDestroy(bool combo)
{
for (int i = 0; i < 8; i++)
{
GameObject be = new GameObject();
be.transform.localPosition = Holder.transform.localPosition;
be.transform.parent = this.transform.parent;
be.transform.localScale = Holder.transform.localScale;
BarrelDestroyEffect bde = be.AddComponent<BarrelDestroyEffect>();
Vector3 pos = be.transform.localPosition;
SpriteRenderer sprite = be.AddComponent<SpriteRenderer>();
bde.shadow = Instantiate(Shadow, transform.parent);
bde.shadow.transform.position = Shadow.transform.position;
bde.shadow.transform.localScale = Shadow.transform.lossyScale;
bde.index = i;
bde.combo = combo;
switch (i)
{
case 0:
be.transform.localPosition = new Vector3(pos.x, pos.y + 1.25f);
sprite.sortingOrder = 35;
bde.spriteIndex = 3;
break;
case 1:
be.transform.localPosition = new Vector3(pos.x, pos.y + -0.55f);
sprite.sortingOrder = 31;
bde.spriteIndex = 3;
break;
case 2:
be.transform.localPosition = new Vector3(pos.x - 0.8f, pos.y + 0.45f);
sprite.sortingOrder = 32;
bde.spriteIndex = 0;
break;
case 3:
be.transform.localPosition = new Vector3(pos.x - 0.5f, pos.y + 0.45f);
sprite.sortingOrder = 33;
bde.spriteIndex = 1;
break;
case 4:
be.transform.localPosition = new Vector3(pos.x, pos.y + 0.45f);
sprite.sortingOrder = 34;
bde.spriteIndex = 2;
break;
case 5:
be.transform.localPosition = new Vector3(pos.x + 0.5f, pos.y + 0.45f);
sprite.sortingOrder = 33;
sprite.flipX = true;
bde.spriteIndex = 1;
break;
case 6:
be.transform.localPosition = new Vector3(pos.x + 0.8f, pos.y + 0.45f);
sprite.sortingOrder = 32;
sprite.flipX = true;
bde.spriteIndex = 0;
break;
case 7:
be.transform.localPosition = new Vector3(pos.x, pos.y + 1.25f);
sprite.sortingOrder = 39;
bde.spriteIndex = 4;
break;
}
}
}
2021-12-29 06:52:48 +00:00
}
}