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

384 lines
13 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
{
2021-12-30 08:26:18 +00:00
public Animator anim;
2021-12-29 06:52:48 +00:00
private int currentHitInList = 0;
2021-12-30 08:26:18 +00:00
public GameObject HitEffect;
[Header("Particles")]
public ParticleSystem HitParticle;
public ParticleSystem RockParticle;
public GameObject BulbHit;
public bool hitBarrel = false;
private Coroutine kickC;
private float barrelBeat;
2022-01-20 01:48:52 +00:00
private bool inCombo;
private bool hitCombo;
private float comboBeat;
public List<Pot> currentComboPots = new List<Pot>();
private int comboPotIndex;
private int currentComboHitInList;
private int comboIndex;
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)
{
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(comboBeat, 1);
if (hitCombo)
{
if (currentComboPots[comboPotIndex] == null) return;
}
else
{
normalizedBeat += 1;
}
if (normalizedBeat >= 1 && comboIndex < 1)
{
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");
}
comboIndex++;
anim.Play("PunchLeft", 0, 0);
}
else if (normalizedBeat >= 1.25f && comboIndex < 2)
{
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");
}
comboIndex++;
anim.Play("PunchRight", 0, 0);
}
else if (normalizedBeat >= 1.5f && comboIndex < 3)
{
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++;
anim.Play("ComboCrouch", 0, 0);
}
else if (normalizedBeat >= 1.75f && comboIndex < 4)
{
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++;
anim.Play("ComboKick", 0, 0);
}
else if (normalizedBeat >= 2f && comboIndex < 5)
{
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++;
anim.Play("ComboCrouchPunch", 0, 0);
}
else if (normalizedBeat >= 2.05f)
{
if (hitCombo)
{
if (PlayerInput.AltPressedUp())
{
ComboPow();
}
}
else
{
// fail anim
anim.Play("Idle");
2022-01-20 07:26:53 +00:00
ResetCombo();
2022-01-20 01:48:52 +00:00
}
}
}
else
{
if (PlayerInput.AltPressed())
{
Combo();
}
}
if (hitBarrel)
2021-12-29 06:52:48 +00:00
{
if (PlayerInput.PressedUp())
{
if (kickC != null) StopCoroutine(kickC);
hitBarrel = false;
anim.Play("Kick", 0, 0);
}
if (Conductor.instance.songPositionInBeats > barrelBeat + 3)
{
if (kickC != null) StopCoroutine(kickC);
hitBarrel = false;
// should be inebetween for this
anim.Play("Idle", 0, 0);
}
}
else
{
2022-01-20 01:48:52 +00:00
if (PlayerInput.Pressed() && !inCombo)
{
Swing();
}
2021-12-29 06:52:48 +00:00
}
}
2022-01-20 01:48:52 +00:00
private void Combo()
{
var EligibleHits = KarateMan.instance.EligibleCombos;
bool canHit = (EligibleHits.Count > 0) && (currentComboHitInList < EligibleHits.Count);
if (canHit)
{
if (KarateMan.instance.EligibleCombos[currentComboHitInList].perfect)
{
comboBeat = EligibleHits[currentComboHitInList].createBeat;
hitCombo = true;
2022-01-20 07:26:53 +00:00
// Debug.Break();
2022-01-20 01:48:52 +00:00
}
else
{
comboBeat = Conductor.instance.songPositionInBeats;
hitCombo = false;
}
}
else
{
comboBeat = Conductor.instance.songPositionInBeats;
hitCombo = false;
}
inCombo = true;
}
private void ComboPow()
{
if (!hitCombo || !inCombo || !hitCombo && !inCombo) return;
anim.Play("Pow", 0, 0);
if (currentComboPots[comboPotIndex].state.perfect)
{
2022-01-20 07:26:53 +00:00
BarrelDestroy(currentComboPots[comboPotIndex], true);
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-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();
}
private IEnumerator PrepareKick()
{
barrelBeat = Conductor.instance.songPositionInBeats;
hitBarrel = true;
yield return new WaitForSeconds(0.17f);
anim.Play("KickPrepare", 0, 0);
}
2021-12-29 06:52:48 +00:00
private void Swing()
{
var EligibleHits = KarateMan.instance.EligibleHits;
bool canHit = (EligibleHits.Count > 0) && (currentHitInList < EligibleHits.Count);
2021-12-30 08:26:18 +00:00
bool punchLeft = true;
int events = KarateMan.instance.MultipleEventsAtOnce();
2021-12-30 08:26:18 +00:00
for (int pt = 0; pt < events; pt++)
{
if (canHit)
2021-12-29 06:52:48 +00:00
{
Pot p = EligibleHits[currentHitInList].gameObject.GetComponent<Pot>();
2021-12-30 08:26:18 +00:00
if (p.type == 2 || p.type == 3 || p.type == 4)
{
punchLeft = false;
}
else
{
punchLeft = true;
}
2021-12-30 08:26:18 +00:00
if (KarateMan.instance.EligibleHits[currentHitInList].perfect)
2021-12-30 08:26:18 +00:00
{
Jukebox.PlayOneShotGame(p.hitSnd);
p.Hit();
HitEffectF(HitEffect.transform.localPosition);
switch (p.type)
{
case 0:
// HitParticle.Play();
break;
case 1:
GameObject bulbHit = Instantiate(BulbHit);
bulbHit.transform.parent = BulbHit.transform.parent;
bulbHit.SetActive(true);
Destroy(bulbHit, 0.7f);
break;
case 2:
// RockParticle.Play();
break;
case 4:
if (kickC != null) StopCoroutine(kickC);
kickC = StartCoroutine(PrepareKick());
2022-01-20 07:26:53 +00:00
BarrelDestroy(p, false);
break;
}
}
else
{
Jukebox.PlayOneShot("miss");
p.Miss();
2021-12-30 08:26:18 +00:00
}
p.isEligible = false;
p.RemoveObject(currentHitInList);
2021-12-29 06:52:48 +00:00
}
}
2022-01-17 19:23:18 +00:00
if (!canHit)
Jukebox.PlayOneShotGame("karateman/swingNoHit");
if (punchLeft)
anim.Play("PunchLeft", 0, 0);
else
anim.Play("PunchRight", 0, 0);
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
2022-01-20 07:26:53 +00:00
private void BarrelDestroy(Pot p, bool combo)
2022-01-20 01:48:52 +00:00
{
for (int i = 0; i < 8; i++)
{
GameObject be = new GameObject();
be.transform.localPosition = p.Holder.transform.localPosition;
be.transform.parent = this.transform.parent;
be.transform.localScale = p.Holder.transform.localScale;
BarrelDestroyEffect bde = be.AddComponent<BarrelDestroyEffect>();
Vector3 pos = be.transform.localPosition;
SpriteRenderer sprite = be.AddComponent<SpriteRenderer>();
bde.shadow = Instantiate(p.Shadow, transform.parent);
bde.shadow.transform.position = p.Shadow.transform.position;
bde.shadow.transform.localScale = p.Shadow.transform.lossyScale;
bde.index = i;
2022-01-20 07:26:53 +00:00
bde.combo = combo;
2022-01-20 01:48:52 +00:00
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
}
}