HeavenStudioPlus/Assets/Scripts/Games/SickBeats/Virus.cs

253 lines
8.3 KiB
C#
Raw Normal View History

2024-03-10 00:36:43 +00:00
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;
bool isJust = false; // not fundamental solution
2024-03-10 00:36:43 +00:00
private SickBeats game;
public void Init()
{
game = SickBeats.instance;
ChangeColor();
}
public void Appear()
{
if (startBeat >= game.gameEndBeat) return;
2024-03-10 00:36:43 +00:00
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("sickBeats/appear"+UnityEngine.Random.Range(0, 2).ToString(), startBeat),
2024-03-10 00:36:43 +00:00
});
BeatAction.New(game, new() {new BeatAction.Action(startBeat, delegate {
VirusAnim("appear");
})});
isJust = false;
PlayerInput.InputAction InputAction;
if (PlayerInput.PlayerHasControl() && PlayerInput.CurrentControlStyle is InputSystem.InputController.ControlStyles.Touch)
{
InputAction = SickBeats.InputAction_FlickPress;
}
else
{
InputAction = position switch {
0 => SickBeats.InputAction_Right,
1 => SickBeats.InputAction_Up,
2 => SickBeats.InputAction_Left,
3 => SickBeats.InputAction_Down,
_ => null, //This switch needed a default parameter - Marc
};
}
// if (GameManager.instance.autoplay)
// {
// game.ScheduleAutoplayInput(startBeat, 1, InputAction, Just, Miss, Empty);
// }
// else
// {
// game.ScheduleUserInput(startBeat, 1, InputAction, Just, Miss, Empty, CanJust);
// }
game.ScheduleMissableInput(startBeat, 1, InputAction, Just, Miss, Empty, CanJust);
var dir = position;
BeatAction.New(game, new() {
new BeatAction.Action(startBeat, delegate { game.isPrepare[dir] = true;}),
new BeatAction.Action((startBeat+1.5f), delegate { game.isPrepare[dir] = false;}),
});
2024-03-10 00:36:43 +00:00
}
public void Dash()
{
SoundByte.PlayOneShotGame("sickBeats/dash");
2024-03-10 00:36:43 +00:00
VirusAnim("dash");
}
public void Summon()
2024-03-10 00:36:43 +00:00
{
VirusAnim("summon");
2024-03-10 00:36:43 +00:00
}
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),
});
2024-03-10 00:36:43 +00:00
BeatAction.New(game, new() {
new BeatAction.Action(startBeat + 2, delegate {
2024-03-10 00:36:43 +00:00
virusAnim.DoScaledAnimationAsync("laugh", 0.5f);
virusAnim.DoScaledAnimationAsync("enter", 0.5f);
}),
new BeatAction.Action(startBeat + 4, delegate {
2024-03-10 00:36:43 +00:00
virusAnim.DoScaledAnimationAsync("hide", 0.5f);
game.orgAnim.DoScaledAnimationAsync("damage", 0.5f);
game.orgAlive = false;
}),
new BeatAction.Action(startBeat + 5, delegate {
2024-03-10 00:36:43 +00:00
game.orgAnim.DoScaledAnimationAsync("vanish", 0.5f);
}),
new BeatAction.Action(startBeat + 6, delegate {
2024-03-10 00:36:43 +00:00
virusAnim.DoScaledAnimationAsync("laugh", 0.5f);
}),
new BeatAction.Action(startBeat + 7, delegate {
2024-03-10 00:36:43 +00:00
game.orgAnim.DoScaledAnimationAsync("idleAdd", 0.5f);
game.orgAnim.DoScaledAnimationAsync("appear", 0.5f);
game.orgAlive = true;
Destroy(gameObject);
}),
});
Debug.Log(startBeat);
Debug.Log(game.docShockBeat);
if (startBeat + 6 >= game.docShockBeat + 3)
{
game.docShockBeat = startBeat + 6;
BeatAction.New(game, new() {
new BeatAction.Action(startBeat + 6, delegate {
game.docShock = true;
game.doctorAnim.DoScaledAnimationAsync("shock0", 0.5f);
}),
new BeatAction.Action(startBeat + 7, delegate {
game.doctorAnim.DoScaledAnimationAsync("shock1", 0.5f);
}),
new BeatAction.Action(startBeat + 9, delegate {
game.docShock = false;
game.doctorAnim.DoScaledAnimationAsync("idle", 0.5f);
}),
});
}
2024-03-10 00:36:43 +00:00
}
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;
isJust = true;
2024-03-10 00:36:43 +00:00
if (life < 0)
{
if (state >= 1f)
{
SoundByte.PlayOneShotGame("sickBeats/bad");
2024-03-10 00:36:43 +00:00
VirusAnim("stabLate");
KeyAnim("stabLate");
}
else if (state <= -1f)
{
SoundByte.PlayOneShotGame("sickBeats/bad");
2024-03-10 00:36:43 +00:00
VirusAnim("stabFast");
KeyAnim("stabFast");
}
else
{
SoundByte.PlayOneShotGame("sickBeats/hit");
2024-03-10 00:36:43 +00:00
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)
{
var dir = position;
if (dir >= 0 && dir <= 3)
{
game.isMiss[dir] = true;
BeatAction.New(game, new() {new BeatAction.Action((startBeat+1.5f), delegate { game.isMiss[dir] = false;})});
}
2024-03-10 00:36:43 +00:00
Dash();
Move();
}
private void Empty(PlayerActionEvent caller) { }
private bool CanJust() {
if (position < 0 || position > 3) return false;
return game.isForkPop[position] || isJust;
2024-03-10 00:36:43 +00:00
}
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];
}
2024-03-10 00:36:43 +00:00
}
}
}