2022-04-10 21:37:37 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_TrickClass
|
|
|
|
{
|
|
|
|
public class MobTrickObj : PlayerActionObject
|
|
|
|
{
|
|
|
|
public bool flyType;
|
|
|
|
public float startBeat;
|
|
|
|
bool flying = true;
|
2022-04-11 13:56:37 +00:00
|
|
|
bool dodged = false;
|
2022-04-11 01:05:33 +00:00
|
|
|
bool miss = false;
|
2022-04-10 21:37:37 +00:00
|
|
|
|
|
|
|
float flyBeats;
|
2022-04-11 01:05:33 +00:00
|
|
|
float dodgeBeats;
|
|
|
|
public int type;
|
2022-04-10 21:37:37 +00:00
|
|
|
|
|
|
|
[NonSerialized] public BezierCurve3D curve;
|
|
|
|
|
|
|
|
private TrickClass game;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
game = TrickClass.instance;
|
2022-04-10 22:29:31 +00:00
|
|
|
flyBeats = flyType ? 4f : 2f;
|
2022-04-11 01:05:33 +00:00
|
|
|
dodgeBeats = flyType ? 2f : 1f;
|
2022-04-10 22:29:31 +00:00
|
|
|
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
|
|
|
|
transform.position = curve.GetPoint(flyPos);
|
2022-04-10 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2022-04-10 22:29:31 +00:00
|
|
|
if (flying)
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
|
2022-04-11 01:05:33 +00:00
|
|
|
if (flyPos <= 1f)
|
2022-04-10 23:15:59 +00:00
|
|
|
{
|
2022-04-11 01:05:33 +00:00
|
|
|
if (!miss)
|
|
|
|
{
|
|
|
|
flyPos *= 0.9f;
|
|
|
|
}
|
|
|
|
Vector3 lastPos = transform.position;
|
|
|
|
Vector3 nextPos = curve.GetPoint(flyPos);
|
|
|
|
|
|
|
|
if (flyType)
|
|
|
|
{
|
|
|
|
Vector3 direction = (nextPos - lastPos).normalized;
|
|
|
|
float rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
|
|
|
this.transform.eulerAngles = new Vector3(0, 0, rotation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (360f * Time.deltaTime));
|
|
|
|
}
|
|
|
|
|
|
|
|
transform.position = nextPos;
|
2022-04-10 23:15:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-11 01:05:33 +00:00
|
|
|
transform.position = curve.GetPoint(1f);
|
2022-04-10 23:15:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-10 22:29:31 +00:00
|
|
|
if (flyPos > 1f)
|
|
|
|
{
|
2022-04-11 01:05:33 +00:00
|
|
|
if (Conductor.instance.GetPositionFromBeat(startBeat, flyBeats + 1f) >= 1f)
|
|
|
|
{
|
|
|
|
GameObject.Destroy(gameObject);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 13:56:37 +00:00
|
|
|
if (!(dodged || miss))
|
2022-04-11 01:05:33 +00:00
|
|
|
{
|
|
|
|
float normalizedBeat = cond.GetPositionFromMargin(startBeat + dodgeBeats, 1f);
|
|
|
|
StateCheck(normalizedBeat);
|
|
|
|
|
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
2022-04-11 13:56:37 +00:00
|
|
|
dodged = true;
|
2022-04-11 01:05:33 +00:00
|
|
|
MultiSound.Play(new MultiSound.Sound[] {
|
|
|
|
new MultiSound.Sound("trickClass/ball_impact", startBeat + flyBeats, volume: 0.75f),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no input?
|
|
|
|
if (Conductor.instance.GetPositionFromBeat(startBeat, dodgeBeats) >= Minigame.EndTime())
|
|
|
|
{
|
2022-04-11 14:57:27 +00:00
|
|
|
Jukebox.PlayOneShotGame(GetDodgeSound());
|
2022-04-11 01:05:33 +00:00
|
|
|
miss = true;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case (int) TrickClass.TrickObjType.Plane:
|
|
|
|
curve = TrickClass.instance.planeMissCurve;
|
|
|
|
flyBeats = 4f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
curve = TrickClass.instance.ballMissCurve;
|
2022-04-11 13:56:37 +00:00
|
|
|
flyBeats = 1.25f;
|
2022-04-11 01:05:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
startBeat += dodgeBeats;
|
|
|
|
}
|
2022-04-10 22:29:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-10 21:37:37 +00:00
|
|
|
}
|
2022-04-11 01:05:33 +00:00
|
|
|
|
|
|
|
public override void OnAce()
|
|
|
|
{
|
|
|
|
TrickClass.instance.PlayerDodge();
|
2022-04-11 13:56:37 +00:00
|
|
|
dodged = true;
|
2022-04-11 01:05:33 +00:00
|
|
|
MultiSound.Play(new MultiSound.Sound[] {
|
2022-04-11 14:57:27 +00:00
|
|
|
new MultiSound.Sound(GetDodgeSound(), startBeat + flyBeats, volume: 0.5f),
|
2022-04-11 01:05:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:57:27 +00:00
|
|
|
public string GetDodgeSound()
|
2022-04-11 01:05:33 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
default:
|
2022-04-11 14:57:27 +00:00
|
|
|
return "trickClass/ball_impact";
|
2022-04-11 01:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-10 21:37:37 +00:00
|
|
|
}
|
|
|
|
}
|