2021-12-21 01:10:49 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2021-12-21 01:10:49 +00:00
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_ForkLifter
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
public class Pea : MonoBehaviour
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
public double startBeat;
|
|
|
|
public int type;
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
ForkLifter game;
|
2023-10-27 20:19:11 +00:00
|
|
|
ForkLifterPlayer player;
|
2021-12-21 01:10:49 +00:00
|
|
|
private Animator anim;
|
|
|
|
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
game = ForkLifter.instance;
|
2023-10-27 20:19:11 +00:00
|
|
|
player = ForkLifterPlayer.instance;
|
2021-12-21 01:10:49 +00:00
|
|
|
anim = GetComponent<Animator>();
|
2022-02-05 13:08:33 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
GetComponentInChildren<SpriteRenderer>().sprite = game.peaSprites[type];
|
2021-12-21 01:10:49 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < transform.GetChild(0).childCount; i++)
|
|
|
|
{
|
|
|
|
transform.GetChild(0).GetChild(i).GetComponent<SpriteRenderer>().sprite = transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
|
|
|
|
}
|
2022-01-17 05:00:26 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
game.ScheduleInput(startBeat, 2f, ForkLifter.InputAction_BasicPress, Just, Miss, Out);
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Hit()
|
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
player.Stab(this);
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
if (player.currentPerfectPeasOnFork < 4)
|
2022-01-23 07:01:59 +00:00
|
|
|
{
|
2022-02-28 17:32:08 +00:00
|
|
|
GameObject pea = new GameObject();
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
pea.transform.parent = player.perfect.transform;
|
2022-02-28 17:32:08 +00:00
|
|
|
pea.transform.localScale = Vector2.one;
|
|
|
|
pea.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
|
|
|
|
pea.transform.localPosition = Vector3.zero;
|
|
|
|
|
2023-04-23 20:17:21 +00:00
|
|
|
float peaOffset = 0;
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
if (player.currentPerfectPeasOnFork == 3) peaOffset = -0.15724f;
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
for (int i = 0; i < player.perfect.transform.childCount; i++)
|
2022-02-28 17:32:08 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
player.perfect.transform.GetChild(i).transform.localPosition = new Vector3(0, (-1.67f - (0.15724f * i)) + 0.15724f * player.currentPerfectPeasOnFork + peaOffset);
|
2022-02-28 17:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteRenderer psprite = pea.AddComponent<SpriteRenderer>();
|
2023-10-27 20:19:11 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
psprite.sprite = game.peaHitSprites[type];
|
2023-10-27 20:19:11 +00:00
|
|
|
psprite.sortingOrder = type switch {
|
|
|
|
0 => 101,
|
|
|
|
1 => 104,
|
|
|
|
2 => 103,
|
|
|
|
3 => 102,
|
|
|
|
_ => 20,
|
|
|
|
};
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GameObject hitFXo = new GameObject();
|
|
|
|
hitFXo.transform.localPosition = new Vector3(1.9969f, -3.7026f);
|
|
|
|
hitFXo.transform.localScale = new Vector3(3.142196f, 3.142196f);
|
|
|
|
SpriteRenderer hfxs = hitFXo.AddComponent<SpriteRenderer>();
|
2023-10-27 20:19:11 +00:00
|
|
|
hfxs.sprite = player.hitFX;
|
2022-01-23 07:01:59 +00:00
|
|
|
hfxs.sortingOrder = 100;
|
|
|
|
hfxs.DOColor(new Color(1, 1, 1, 0), 0.05f).OnComplete(delegate { Destroy(hitFXo); });
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.FastEffectHit(type);
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("forkLifter/stab");
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.currentPerfectPeasOnFork++;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.topbun = type == 1;
|
|
|
|
player.middleburger = type == 2;
|
|
|
|
player.bottombun = type == 3;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Early()
|
|
|
|
{
|
2024-01-09 16:55:00 +00:00
|
|
|
player.Stab(null);
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
GameObject pea = new GameObject();
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
pea.transform.parent = player.early.transform;
|
2022-01-23 07:01:59 +00:00
|
|
|
pea.transform.localScale = Vector2.one;
|
|
|
|
|
|
|
|
pea.transform.localPosition = Vector3.zero;
|
|
|
|
pea.transform.localRotation = Quaternion.Euler(0, 0, 90);
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
for (int i = 0; i < player.early.transform.childCount; i++)
|
2022-01-23 07:01:59 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
player.early.transform.GetChild(i).transform.localPosition = new Vector3(0, (-1.67f - (0.15724f * i)) + 0.15724f * player.currentEarlyPeasOnFork);
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteRenderer psprite = pea.AddComponent<SpriteRenderer>();
|
2023-01-15 04:33:37 +00:00
|
|
|
psprite.sprite = game.peaHitSprites[type];
|
2022-01-23 07:01:59 +00:00
|
|
|
psprite.sortingOrder = 20;
|
2023-10-27 20:19:11 +00:00
|
|
|
player.HitFXMiss(new Vector2(1.0424f, -4.032f), new Vector2(1.129612f, 1.129612f));
|
|
|
|
player.HitFXMiss(new Vector2(0.771f, -3.016f), new Vector2(1.71701f, 1.71701f));
|
|
|
|
player.HitFXMiss(new Vector2(2.598f, -2.956f), new Vector2(1.576043f, 1.576043f));
|
|
|
|
player.HitFXMiss(new Vector2(2.551f, -3.609f), new Vector2(1.200788f, 1.200788f));
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.FastEffectHit(type);
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.currentEarlyPeasOnFork++;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Late()
|
|
|
|
{
|
2024-01-09 16:55:00 +00:00
|
|
|
player.Stab(null);
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
GameObject pea = new GameObject();
|
2023-10-27 20:19:11 +00:00
|
|
|
pea.transform.parent = player.late.transform;
|
2022-01-23 07:01:59 +00:00
|
|
|
pea.transform.localScale = Vector2.one;
|
|
|
|
|
|
|
|
pea.transform.localPosition = Vector3.zero;
|
|
|
|
pea.transform.localRotation = Quaternion.Euler(0, 0, 90);
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
for (int i = 0; i < player.late.transform.childCount; i++)
|
2022-01-23 07:01:59 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
player.late.transform.GetChild(i).transform.localPosition = new Vector3(0, (-1.67f - (0.15724f * i)) + 0.15724f * player.currentLatePeasOnFork);
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteRenderer psprite = pea.AddComponent<SpriteRenderer>();
|
2023-01-15 04:33:37 +00:00
|
|
|
psprite.sprite = game.peaHitSprites[type];
|
2022-01-23 07:01:59 +00:00
|
|
|
psprite.sortingOrder = 20;
|
2023-10-27 20:19:11 +00:00
|
|
|
player.HitFXMiss(new Vector2(1.0424f, -4.032f), new Vector2(1.129612f, 1.129612f));
|
|
|
|
player.HitFXMiss(new Vector2(0.771f, -3.016f), new Vector2(1.71701f, 1.71701f));
|
|
|
|
player.HitFXMiss(new Vector2(2.598f, -2.956f), new Vector2(1.576043f, 1.576043f));
|
|
|
|
player.HitFXMiss(new Vector2(2.551f, -3.609f), new Vector2(1.200788f, 1.200788f));
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.FastEffectHit(type);
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
player.currentLatePeasOnFork++;
|
2022-01-23 07:01:59 +00:00
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-03 22:20:26 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, 2.45f);
|
2021-12-24 23:41:35 +00:00
|
|
|
anim.Play("Flicked_Object", -1, normalizedBeatAnim);
|
2021-12-21 01:10:49 +00:00
|
|
|
anim.speed = 0;
|
2023-01-15 04:33:37 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
private void Just(PlayerActionEvent caller, float state)
|
|
|
|
{
|
2024-01-09 16:55:00 +00:00
|
|
|
if (state >= 1f)
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
Late();
|
2024-01-09 16:55:00 +00:00
|
|
|
}
|
|
|
|
else if (state <= -1f)
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
Early();
|
2024-01-09 16:55:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
Hit();
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
|
|
|
|
private void Miss(PlayerActionEvent caller)
|
|
|
|
{
|
2024-01-09 16:55:00 +00:00
|
|
|
SoundByte.PlayOneShotGame("forkLifter/disappointed");
|
2023-09-11 22:28:04 +00:00
|
|
|
BeatAction.New(game, new List<BeatAction.Action>()
|
2023-01-15 04:33:37 +00:00
|
|
|
{
|
|
|
|
new BeatAction.Action(startBeat+ 2.45f, delegate {
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Out(PlayerActionEvent caller) {}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|