mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 15:57:37 +02:00
Catchy Tune Added (#194)
* catchy tune setup work, animations * more catchy tune progress * catchy tune: gameplay implemented, animation adjustments * more animation work catchy tune * more animation work catchy tune * adjust icon metadata * code cleanup left remarks for minigame developer Co-authored-by: minenice55 <star.elementa@gmail.com>
This commit is contained in:
285
Assets/Scripts/Games/CatchyTune/CatchyTune.cs
Normal file
285
Assets/Scripts/Games/CatchyTune/CatchyTune.cs
Normal file
@ -0,0 +1,285 @@
|
||||
using DG.Tweening;
|
||||
using NaughtyBezierCurves;
|
||||
using HeavenStudio.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Games.Loaders
|
||||
{
|
||||
using static Minigames;
|
||||
public static class CtrCatchLoader
|
||||
{
|
||||
// minigame menu items
|
||||
public static Minigame AddGame(EventCaller eventCaller)
|
||||
{
|
||||
return new Minigame("catchyTune", "Catchy Tune \n<color=#eb5454>[WIP]</color>", "B4E6F6", false, false, new List<GameAction>()
|
||||
{
|
||||
new GameAction("orange", "Orange")
|
||||
{
|
||||
defaultLength = 4f,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("side", CatchyTune.Side.Left, "Side", "The side the orange falls down"),
|
||||
new Param("smile", false, "Smile", "If the characters smile with the heart message after catching")
|
||||
},
|
||||
preFunction = delegate {var e = eventCaller.currentEntity; CatchyTune.PreDropFruit(e.beat, e["side"], e["smile"], false); },
|
||||
},
|
||||
|
||||
new GameAction("pineapple", "Pineapple")
|
||||
{
|
||||
defaultLength = 8f,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("side", CatchyTune.Side.Left, "Side", "The side the pineapple falls down"),
|
||||
new Param("smile", false, "Smile", "If the characters smile with the heart message after catching")
|
||||
},
|
||||
preFunction = delegate {var e = eventCaller.currentEntity; CatchyTune.PreDropFruit(e.beat, e["side"], e["smile"], true); },
|
||||
},
|
||||
|
||||
new GameAction("bop", "Bop")
|
||||
{
|
||||
function = delegate {var e = eventCaller.currentEntity; CatchyTune.instance.Bop(e.beat, e["left"], e["right"]); },
|
||||
defaultLength = 1f,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("left" , true, "Left", "Plalin bops head"),
|
||||
new Param("right", true, "Right", "Alalin bops head")
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace HeavenStudio.Games
|
||||
{
|
||||
using Scripts_CatchyTune;
|
||||
public class CatchyTune : Minigame
|
||||
{
|
||||
|
||||
public enum Side
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Both
|
||||
}
|
||||
|
||||
|
||||
[Header("Animators")]
|
||||
public Animator plalinAnim; // Left d-pad
|
||||
public Animator alalinAnim; // right A button
|
||||
|
||||
[Header("References")]
|
||||
public GameObject orangeBase;
|
||||
public GameObject pineappleBase;
|
||||
public Transform fruitHolder;
|
||||
|
||||
public GameObject heartMessage;
|
||||
|
||||
// when to stop playing the catch animation
|
||||
private float stopCatchLeft = 0f;
|
||||
private float stopCatchRight = 0f;
|
||||
|
||||
private float startSmile = 0f;
|
||||
private float stopSmile = 0f;
|
||||
|
||||
private bool bopLeft = true;
|
||||
private bool bopRight = true;
|
||||
public GameEvent bop = new GameEvent();
|
||||
|
||||
public static CatchyTune instance;
|
||||
static List<QueuedFruit> queuedFruits = new List<QueuedFruit>();
|
||||
struct QueuedFruit
|
||||
{
|
||||
public float beat;
|
||||
public int side;
|
||||
public bool smile;
|
||||
public bool isPineapple;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
const float orangeoffset = 0.5f;
|
||||
const float pineappleoffset = 0.5f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Conductor cond = Conductor.instance;
|
||||
|
||||
if (cond.isPlaying && !cond.isPaused)
|
||||
{
|
||||
if (queuedFruits.Count > 0)
|
||||
{
|
||||
foreach (var fruit in queuedFruits)
|
||||
{
|
||||
DropFruit(fruit.beat, fruit.side, fruit.smile, fruit.isPineapple);
|
||||
}
|
||||
queuedFruits.Clear();
|
||||
}
|
||||
|
||||
// print(stopCatchLeft + " " + stopCatchRight);
|
||||
// print("current beat: " + conductor.songPositionInBeats);
|
||||
if (stopCatchLeft > 0 && stopCatchLeft <= cond.songPositionInBeats)
|
||||
{
|
||||
plalinAnim.SetTrigger("stopCatch");
|
||||
stopCatchLeft = 0;
|
||||
}
|
||||
|
||||
if (stopCatchRight > 0 && stopCatchRight <= cond.songPositionInBeats)
|
||||
{
|
||||
alalinAnim.SetTrigger("stopCatch");
|
||||
stopCatchRight = 0;
|
||||
}
|
||||
|
||||
if (startSmile > 0 && startSmile <= cond.songPositionInBeats)
|
||||
{
|
||||
//print("smile start");
|
||||
plalinAnim.Play("smile", 1, 0);
|
||||
alalinAnim.Play("smile", 1, 0);
|
||||
startSmile = 0;
|
||||
heartMessage.SetActive(true);
|
||||
}
|
||||
|
||||
if (stopSmile > 0 && stopSmile <= cond.songPositionInBeats)
|
||||
{
|
||||
//print("smile stop");
|
||||
plalinAnim.SetTrigger("stopSmile");
|
||||
alalinAnim.SetTrigger("stopSmile");
|
||||
stopSmile = 0;
|
||||
heartMessage.SetActive(false);
|
||||
}
|
||||
|
||||
if (cond.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1))
|
||||
{
|
||||
if (bopLeft && stopCatchLeft == 0)
|
||||
{
|
||||
plalinAnim.Play("bop", 0, 0);
|
||||
}
|
||||
|
||||
if (bopRight && stopCatchRight == 0)
|
||||
{
|
||||
alalinAnim.Play("bop", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsExpectingInputNow())
|
||||
{
|
||||
if (PlayerInput.GetAnyDirectionDown())
|
||||
{
|
||||
catchWhiff(false);
|
||||
}
|
||||
if (PlayerInput.Pressed())
|
||||
{
|
||||
catchWhiff(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DropFruit(float beat, int side, bool smile, bool isPineapple)
|
||||
{
|
||||
var objectToSpawn = isPineapple ? pineappleBase : orangeBase;
|
||||
|
||||
if (side == (int)Side.Left || side == (int)Side.Both)
|
||||
{
|
||||
DropFruitSingle(beat, false, smile, objectToSpawn);
|
||||
}
|
||||
|
||||
if (side == (int)Side.Right || side == (int)Side.Both)
|
||||
{
|
||||
DropFruitSingle(beat, true, smile, objectToSpawn);
|
||||
}
|
||||
}
|
||||
|
||||
//minenice: experiment to test preFunction
|
||||
public static void PreDropFruit(float beat, int side, bool smile, bool isPineapple)
|
||||
{
|
||||
float spawnBeat = beat - 1f;
|
||||
beat = beat - (isPineapple ? 2f : 1f);
|
||||
if (GameManager.instance.currentGame == "catchyTune")
|
||||
{
|
||||
BeatAction.New(instance.gameObject, new List<BeatAction.Action>()
|
||||
{
|
||||
new BeatAction.Action(spawnBeat, delegate { if (instance != null) instance.DropFruit(beat, side, smile, isPineapple); }),
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
queuedFruits.Add(new QueuedFruit()
|
||||
{
|
||||
beat = beat,
|
||||
side = side,
|
||||
smile = smile,
|
||||
isPineapple = isPineapple
|
||||
});
|
||||
}
|
||||
|
||||
if (side == (int)Side.Left || side == (int)Side.Both)
|
||||
{
|
||||
Fruit.PlaySound(beat, false, isPineapple);
|
||||
}
|
||||
if (side == (int)Side.Right || side == (int)Side.Both)
|
||||
{
|
||||
Fruit.PlaySound(beat, true, isPineapple);
|
||||
}
|
||||
}
|
||||
|
||||
public void DropFruitSingle(float beat, bool side, bool smile, GameObject objectToSpawn)
|
||||
{
|
||||
|
||||
var newFruit = GameObject.Instantiate(objectToSpawn, fruitHolder);
|
||||
var fruitComp = newFruit.GetComponent<Fruit>();
|
||||
fruitComp.startBeat = beat;
|
||||
fruitComp.side = side;
|
||||
fruitComp.smile = smile;
|
||||
newFruit.SetActive(true);
|
||||
}
|
||||
|
||||
public void Bop(float beat, bool left, bool right)
|
||||
{
|
||||
bopLeft = left;
|
||||
bopRight = right;
|
||||
}
|
||||
|
||||
public void catchSuccess(bool side, bool isPineapple, bool smile, float beat)
|
||||
{
|
||||
string anim = isPineapple ? "catchPineapple" : "catchOrange";
|
||||
|
||||
if (side)
|
||||
{
|
||||
alalinAnim.Play(anim, 0, 0);
|
||||
stopCatchRight = beat + 0.9f;
|
||||
}
|
||||
else
|
||||
{
|
||||
plalinAnim.Play(anim, 0, 0);
|
||||
stopCatchLeft = beat + 0.9f;
|
||||
}
|
||||
|
||||
if (smile)
|
||||
{
|
||||
startSmile = beat + 1f;
|
||||
stopSmile = beat + 2f;
|
||||
}
|
||||
}
|
||||
|
||||
public void catchMiss(bool side, bool isPineapple)
|
||||
{
|
||||
// not the right sound at all but need an accurate rip
|
||||
Jukebox.PlayOneShotGame("catchyTune/fruitThrough");
|
||||
|
||||
// hurt animation here
|
||||
}
|
||||
|
||||
public void catchWhiff(bool side)
|
||||
{
|
||||
Jukebox.PlayOneShotGame("catchyTune/whiff");
|
||||
|
||||
// whiff animation here
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/CatchyTune/CatchyTune.cs.meta
Normal file
11
Assets/Scripts/Games/CatchyTune/CatchyTune.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54ed8f81614b9564b99577f03cb58602
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
154
Assets/Scripts/Games/CatchyTune/Fruit.cs
Normal file
154
Assets/Scripts/Games/CatchyTune/Fruit.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using NaughtyBezierCurves;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
|
||||
namespace HeavenStudio.Games.Scripts_CatchyTune
|
||||
{
|
||||
public class Fruit : PlayerActionObject
|
||||
{
|
||||
|
||||
public bool isPineapple;
|
||||
public float startBeat;
|
||||
|
||||
public Animator anim;
|
||||
|
||||
public bool side;
|
||||
|
||||
public bool smile;
|
||||
|
||||
private string soundText;
|
||||
|
||||
private Minigame.Eligible e = new Minigame.Eligible();
|
||||
|
||||
private CatchyTune game;
|
||||
|
||||
private float beatLength = 4f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
game = CatchyTune.instance;
|
||||
|
||||
e.gameObject = this.gameObject;
|
||||
|
||||
var cond = Conductor.instance;
|
||||
var tempo = cond.songBpm;
|
||||
var playbackSpeed = cond.musicSource.pitch;
|
||||
|
||||
if (isPineapple) beatLength = 8f;
|
||||
|
||||
if (side)
|
||||
{
|
||||
transform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
|
||||
anim.DoScaledAnimation("fruit bounce", startBeat, beatLength + (isPineapple ? 1f : 0.5f));
|
||||
|
||||
soundText = "catchyTune/";
|
||||
|
||||
if (side)
|
||||
{
|
||||
soundText += "right";
|
||||
}
|
||||
else
|
||||
{
|
||||
soundText += "left";
|
||||
}
|
||||
|
||||
if (isPineapple)
|
||||
{
|
||||
soundText += "Pineapple";
|
||||
}
|
||||
else
|
||||
{
|
||||
soundText += "Orange";
|
||||
}
|
||||
|
||||
game.ScheduleInput(startBeat, beatLength, side ? InputType.STANDARD_DOWN : InputType.DIRECTION_DOWN,
|
||||
CatchFruit, Miss, WayOff);
|
||||
}
|
||||
|
||||
// minenice: note - needs PlayerActionEvent implementation
|
||||
private void Update()
|
||||
{
|
||||
Conductor cond = Conductor.instance;
|
||||
float tempo = cond.songBpm;
|
||||
float playbackSpeed = cond.musicSource.pitch;
|
||||
|
||||
anim.DoScaledAnimation("fruit bounce", startBeat, beatLength + (isPineapple ? 1f : 0.5f));
|
||||
|
||||
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, beatLength);
|
||||
}
|
||||
|
||||
public static void PlaySound(float startBeat, bool side, bool isPineapple)
|
||||
{
|
||||
string soundText = "catchyTune/";
|
||||
|
||||
if (side)
|
||||
{
|
||||
soundText += "right";
|
||||
}
|
||||
else
|
||||
{
|
||||
soundText += "left";
|
||||
}
|
||||
|
||||
if (isPineapple)
|
||||
{
|
||||
soundText += "Pineapple";
|
||||
}
|
||||
else
|
||||
{
|
||||
soundText += "Orange";
|
||||
}
|
||||
|
||||
|
||||
MultiSound.Sound[] sound;
|
||||
|
||||
|
||||
if (isPineapple)
|
||||
{
|
||||
sound = new MultiSound.Sound[]
|
||||
{
|
||||
new MultiSound.Sound(soundText, startBeat + 2f),
|
||||
new MultiSound.Sound(soundText, startBeat + 4f),
|
||||
new MultiSound.Sound(soundText, startBeat + 6f)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = new MultiSound.Sound[]
|
||||
{
|
||||
new MultiSound.Sound(soundText, startBeat + 1f),
|
||||
new MultiSound.Sound(soundText, startBeat + 2f),
|
||||
new MultiSound.Sound(soundText, startBeat + 3f)
|
||||
};
|
||||
}
|
||||
|
||||
MultiSound.Play(sound, forcePlay: true);
|
||||
}
|
||||
|
||||
private void CatchFruit(PlayerActionEvent caller, float state)
|
||||
{
|
||||
//minenice: TODO - near misses (-1 > state > 1)
|
||||
Jukebox.PlayOneShotGame(soundText + "Catch");
|
||||
game.catchSuccess(side, isPineapple, smile, startBeat + beatLength);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
private void Miss(PlayerActionEvent caller)
|
||||
{
|
||||
game.catchMiss(side, isPineapple);
|
||||
|
||||
BeatAction.New(gameObject, new List<BeatAction.Action>()
|
||||
{
|
||||
new BeatAction.Action(startBeat + beatLength + (isPineapple ? 1f : 0.5f), delegate { Destroy(this.gameObject); }),
|
||||
});
|
||||
}
|
||||
|
||||
private void WayOff(PlayerActionEvent caller) {} // whiffing is handled in the main loop
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/CatchyTune/Fruit.cs.meta
Normal file
11
Assets/Scripts/Games/CatchyTune/Fruit.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b9d796f35f4e624089f267d51df9223
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user