HeavenStudio/Assets/Scripts/Games/SickBeats/Virus.cs
fu-majime 8176ce5866 sfx
2024-03-10 10:29:45 +09:00

216 lines
6.8 KiB
C#

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_SickBeats
{
public class Virus : MonoBehaviour
{
[Header("References")]
[SerializeField] SpriteRenderer[] renderers;
[SerializeField] Animator virusAnim;
[Header("Variables")]
public double startBeat;
public int position;
public int life = 1;
private SickBeats game;
public void Init()
{
game = SickBeats.instance;
ChangeColor();
}
public void Appear()
{
var InputAction = position switch {
0 => SickBeats.InputAction_Right,
1 => SickBeats.InputAction_Up,
2 => SickBeats.InputAction_Left,
3 => SickBeats.InputAction_Down,
};
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("sickBeats/appear"+UnityEngine.Random.Range(0, 2).ToString(), startBeat),
});
BeatAction.New(game, new() {new BeatAction.Action(startBeat, delegate {
VirusAnim("appear");
})});
game.ScheduleInput(startBeat, 1, InputAction, Just, Miss, Empty, CanJust);
}
public void Dash()
{
SoundByte.PlayOneShotGame("sickBeats/dash");
VirusAnim("dash");
}
public void Summon()
{
VirusAnim("summon");
}
public void Move()
{
position++;
if (position <= 3)
{
startBeat+=2;
Appear();
}
else
{
Kill();
}
}
public void Kill()
{
game.ScoreMiss();
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("sickBeats/virusIn", startBeat + 2),
new MultiSound.Sound("sickBeats/miss", startBeat + 4),
new MultiSound.Sound("sickBeats/fadeout", startBeat + 5),
});
var actions = new List<BeatAction.Action>() {
new BeatAction.Action(startBeat + 2, delegate {
virusAnim.DoScaledAnimationAsync("laugh", 0.5f);
virusAnim.DoScaledAnimationAsync("enter", 0.5f);
}),
new BeatAction.Action(startBeat + 4, delegate {
virusAnim.DoScaledAnimationAsync("hide", 0.5f);
game.orgAnim.DoScaledAnimationAsync("damage", 0.5f);
game.orgAlive = false;
}),
new BeatAction.Action(startBeat + 5, delegate {
game.orgAnim.DoScaledAnimationAsync("vanish", 0.5f);
}),
new BeatAction.Action(startBeat + 6, delegate {
virusAnim.DoScaledAnimationAsync("laugh", 0.5f);
}),
new BeatAction.Action(startBeat + 7, delegate {
game.orgAnim.DoScaledAnimationAsync("idleAdd", 0.5f);
game.orgAnim.DoScaledAnimationAsync("appear", 0.5f);
game.orgAlive = true;
Destroy(gameObject);
}),
new BeatAction.Action(startBeat + 9, delegate {
game.docShock = false;
game.doctorAnim.DoScaledAnimationAsync("idle", 0.5f);
}),
};
actions.Add(new BeatAction.Action(startBeat + 6, delegate {
game.docShock = true;
game.doctorAnim.DoScaledAnimationAsync("shock0", 0.5f);
}));
actions.Add(new BeatAction.Action(startBeat + 7, delegate {
game.doctorAnim.DoScaledAnimationAsync("shock1", 0.5f);
}));
actions.Add(new BeatAction.Action(startBeat + 9, delegate {
game.docShock = false;
game.doctorAnim.DoScaledAnimationAsync("idle", 0.5f);
}));
BeatAction.New(game, actions);
}
private void Just(PlayerActionEvent caller, float state)
{
life--;
var dir = position;
BeatAction.New(game, new() {new BeatAction.Action((startBeat+1) + game.RefillBeat, delegate { game.RepopFork(dir);})});
game.isForkPop[dir] = false;
if (life < 0)
{
if (state >= 1f)
{
SoundByte.PlayOneShotGame("sickBeats/bad");
VirusAnim("stabLate");
KeyAnim("stabLate");
}
else if (state <= -1f)
{
SoundByte.PlayOneShotGame("sickBeats/bad");
VirusAnim("stabFast");
KeyAnim("stabFast");
}
else
{
SoundByte.PlayOneShotGame("sickBeats/hit");
VirusAnim("stab");
KeyAnim("stab");
BeatAction.New(game, new() {new BeatAction.Action((startBeat+2), delegate {
game.doctorAnim.DoScaledAnimationAsync("Vsign", 0.5f);
})});
}
}
else
{
SoundByte.PlayOneShotGame("sickBeats/resist");
VirusAnim("resist");
KeyAnim("resist");
ChangeColor();
Move();
}
}
private void Miss(PlayerActionEvent caller)
{
Dash();
Move();
}
private void Empty(PlayerActionEvent caller) { }
private bool CanJust() {
if (position < 0 || position > 3) return false;
return game.isForkPop[position];
}
void VirusAnim(string animation)
{
virusAnim.DoScaledAnimationAsync(animation, 0.5f);
virusAnim.DoScaledAnimationAsync(animation+position.ToString(), 0.5f);
}
void KeyAnim(string animation)
{
game.keyAnim.Play("push");
game.forkAnims[position].DoScaledAnimationAsync(animation+position.ToString(), 0.5f);
}
void Update()
{
var cond = Conductor.instance;
if (cond.isPlaying && !cond.isPaused)
{
double beat = cond.songPositionInBeats;
if (life < 0 && beat >= startBeat + 3) Destroy(gameObject);
}
}
void ChangeColor()
{
foreach (var renderer in renderers)
{
renderer.material = game.RecolorMats[life];
}
}
}
}