2022-03-07 03:17:46 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_DrummingPractice
|
2022-03-07 03:17:46 +00:00
|
|
|
{
|
|
|
|
public class Drummer : MonoBehaviour
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
DrummingPractice game;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
|
|
|
[Header("References")]
|
|
|
|
public Animator animator;
|
|
|
|
public List<MiiFace> miiFaces;
|
|
|
|
public SpriteRenderer face;
|
|
|
|
|
|
|
|
public bool player = false;
|
2022-03-07 05:00:54 +00:00
|
|
|
|
2022-03-07 03:17:46 +00:00
|
|
|
public int mii = 0;
|
2022-03-07 05:00:54 +00:00
|
|
|
public int count = 0;
|
|
|
|
|
|
|
|
private bool hitting = false;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
private double canBopBeat = -2f;
|
2023-03-07 17:22:32 +00:00
|
|
|
|
2022-03-11 18:20:24 +00:00
|
|
|
// in the future: use the MiiStudio API to render any mii from a nintendo account / MNMS / Mii Studio code?
|
|
|
|
// figure out how to call the API from unity?
|
|
|
|
// used expressions: "normal", "smile", "sorrow"
|
2022-03-07 03:17:46 +00:00
|
|
|
[System.Serializable]
|
|
|
|
public class MiiFace
|
|
|
|
{
|
|
|
|
public List<Sprite> Sprites;
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
game = DrummingPractice.instance;
|
|
|
|
}
|
|
|
|
|
2022-03-07 05:00:54 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
if (player && PlayerInput.GetIsAction(DrummingPractice.InputAction_BasicPress) && !DrummingPractice.instance.IsExpectingInputNow(DrummingPractice.InputAction_BasicPress))
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
2022-03-07 17:10:50 +00:00
|
|
|
Hit(false, false);
|
2022-03-07 05:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFace(int type)
|
|
|
|
{
|
|
|
|
face.sprite = miiFaces[mii].Sprites[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bop()
|
|
|
|
{
|
2023-03-07 17:22:32 +00:00
|
|
|
if (Conductor.instance.GetPositionFromBeat(canBopBeat, 2f) > 1f)
|
2022-03-07 05:00:54 +00:00
|
|
|
animator.Play("Bop", 0, 0);
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void Prepare(double beat, int type)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
2023-03-07 17:22:32 +00:00
|
|
|
canBopBeat = beat;
|
2022-03-07 05:00:54 +00:00
|
|
|
count = type;
|
|
|
|
if (count % 2 == 0)
|
|
|
|
animator.Play("PrepareLeft", 0, 0);
|
|
|
|
else
|
|
|
|
animator.Play("PrepareRight", 0, 0);
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:10:50 +00:00
|
|
|
public void Hit(bool hit, bool applause, bool force = false)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
2022-03-07 17:10:50 +00:00
|
|
|
if(player && force)
|
|
|
|
{
|
|
|
|
if (hit)
|
2022-03-15 23:15:54 +00:00
|
|
|
{
|
2022-03-07 17:10:50 +00:00
|
|
|
HitSound(applause);
|
2022-03-15 23:15:54 +00:00
|
|
|
DrummingPractice.instance.Streak();
|
|
|
|
} else
|
2022-03-07 17:10:50 +00:00
|
|
|
MissSound();
|
|
|
|
}
|
|
|
|
|
2022-03-07 05:00:54 +00:00
|
|
|
if (!hitting)
|
|
|
|
{
|
|
|
|
if (count % 2 == 0)
|
2023-02-14 16:31:51 +00:00
|
|
|
animator.DoScaledAnimationAsync("HitLeft", 0.6f);
|
2022-03-07 05:00:54 +00:00
|
|
|
else
|
2023-02-14 16:31:51 +00:00
|
|
|
animator.DoScaledAnimationAsync("HitRight", 0.6f);
|
2022-03-07 05:00:54 +00:00
|
|
|
count++;
|
|
|
|
|
2022-03-07 17:10:50 +00:00
|
|
|
if (player && !force)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
|
|
|
if (hit)
|
2022-03-07 17:10:50 +00:00
|
|
|
HitSound(applause);
|
2022-03-07 05:00:54 +00:00
|
|
|
else
|
2022-03-07 17:10:50 +00:00
|
|
|
MissSound();
|
2022-03-07 05:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hitting = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:10:50 +00:00
|
|
|
private void HitSound(bool applause)
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("drummingPractice/hit");
|
|
|
|
if (applause) SoundByte.PlayOneShot("applause");
|
2022-03-07 17:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void MissSound()
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("drummingPractice/miss");
|
2022-03-07 17:10:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 05:00:54 +00:00
|
|
|
public void EndHit()
|
|
|
|
{
|
|
|
|
hitting = false;
|
|
|
|
}
|
2022-03-07 03:17:46 +00:00
|
|
|
}
|
|
|
|
}
|