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

200 lines
6.9 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 KarateMan : Minigame
{
2022-01-01 18:54:17 +00:00
public GameObject Pot, Bomb;
2021-12-30 08:26:18 +00:00
public KarateJoe KarateJoe;
2021-12-29 06:52:48 +00:00
2022-01-20 01:48:52 +00:00
public List<Minigame.Eligible> EligibleCombos = new List<Minigame.Eligible>();
2021-12-29 06:52:48 +00:00
public static KarateMan instance { get; set; }
2021-12-30 08:26:18 +00:00
public Sprite[] ObjectSprites;
2022-01-03 15:15:48 +00:00
public Sprite[] BarrelSprites;
2021-12-30 08:26:18 +00:00
public List<BGSpriteC> BGSprites;
public SpriteRenderer BGSprite;
private bool bgEnabled;
2022-01-19 05:40:49 +00:00
private float newBeat, newBeatBop;
2022-01-03 22:42:43 +00:00
private float bopLength;
private float bopBeat;
2022-01-19 05:40:49 +00:00
private float bgBeat;
2022-01-20 01:48:52 +00:00
public GameObject comboRef;
[System.Serializable]
public class BGSpriteC
{
public List<Sprite> Sprites;
}
2021-12-29 06:52:48 +00:00
private void Awake()
{
instance = this;
}
2022-01-20 01:48:52 +00:00
public void Combo(float beat)
{
comboRef.GetComponent<Animator>().enabled = true;
comboRef.GetComponent<Animator>().Play("comboRef");
Jukebox.PlayOneShotGame("karateman/barrelOutCombos");
Shoot(beat, 0, true, "PotCombo1", 0, new Vector2(-0.94f, -2.904f));
Shoot(beat + 0.25f, 0, true, "PotCombo2", 1, new Vector2(-0.94f, -2.904f));
Shoot(beat + 0.5f, 0, true, "PotCombo3", 2, new Vector2(-0.776f, -3.162f));
Shoot(beat + 0.75f, 0, true, "PotCombo4", 3, new Vector2(1.453f, -3.162f));
Shoot(beat + 1f, 0, true, "PotCombo5", 4, new Vector2(0.124f, -3.123f));
Shoot(beat + 1.5f, 4, true, "PotCombo6", 5, new Vector2(-1.333f, -2.995f));
2022-01-21 01:24:30 +00:00
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("karateman/punchy1", beat + 1f),
new MultiSound.Sound("karateman/punchy2", beat + 1.25f),
new MultiSound.Sound("karateman/punchy3", beat + 1.5f),
new MultiSound.Sound("karateman/punchy4", beat + 1.75f),
new MultiSound.Sound("karateman/ko", beat + 2f),
new MultiSound.Sound("karateman/pow", beat + 2.5f)
});
2022-01-20 01:48:52 +00:00
}
public void Shoot(float beat, int type, bool combo = false, string throwAnim = "", int comboIndex = 0, Vector2 endShadowPos = new Vector2())
{
GameObject pot = Instantiate(Pot);
pot.transform.parent = Pot.transform.parent;
Pot p = pot.GetComponent<Pot>();
pot.SetActive(true);
p.startBeat = beat;
p.createBeat = beat;
p.isThrown = true;
p.type = type;
p.Sprite.GetComponent<SpriteRenderer>().sprite = ObjectSprites[type];
if (combo)
{
p.comboIndex = comboIndex;
p.throwAnim = throwAnim;
p.combo = true;
KarateJoe.currentComboPots.Add(p);
p.endShadowThrowPos = endShadowPos;
}
else
{
p.throwAnim = "PotThrow";
string outSnd = "";
switch (type)
{
case 0:
if (Starpelly.Mathp.GetDecimalFromFloat(beat) == 0f)
outSnd = "karateman/objectOut";
else
outSnd = "karateman/offbeatObjectOut";
p.hitSnd = "karateman/potHit";
break;
case 1:
outSnd = "karateman/lightbulbOut";
p.hitSnd = "karateman/lightbulbHit";
break;
case 2:
outSnd = "karateman/objectOut";
p.hitSnd = "karateman/rockHit";
break;
case 3:
outSnd = "karateman/objectOut";
p.hitSnd = "karateman/soccerHit";
break;
case 4:
p.kick = true;
outSnd = "karateman/barrelOutKicks";
p.hitSnd = "karateman/barrelBreak";
2022-01-21 01:24:30 +00:00
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("karateman/punchKick1", beat + 1f),
new MultiSound.Sound("karateman/punchKick2", beat + 1.5f),
new MultiSound.Sound("karateman/punchKick3", beat + 1.75f),
new MultiSound.Sound("karateman/punchKick4", beat + 2.25f)
});
2022-01-20 01:48:52 +00:00
break;
}
p.endShadowThrowPos = new Vector2(-1.036f, -2.822f);
Jukebox.PlayOneShotGame(outSnd);
}
}
private void Update()
{
2022-01-19 05:40:49 +00:00
if (Conductor.instance.ReportBeat(ref newBeat))
{
2022-01-03 22:42:43 +00:00
if (bgEnabled)
{
2022-01-19 05:40:49 +00:00
if (bgBeat % 2 == 0)
{
BGSprite.sprite = BGSprites[0].Sprites[1];
2022-01-19 05:40:49 +00:00
}
else
2022-01-19 05:40:49 +00:00
{
BGSprite.sprite = BGSprites[0].Sprites[2];
2022-01-19 05:40:49 +00:00
}
bgBeat++;
2022-01-03 22:42:43 +00:00
}
2022-01-19 05:40:49 +00:00
}
2022-01-19 05:40:49 +00:00
if (Conductor.instance.ReportBeat(ref newBeatBop, bopBeat % 1))
{
2022-01-03 22:42:43 +00:00
if (Conductor.instance.songPositionInBeats >= bopBeat && Conductor.instance.songPositionInBeats < bopBeat + bopLength)
{
2022-01-19 05:40:49 +00:00
float compare = KarateJoe.anim.GetCurrentAnimatorStateInfo(0).speed;
if (KarateJoe.anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= compare && !KarateJoe.anim.IsInTransition(0))
KarateJoe.anim.Play("Bop", 0, 0);
}
}
}
public void BGFXOn()
{
bgEnabled = true;
}
public void BGFXOff()
{
bgEnabled = false;
BGSprite.sprite = BGSprites[0].Sprites[0];
}
2022-01-03 22:42:43 +00:00
public void Bop(float beat, float length)
2021-12-30 08:26:18 +00:00
{
2022-01-03 22:42:43 +00:00
bopLength = length;
bopBeat = beat;
2021-12-29 06:52:48 +00:00
}
2022-01-19 05:40:49 +00:00
2022-01-21 01:24:30 +00:00
public void Hit3(float beat)
{
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("karateman/hit", beat), new MultiSound.Sound("karateman/three", beat + 0.5f) });
}
2022-01-19 05:40:49 +00:00
public void CreateBomb(Transform parent, Vector2 scale, ref GameObject shadow)
{
GameObject bomb = Instantiate(Bomb, parent);
bomb.SetActive(true);
bomb.transform.localScale = scale;
shadow.transform.parent = bomb.transform;
shadow.transform.SetAsLastSibling();
bomb.GetComponent<Bomb>().shadow = shadow;
}
2021-12-29 06:52:48 +00:00
}
}