HeavenStudioPlus/Assets/Scripts/Games/RhythmRally/Paddlers.cs
minenice55 8fa4d74096 Alternate Control Styles Support (#554)
* add mouse controller

* support different control styles in options

deprecate old input check methods

* fully functional input actions system

* btsds InputAction

* blue bear InputAction

* more games

fix bugs with some input related systems

* coin toss re-toss

* cheer readers touch

* dog ninja touch

* multiple games

* last of the easy games' touch

* more specialized games

* specialized games 2

* finish ktb games

* remove legacy settings disclaimer

* "only" two games left

* karate man touch

* rockers touch

still needs fixes and bad judge strum

* DSGuy flicking animation

* playstyle chart property

* improve performance of minigame preloading

* improve look of cursor

make assetbundles use chunk-based compression
refactor assetbundle loading methods a bit

* prime conductor stream playback to stabilize seeking operations

* fix air rally swing on pad release

* use virtual mouse pointer

* add UniTask

* make BeatAction use UniTask

* implement UniTask to replace some coroutines

* add touch style UI elements and effects

games now support the ability to define two cursor colours if they need split screen touch inputs

* update plugins and buildscript

* implement thresholded pointer position clipping

* fix clamping

* instant show / hide

fix discord game SDK crashes
2023-10-29 19:44:47 +00:00

136 lines
4.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using HeavenStudio.Util;
using HeavenStudio.InputSystem;
namespace HeavenStudio.Games.Scripts_RhythmRally
{
public class Paddlers : MonoBehaviour
{
private RhythmRally game;
private Animator playerAnim;
private Animator opponentAnim;
private Conductor cond;
public void Init()
{
game = RhythmRally.instance;
playerAnim = game.playerAnim;
opponentAnim = game.opponentAnim;
cond = Conductor.instance;
}
void Update()
{
if (PlayerInput.CurrentControlStyle == InputController.ControlStyles.Touch && !GameManager.instance.autoplay)
{
if (PlayerInput.GetIsAction(RhythmRally.InputAction_BasicPress))
{
playerAnim.Play("Ready1");
}
if (PlayerInput.GetIsAction(RhythmRally.InputAction_BasicRelease))
{
playerAnim.Play("UnReady1");
}
}
else
{
if (!game.served || game.missed || !game.started) return;
}
if (PlayerInput.GetIsAction(RhythmRally.InputAction_FlickPress) && !game.IsExpectingInputNow(RhythmRally.InputAction_FlickPress))
{
// Play "whoosh" sound here
playerAnim.DoScaledAnimationAsync("Swing", 0.5f);
}
}
void Ace()
{
game.served = false;
var hitBeat = cond.songPositionInBeatsAsDouble;
var bounceBeat = game.serveBeat + game.targetBeat + 1f;
if (game.rallySpeed == RhythmRally.RallySpeed.Slow)
{
bounceBeat = game.serveBeat + game.targetBeat + 2f;
}
else if (game.rallySpeed == RhythmRally.RallySpeed.SuperFast)
{
bounceBeat = game.serveBeat + game.targetBeat + 0.5f;
}
playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ;
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Return", hitBeat), new MultiSound.Sound("rhythmRally/ReturnBounce", bounceBeat) });
BounceFX(bounceBeat);
game.ball.SetActive(true);
}
void NearMiss(float state)
{
MissBall();
SoundByte.PlayOneShot("miss");
playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ;
game.missCurve.KeyPoints[0].Position = game.ball.transform.position;
game.missCurve.transform.localScale = new Vector3(-state, 1f, 1f);
game.missBeat = cond.songPositionInBeatsAsDouble;
game.ball.SetActive(true);
}
void MissBall()
{
game.served = false;
game.missed = true;
var whistleBeat = game.serveBeat + game.targetBeat + 1f;
if (game.rallySpeed == RhythmRally.RallySpeed.Slow)
{
whistleBeat = game.serveBeat + game.targetBeat + 2f;
}
else if (game.rallySpeed == RhythmRally.RallySpeed.SuperFast)
{
whistleBeat = game.serveBeat + game.targetBeat + 0.5f;
}
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Whistle", whistleBeat) });
}
public void BounceFX(double bounceBeat)
{
BeatAction.New(this, 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); });
})
});
}
public void Just(PlayerActionEvent caller, float state)
{
if (state >= 1f || state <= -1f)
{
NearMiss(state);
return;
}
Ace();
}
public void Miss(PlayerActionEvent caller)
{
MissBall();
}
public void Out(PlayerActionEvent caller) { }
}
}