HeavenStudioPlus/Assets/Scripts/Games/TrickClass/MobTrickObj.cs

152 lines
4.8 KiB
C#
Raw Normal View History

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 miss = false;
2022-04-10 21:37:37 +00:00
float flyBeats;
float dodgeBeats;
public int type;
2022-04-10 21:37:37 +00:00
[NonSerialized] public BezierCurve3D curve;
PlayerActionEvent hitProg;
2022-04-10 21:37:37 +00:00
private TrickClass game;
private void Awake()
{
game = TrickClass.instance;
2022-04-10 22:29:31 +00:00
flyBeats = flyType ? 4f : 2f;
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);
hitProg = game.ScheduleInput(startBeat, dodgeBeats, InputType.STANDARD_DOWN, DodgeJustOrNg, DodgeMiss, DodgeThrough);
2022-04-10 21:37:37 +00:00
}
// Update is called once per frame
void Update()
{
var cond = Conductor.instance;
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
if (flyPos <= 1f)
2022-04-10 22:29:31 +00:00
{
if (!miss)
{
flyPos *= 0.95f;
}
Vector3 lastPos = transform.position;
Vector3 nextPos = curve.GetPoint(flyPos);
2022-04-10 22:29:31 +00:00
if (flyType)
2022-04-10 23:15:59 +00:00
{
Vector3 direction = (nextPos - lastPos).normalized;
float rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
this.transform.eulerAngles = new Vector3(0, 0, rotation);
2022-04-10 23:15:59 +00:00
}
else
{
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (360f * Time.deltaTime));
2022-04-10 23:15:59 +00:00
}
transform.position = nextPos;
}
else
{
transform.position = curve.GetPoint(miss ? 1f : 0.95f);
}
if (flyPos > 1f)
{
if (Conductor.instance.GetPositionFromBeat(startBeat, flyBeats + 1f) >= 1f)
{
GameObject.Destroy(gameObject);
return;
2022-04-10 22:29:31 +00:00
}
}
2022-04-10 21:37:37 +00:00
}
public string GetDodgeSound()
{
switch (type)
{
default:
return "trickClass/ball_impact";
}
}
public void DoObjMiss()
{
miss = true;
switch (type)
{
case (int) TrickClass.TrickObjType.Plane:
curve = game.planeMissCurve;
flyBeats = 4f;
Vector3 lastPos = curve.GetPoint(0);
Vector3 nextPos = curve.GetPoint(0.000001f);
Vector3 direction = (nextPos - lastPos).normalized;
float rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
this.transform.eulerAngles = new Vector3(0, 0, rotation);
transform.position = nextPos;
break;
default:
curve = game.ballMissCurve;
flyBeats = 1.25f;
break;
}
startBeat += dodgeBeats;
}
public void DodgeJustOrNg(PlayerActionEvent caller, float state)
{
if (game.playerCanDodge <= Conductor.instance.songPositionInBeats)
{
if (state <= -1f || state >= 1f)
{
//NG
game.PlayerDodgeNg();
MultiSound.Play(new MultiSound.Sound[] {
new MultiSound.Sound(GetDodgeSound(), startBeat + flyBeats, volume: 0.4f),
});
Jukebox.PlayOneShotGame(GetDodgeSound(), volume: 0.6f);
Jukebox.PlayOneShot("miss");
DoObjMiss();
}
else
{
//just
game.PlayerDodge();
Jukebox.PlayOneShotGame("trickClass/player_dodge_success", volume: 0.8f, pitch: UnityEngine.Random.Range(0.95f, 1.15f));
MultiSound.Play(new MultiSound.Sound[] {
new MultiSound.Sound(GetDodgeSound(), startBeat + flyBeats, volume: 0.4f),
});
}
}
}
public void DodgeMiss(PlayerActionEvent caller)
{
Jukebox.PlayOneShotGame(GetDodgeSound());
DoObjMiss();
game.PlayerThrough();
}
public void DodgeThrough(PlayerActionEvent caller) {}
2022-04-10 21:37:37 +00:00
}
}