2022-02-14 08:53:58 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-02-15 05:17:53 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-14 08:53:58 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_RhythmRally
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
public class Paddlers : MonoBehaviour
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
|
|
|
private RhythmRally game;
|
|
|
|
private Animator playerAnim;
|
|
|
|
private Animator opponentAnim;
|
|
|
|
private Conductor cond;
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
public void Init()
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
|
|
|
game = RhythmRally.instance;
|
|
|
|
playerAnim = game.playerAnim;
|
|
|
|
opponentAnim = game.opponentAnim;
|
|
|
|
cond = Conductor.instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (!game.served || game.missed || !game.started) return;
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
// Play "whoosh" sound here
|
2023-02-17 18:45:18 +00:00
|
|
|
playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ;
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ace()
|
|
|
|
{
|
|
|
|
game.served = false;
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
var hitBeat = cond.songPositionInBeatsAsDouble;
|
2022-02-14 08:53:58 +00:00
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
var bounceBeat = game.serveBeat + game.targetBeat + 1f;
|
2022-02-14 08:53:58 +00:00
|
|
|
|
|
|
|
if (game.rallySpeed == RhythmRally.RallySpeed.Slow)
|
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
bounceBeat = game.serveBeat + game.targetBeat + 2f;
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
else if (game.rallySpeed == RhythmRally.RallySpeed.SuperFast)
|
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
bounceBeat = game.serveBeat + game.targetBeat + 0.5f;
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 18:45:18 +00:00
|
|
|
playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ;
|
2022-02-14 08:53:58 +00:00
|
|
|
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Return", hitBeat), new MultiSound.Sound("rhythmRally/ReturnBounce", bounceBeat) });
|
2022-02-15 05:17:53 +00:00
|
|
|
BounceFX(bounceBeat);
|
2023-01-16 03:05:25 +00:00
|
|
|
game.ball.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NearMiss(float state)
|
|
|
|
{
|
|
|
|
MissBall();
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
2023-02-17 18:45:18 +00:00
|
|
|
playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ;
|
2023-01-16 03:05:25 +00:00
|
|
|
|
|
|
|
game.missCurve.KeyPoints[0].Position = game.ball.transform.position;
|
|
|
|
game.missCurve.transform.localScale = new Vector3(-state, 1f, 1f);
|
2023-06-10 19:17:06 +00:00
|
|
|
game.missBeat = cond.songPositionInBeatsAsDouble;
|
2023-01-16 03:05:25 +00:00
|
|
|
game.ball.SetActive(true);
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
void MissBall()
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
|
|
|
game.served = false;
|
|
|
|
game.missed = true;
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
var whistleBeat = game.serveBeat + game.targetBeat + 1f;
|
2022-02-14 08:53:58 +00:00
|
|
|
|
|
|
|
if (game.rallySpeed == RhythmRally.RallySpeed.Slow)
|
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
whistleBeat = game.serveBeat + game.targetBeat + 2f;
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
else if (game.rallySpeed == RhythmRally.RallySpeed.SuperFast)
|
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
whistleBeat = game.serveBeat + game.targetBeat + 0.5f;
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Whistle", whistleBeat) });
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void BounceFX(double bounceBeat)
|
2022-02-15 05:17:53 +00:00
|
|
|
{
|
|
|
|
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(bounceBeat, delegate
|
|
|
|
{
|
|
|
|
GameObject ballHitFX2 = Instantiate(RhythmRally.instance.ballHitFX.gameObject, RhythmRally.instance.gameObject.transform);
|
|
|
|
ballHitFX2.SetActive(true);
|
|
|
|
ballHitFX2.transform.position = new Vector3(ballHitFX2.transform.position.x, ballHitFX2.transform.position.y, RhythmRally.instance.ball.transform.position.z);
|
|
|
|
ballHitFX2.GetComponent<SpriteRenderer>().DOColor(new Color(0, 0, 0, 0), 0.65f).SetEase(Ease.OutExpo).OnComplete(delegate { Destroy(ballHitFX2); });
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
public void Just(PlayerActionEvent caller, float state)
|
2022-02-14 08:53:58 +00:00
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
if (state >= 1f || state <= -1f) {
|
|
|
|
NearMiss(state);
|
|
|
|
return;
|
|
|
|
}
|
2022-02-14 08:53:58 +00:00
|
|
|
Ace();
|
|
|
|
}
|
2023-01-16 03:05:25 +00:00
|
|
|
|
|
|
|
public void Miss(PlayerActionEvent caller)
|
|
|
|
{
|
|
|
|
MissBall();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Out(PlayerActionEvent caller) {}
|
2022-02-14 08:53:58 +00:00
|
|
|
}
|
|
|
|
}
|