2022-02-16 17:04:28 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_BuiltToScaleDS
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-05-07 20:33:15 +00:00
|
|
|
public class Blocks : MonoBehaviour
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
public double createBeat;
|
2022-02-16 17:04:28 +00:00
|
|
|
public float createLength;
|
|
|
|
public Animator anim;
|
|
|
|
|
|
|
|
private bool moving = true;
|
|
|
|
private BuiltToScaleDS game;
|
2023-06-10 19:17:06 +00:00
|
|
|
double windupBeat;
|
|
|
|
double hitBeat;
|
|
|
|
double sinkBeat;
|
2022-02-16 17:04:28 +00:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
game = BuiltToScaleDS.instance;
|
2023-01-15 04:33:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
windupBeat = createBeat + (createLength * 4f);
|
|
|
|
hitBeat = windupBeat + createLength;
|
|
|
|
sinkBeat = hitBeat + (createLength * 2f);
|
|
|
|
|
|
|
|
game.ScheduleInput(windupBeat, createLength, InputType.STANDARD_DOWN, Just, Miss, Out);
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!moving) return;
|
2023-06-10 19:17:06 +00:00
|
|
|
double currentBeat = Conductor.instance.songPositionInBeatsAsDouble;
|
2022-02-16 17:04:28 +00:00
|
|
|
|
|
|
|
var shooterState = game.shooterAnim.GetCurrentAnimatorStateInfo(0);
|
|
|
|
if (currentBeat > windupBeat && currentBeat < hitBeat
|
|
|
|
&& !shooterState.IsName("Windup")
|
2023-01-15 04:33:37 +00:00
|
|
|
&& !game.lastShotOut)
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
|
|
|
game.shooterAnim.Play("Windup", 0, 0);
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (moving && currentBeat < sinkBeat)
|
|
|
|
game.SetBlockTime(this, createBeat, createLength);
|
|
|
|
}
|
2022-02-16 17:04:28 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Just(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
var shooterState = game.shooterAnim.GetCurrentAnimatorStateInfo(0);
|
|
|
|
if (!shooterState.IsName("Windup")) return;
|
|
|
|
|
|
|
|
// near miss
|
|
|
|
if (state >= 1f || state <= -1f) {
|
|
|
|
NearMiss();
|
|
|
|
return;
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
// hit
|
|
|
|
Hit();
|
|
|
|
}
|
2022-02-16 17:04:28 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Miss(PlayerActionEvent caller)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
double sinkBeat = hitBeat + (createLength * 2f);
|
2023-01-15 04:33:37 +00:00
|
|
|
MultiSound.Play(
|
|
|
|
new MultiSound.Sound[] {
|
|
|
|
new MultiSound.Sound("builtToScaleDS/Sink", sinkBeat),
|
|
|
|
}, forcePlay: true
|
|
|
|
);
|
|
|
|
|
|
|
|
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
new BeatAction.Action(sinkBeat, delegate { moving = false; }),
|
|
|
|
});
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Out(PlayerActionEvent caller) {}
|
|
|
|
|
|
|
|
void Hit()
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
|
|
|
moving = false;
|
|
|
|
game.shootingThisFrame = true;
|
|
|
|
|
|
|
|
game.Shoot();
|
|
|
|
game.SpawnObject(BuiltToScaleDS.BTSObject.HitPieces);
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame("builtToScaleDS/Hit");
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
void NearMiss()
|
2022-02-16 17:04:28 +00:00
|
|
|
{
|
|
|
|
moving = false;
|
|
|
|
game.shootingThisFrame = true;
|
|
|
|
|
|
|
|
game.Shoot();
|
|
|
|
game.SpawnObject(BuiltToScaleDS.BTSObject.MissPieces);
|
|
|
|
Destroy(gameObject);
|
2022-02-17 02:59:46 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame("builtToScaleDS/Crumble");
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|