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

140 lines
4.1 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;
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()
{
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
{
if (PlayerInput.Pressed())
{
Swing();
}
2021-12-29 06:52:48 +00:00
}
}
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;
2021-12-29 06:52:48 +00:00
if (canHit)
{
2021-12-30 08:26:18 +00:00
Pot p = EligibleHits[currentHitInList].gameObject.GetComponent<Pot>();
2022-01-01 18:54:17 +00:00
if (p.type == 2 || p.type == 3 || p.type == 4)
2021-12-30 08:26:18 +00:00
{
punchLeft = false;
}
else
{
punchLeft = true;
}
2021-12-29 06:52:48 +00:00
if (KarateMan.instance.EligibleHits[currentHitInList].perfect)
{
2021-12-30 08:26:18 +00:00
Jukebox.PlayOneShotGame(p.hitSnd);
p.Hit();
GameObject hit = Instantiate(HitEffect);
hit.transform.parent = HitEffect.transform.parent;
hit.SetActive(true);
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());
break;
2021-12-30 08:26:18 +00:00
}
Destroy(hit, 0.04f);
2021-12-29 06:52:48 +00:00
}
else
{
Jukebox.PlayOneShot("miss");
2022-01-01 18:54:17 +00:00
p.Miss();
2021-12-29 06:52:48 +00:00
}
2021-12-30 08:26:18 +00:00
p.isEligible = false;
p.RemoveObject(currentHitInList, EligibleHits);
2021-12-29 06:52:48 +00:00
}
else
{
Jukebox.PlayOneShotGame("karateman/swingNoHit");
}
2021-12-30 08:26:18 +00:00
if (punchLeft)
anim.Play("PunchLeft", 0, 0);
else
anim.Play("PunchRight", 0, 0);
2021-12-29 06:52:48 +00:00
}
}
}