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

312 lines
9.5 KiB
C#
Raw Normal View History

2021-12-29 06:52:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.KarateMan
{
public class KarateJoe : MonoBehaviour
{
2022-01-26 17:02:44 +00:00
[Header("Components")]
public Animator anim;
2021-12-30 08:26:18 +00:00
public GameObject HitEffect;
public ParticleSystem HitParticle;
public ParticleSystem RockParticle;
public GameObject BulbHit;
2022-01-26 17:02:44 +00:00
[SerializeField] private SpriteRenderer head;
[SerializeField] private Sprite[] heads;
[SerializeField] private GameObject missEffect;
2021-12-30 08:26:18 +00:00
2022-01-26 17:02:44 +00:00
[Header("Properties")]
public bool hitBarrel = false;
2022-01-23 03:40:53 +00:00
public Coroutine kickC;
2022-01-26 17:02:44 +00:00
public Coroutine missC;
private float barrelBeat;
public bool inCombo;
public bool hitCombo;
2022-01-20 01:48:52 +00:00
private float comboBeat;
public List<Pot> currentComboPots = new List<Pot>();
private int comboPotIndex;
private int currentComboHitInList;
private int comboIndex;
2022-01-23 03:40:53 +00:00
public float comboNormalizedBeat = 0;
public static KarateJoe instance { get; set; }
2021-12-29 06:52:48 +00:00
private void Start()
{
instance = this;
2021-12-29 06:52:48 +00:00
anim = GetComponent<Animator>();
}
private void Update()
{
2022-01-20 01:48:52 +00:00
if (inCombo)
{
2022-01-23 03:40:53 +00:00
comboNormalizedBeat = Conductor.instance.GetLoopPositionFromBeat(comboBeat, 1);
2022-01-20 01:48:52 +00:00
if (hitCombo)
{
if (currentComboPots[comboPotIndex] == null) return;
}
else
{
2022-01-23 03:40:53 +00:00
comboNormalizedBeat += 1;
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
if (comboNormalizedBeat >= 1 && comboIndex < 1)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
currentComboPots[comboPotIndex].Hit();
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
comboPotIndex++;
Jukebox.PlayOneShotGame("karateman/comboHit1");
}
2022-01-21 01:24:30 +00:00
else
{
Jukebox.PlayOneShotGame("karateman/swingNoHit");
}
2022-01-20 01:48:52 +00:00
comboIndex++;
AnimPlay("PunchLeft");
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
else if (comboNormalizedBeat >= 1.25f && comboIndex < 2)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
currentComboPots[comboPotIndex].Hit();
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
comboPotIndex++;
Jukebox.PlayOneShotGame("karateman/comboHit1");
}
2022-01-21 01:24:30 +00:00
else
{
Jukebox.PlayOneShotGame("karateman/swingNoHit_Alt");
}
2022-01-20 01:48:52 +00:00
comboIndex++;
AnimPlay("PunchRight");
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
else if (comboNormalizedBeat >= 1.5f && comboIndex < 3)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
currentComboPots[comboPotIndex].Hit();
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
comboPotIndex++;
Jukebox.PlayOneShotGame("karateman/comboHit2");
}
comboIndex++;
AnimPlay("ComboCrouch");
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
else if (comboNormalizedBeat >= 1.75f && comboIndex < 4)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
currentComboPots[comboPotIndex].Hit();
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
comboPotIndex++;
Jukebox.PlayOneShotGame("karateman/comboHit3");
}
2022-01-21 01:24:30 +00:00
else
{
Jukebox.PlayOneShotGame("karateman/comboMiss");
}
2022-01-20 01:48:52 +00:00
comboIndex++;
AnimPlay("ComboKick");
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
else if (comboNormalizedBeat >= 2f && comboIndex < 5)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
currentComboPots[comboPotIndex].Hit();
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
comboPotIndex++;
Jukebox.PlayOneShotGame("karateman/comboHit3");
}
comboIndex++;
AnimPlay("ComboCrouchPunch");
2022-01-20 01:48:52 +00:00
}
2022-01-23 03:40:53 +00:00
else if (comboNormalizedBeat >= 2.05f)
2022-01-20 01:48:52 +00:00
{
if (hitCombo)
{
if (PlayerInput.AltPressedUp())
{
2022-01-23 03:40:53 +00:00
// ComboPow(null);
2022-01-20 01:48:52 +00:00
}
}
else
{
// fail anim
AnimPlay("ComboMiss");
2022-01-20 07:26:53 +00:00
ResetCombo();
2022-01-20 01:48:52 +00:00
}
}
}
else
{
2022-01-23 03:40:53 +00:00
if (!inCombo)
2022-01-20 01:48:52 +00:00
if (PlayerInput.AltPressed())
{
2022-01-23 03:40:53 +00:00
Combo(null);
2022-01-20 01:48:52 +00:00
}
}
2022-01-23 03:40:53 +00:00
if (!hitBarrel)
{
2022-01-20 01:48:52 +00:00
if (PlayerInput.Pressed() && !inCombo)
{
2022-01-23 03:40:53 +00:00
Swing(null);
}
2021-12-29 06:52:48 +00:00
}
}
2022-01-23 03:40:53 +00:00
public void Combo(Pot p)
2022-01-20 01:48:52 +00:00
{
2022-01-23 03:40:53 +00:00
if (p == null)
2022-01-20 01:48:52 +00:00
{
2022-01-23 03:40:53 +00:00
comboBeat = Conductor.instance.songPositionInBeats;
hitCombo = false;
2022-01-20 01:48:52 +00:00
}
else
{
2022-01-23 03:40:53 +00:00
comboBeat = p.createBeat;
hitCombo = true;
2022-01-20 01:48:52 +00:00
}
inCombo = true;
}
2022-01-23 03:40:53 +00:00
public void ComboPow(Pot p, bool overrideState = false)
2022-01-20 01:48:52 +00:00
{
if (!hitCombo || !inCombo || !hitCombo && !inCombo) return;
anim.Play("Pow", 0, 0);
2022-01-23 03:40:53 +00:00
/*if (currentComboPots[comboPotIndex].state.perfect)
2022-01-20 01:48:52 +00:00
{
2022-01-23 03:40:53 +00:00
// BarrelDestroy(currentComboPots[comboPotIndex], true);
2022-01-20 07:26:53 +00:00
HitEffectF(currentComboPots[comboPotIndex].Holder.transform.localPosition);
2022-01-20 01:48:52 +00:00
Destroy(currentComboPots[comboPotIndex].gameObject);
Jukebox.PlayOneShotGame("karateman/comboHit4");
}
else
{
Jukebox.PlayOneShot("miss");
currentComboPots[comboPotIndex].Miss();
2022-01-23 03:40:53 +00:00
}*/
if (p != null)
{
if (p.state.perfect || overrideState)
{
p.BarrelDestroy(true);
HitEffectF(p.Holder.transform.localPosition);
Destroy(p.gameObject);
Jukebox.PlayOneShotGame("karateman/comboHit4");
}
else if (p.state.notPerfect())
{
p.Miss();
}
2022-01-20 01:48:52 +00:00
}
2022-01-20 07:26:53 +00:00
ResetCombo();
}
private void ResetCombo()
{
2022-01-20 01:48:52 +00:00
hitCombo = false;
inCombo = false;
comboPotIndex = 0;
comboIndex = 0;
currentComboHitInList = 0;
currentComboPots.Clear();
}
2022-01-23 03:40:53 +00:00
public IEnumerator PrepareKick()
{
barrelBeat = Conductor.instance.songPositionInBeats;
hitBarrel = true;
yield return new WaitForSeconds(0.17f);
AnimPlay("KickPrepare");
}
2022-01-23 03:40:53 +00:00
public void ResetKick()
2021-12-29 06:52:48 +00:00
{
2022-01-23 03:40:53 +00:00
if (kickC != null)
{
StopCoroutine(kickC);
}
hitBarrel = false;
}
2021-12-29 06:52:48 +00:00
2022-01-23 03:40:53 +00:00
public void Swing(Pot p)
{
2021-12-30 08:26:18 +00:00
bool punchLeft = true;
2022-01-23 03:40:53 +00:00
if (p == null)
{
2022-01-23 03:40:53 +00:00
Jukebox.PlayOneShotGame("karateman/swingNoHit");
}
else
{
if (p.type == 2 || p.type == 3 || p.type == 4 || p.type == 6)
2021-12-29 06:52:48 +00:00
{
2022-01-23 03:40:53 +00:00
punchLeft = false;
}
else
{
punchLeft = true;
}
2022-01-23 03:40:53 +00:00
if (p.type == 4)
{
if (kickC != null) StopCoroutine(kickC);
kickC = StartCoroutine(PrepareKick());
2021-12-29 06:52:48 +00:00
}
2022-01-17 19:23:18 +00:00
2022-01-23 03:40:53 +00:00
if (!p.combo)
HitEffectF(HitEffect.transform.localPosition);
}
2022-01-17 19:23:18 +00:00
if (punchLeft)
AnimPlay("PunchLeft");
2022-01-17 19:23:18 +00:00
else
AnimPlay("PunchRight");
2021-12-29 06:52:48 +00:00
}
2022-01-03 15:15:48 +00:00
public void HitEffectF(Vector3 pos)
{
GameObject hit = Instantiate(HitEffect);
hit.transform.parent = HitEffect.transform.parent;
hit.transform.localPosition = pos;
hit.SetActive(true);
2022-01-19 05:40:49 +00:00
Destroy(hit, 0.06f);
2022-01-03 15:15:48 +00:00
}
2022-01-20 01:48:52 +00:00
public void AnimPlay(string name)
{
anim.Play(name, 0, 0);
anim.speed = 1;
}
2022-01-26 17:02:44 +00:00
public void SetHead(int index)
{
head.sprite = heads[index];
}
public IEnumerator Miss()
{
// I couldn't find the sound for this
GameObject miss = Instantiate(missEffect, missEffect.transform.parent);
miss.SetActive(true);
SetHead(2);
yield return new WaitForSeconds(0.08f);
Destroy(miss);
SetHead(0);
}
2021-12-29 06:52:48 +00:00
}
}