2022-02-15 23:28:08 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
using DG.Tweening;
|
2022-02-16 17:04:28 +00:00
|
|
|
using System;
|
2022-02-15 23:28:08 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-04-12 16:14:46 +00:00
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class NtrFlickLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
|
|
|
return new Minigame("builtToScaleDS", "Built To Scale (DS)", "00BB00", true, false, new List<GameAction>()
|
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("spawn blocks", "Spawn Blocks")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("play piano", "Play Note")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { BuiltToScaleDS.instance.PlayPiano(eventCaller.currentEntity.beat, eventCaller.currentEntity.length, eventCaller.currentEntity["type"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", new EntityTypes.Integer(-24, 24, 0), "Semitones", "The number of semitones up or down this note should be pitched")
|
|
|
|
}
|
|
|
|
},
|
2022-04-12 16:14:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-02-15 23:28:08 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_BuiltToScaleDS;
|
|
|
|
|
2022-02-15 23:28:08 +00:00
|
|
|
public class BuiltToScaleDS : Minigame
|
|
|
|
{
|
2022-02-16 17:04:28 +00:00
|
|
|
public enum BTSObject { HitPieces, MissPieces, FlyingRod }
|
|
|
|
|
2022-02-15 23:28:08 +00:00
|
|
|
[Header("Camera")]
|
|
|
|
public Transform renderQuadTrans;
|
2022-02-24 12:26:56 +00:00
|
|
|
public Transform camPivot;
|
2022-03-10 12:45:21 +00:00
|
|
|
public Camera camComp;
|
2022-02-15 23:28:08 +00:00
|
|
|
|
|
|
|
[Header("References")]
|
|
|
|
public SkinnedMeshRenderer environmentRenderer;
|
2022-02-16 17:04:28 +00:00
|
|
|
public GameObject flyingRodBase;
|
|
|
|
public GameObject movingBlocksBase;
|
|
|
|
public GameObject hitPartsBase;
|
|
|
|
public GameObject missPartsBase;
|
|
|
|
public Transform partsHolder;
|
|
|
|
public Transform blocksHolder;
|
|
|
|
public Animator shooterAnim;
|
|
|
|
public Animator elevatorAnim;
|
2022-02-15 23:28:08 +00:00
|
|
|
|
|
|
|
[Header("Properties")]
|
|
|
|
public float beltSpeed = 1f;
|
|
|
|
|
|
|
|
private Material beltMaterial;
|
|
|
|
private Material[] environmentMaterials;
|
|
|
|
private float currentBeltOffset;
|
2022-02-16 17:04:28 +00:00
|
|
|
|
|
|
|
[NonSerialized] public bool shootingThisFrame;
|
2022-02-15 23:28:08 +00:00
|
|
|
|
|
|
|
public static BuiltToScaleDS instance;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
environmentMaterials = environmentRenderer.materials;
|
|
|
|
beltMaterial = Instantiate(environmentMaterials[8]);
|
|
|
|
environmentMaterials[8] = beltMaterial;
|
|
|
|
renderQuadTrans.gameObject.SetActive(true);
|
2022-03-26 02:08:46 +00:00
|
|
|
|
2022-02-15 23:28:08 +00:00
|
|
|
var cam = GameCamera.instance.camera;
|
|
|
|
var camHeight = 2f * cam.orthographicSize;
|
|
|
|
var camWidth = camHeight * cam.aspect;
|
|
|
|
renderQuadTrans.localScale = new Vector3(camWidth, camHeight, 1f);
|
2022-02-16 17:04:28 +00:00
|
|
|
|
2022-03-10 12:45:21 +00:00
|
|
|
camComp.depthTextureMode = camComp.depthTextureMode | DepthTextureMode.Depth;
|
|
|
|
|
2022-02-16 17:04:28 +00:00
|
|
|
elevatorAnim.Play("MakeRod", 0, 1f);
|
2022-02-15 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 23:46:45 +00:00
|
|
|
List<DynamicBeatmap.DynamicEntity> spawnedBlockEvents = new List<DynamicBeatmap.DynamicEntity>();
|
2022-02-15 23:28:08 +00:00
|
|
|
void Update()
|
|
|
|
{
|
2022-02-16 17:04:28 +00:00
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var currentBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
|
|
|
var blockEvents = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel == "builtToScaleDS/spawn blocks");
|
|
|
|
for (int i = 0; i < blockEvents.Count; i++)
|
|
|
|
{
|
|
|
|
var ev = blockEvents[i];
|
|
|
|
if (spawnedBlockEvents.Contains(ev)) continue; // Don't spawn the same blocks multiple times.
|
|
|
|
|
2022-02-18 14:32:38 +00:00
|
|
|
var spawnBeat = ev.beat - ev.length;
|
2022-02-16 17:04:28 +00:00
|
|
|
if (currentBeat > spawnBeat && currentBeat < ev.beat + ev.length)
|
|
|
|
{
|
|
|
|
SpawnBlocks(spawnBeat, ev.length);
|
|
|
|
spawnedBlockEvents.Add(ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 23:28:08 +00:00
|
|
|
currentBeltOffset = (currentBeltOffset + Time.deltaTime * -beltSpeed) % 1f;
|
|
|
|
beltMaterial.mainTextureOffset = new Vector2(0f, currentBeltOffset);
|
|
|
|
environmentRenderer.materials = environmentMaterials;
|
|
|
|
}
|
2022-02-16 17:04:28 +00:00
|
|
|
|
|
|
|
void LateUpdate()
|
|
|
|
{
|
|
|
|
var shooterState = shooterAnim.GetCurrentAnimatorStateInfo(0);
|
|
|
|
bool canShoot = !shooterState.IsName("Shoot") || shooterAnim.IsAnimationNotPlaying();
|
|
|
|
|
|
|
|
if (canShoot && PlayerInput.Pressed() && !shootingThisFrame)
|
|
|
|
{
|
|
|
|
shootingThisFrame = true;
|
|
|
|
Shoot();
|
|
|
|
SpawnObject(BTSObject.FlyingRod);
|
2022-02-17 02:19:40 +00:00
|
|
|
Jukebox.PlayOneShotGame("builtToScaleDS/Boing");
|
2022-02-16 17:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!shootingThisFrame)
|
|
|
|
{
|
|
|
|
if (blocksHolder.childCount == 0 && shooterState.IsName("Windup") && shooterAnim.IsAnimationNotPlaying())
|
|
|
|
{
|
|
|
|
shooterAnim.Play("WindDown", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shootingThisFrame = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SpawnBlocks(float beat, float length)
|
|
|
|
{
|
|
|
|
var newBlocks = GameObject.Instantiate(movingBlocksBase, blocksHolder).GetComponent<Blocks>();
|
|
|
|
newBlocks.createBeat = beat;
|
|
|
|
newBlocks.createLength = length;
|
|
|
|
newBlocks.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
SetBlockTime(newBlocks, beat, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int blockFramesPerSecond = 24;
|
|
|
|
const int blockHitFrame = 39;
|
|
|
|
const int blockTotalFrames = 80;
|
2022-02-18 14:32:38 +00:00
|
|
|
const int spawnFrameOffset = -3;
|
2022-02-16 17:04:28 +00:00
|
|
|
List<int> criticalFrames = new List<int> { 7, 15, 23, 31, 39, 47 };
|
|
|
|
public void SetBlockTime(Blocks blocks, float spawnBeat, float length)
|
|
|
|
{
|
2022-02-18 14:32:38 +00:00
|
|
|
float spawnTimeOffset = (float)spawnFrameOffset / (float)blockFramesPerSecond;
|
|
|
|
|
2022-02-16 17:04:28 +00:00
|
|
|
float secondsPerFrame = 1f / blockFramesPerSecond;
|
|
|
|
float secondsToHitFrame = secondsPerFrame * blockHitFrame;
|
|
|
|
|
|
|
|
float secondsPerBeat = Conductor.instance.secPerBeat;
|
2022-02-18 14:32:38 +00:00
|
|
|
float secondsToHitBeat = secondsPerBeat * 5f * length + spawnTimeOffset;
|
2022-02-16 17:04:28 +00:00
|
|
|
|
|
|
|
float speedMult = secondsToHitFrame / secondsToHitBeat;
|
|
|
|
|
2022-02-18 14:32:38 +00:00
|
|
|
float secondsPastSpawnTime = secondsPerBeat * (Conductor.instance.songPositionInBeats - spawnBeat) + spawnTimeOffset;
|
2022-02-16 17:04:28 +00:00
|
|
|
float framesPastSpawnTime = blockFramesPerSecond * speedMult * secondsPastSpawnTime;
|
|
|
|
|
|
|
|
// The only way I could deal with Unity's interpolation shenanigans without having a stroke.
|
|
|
|
if (criticalFrames.Contains(Mathf.FloorToInt(framesPastSpawnTime)))
|
|
|
|
framesPastSpawnTime = Mathf.CeilToInt(framesPastSpawnTime);
|
|
|
|
|
|
|
|
blocks.anim.Play("Move", 0, framesPastSpawnTime / blockTotalFrames);
|
|
|
|
blocks.anim.speed = speedMult;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SpawnObject(BTSObject btsObject)
|
|
|
|
{
|
|
|
|
GameObject prefabToUse = null;
|
|
|
|
string animNameToUse = "";
|
|
|
|
|
|
|
|
switch (btsObject)
|
|
|
|
{
|
|
|
|
case BTSObject.HitPieces:
|
|
|
|
prefabToUse = hitPartsBase;
|
|
|
|
animNameToUse = "PartsHit";
|
|
|
|
break;
|
|
|
|
case BTSObject.MissPieces:
|
|
|
|
prefabToUse = missPartsBase;
|
|
|
|
animNameToUse = "PartsMiss";
|
|
|
|
break;
|
|
|
|
case BTSObject.FlyingRod:
|
|
|
|
prefabToUse = flyingRodBase;
|
|
|
|
animNameToUse = "Fly";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefabToUse != null)
|
|
|
|
{
|
|
|
|
var newPiece = GameObject.Instantiate(prefabToUse, partsHolder).GetComponent<BTSPiece>();
|
|
|
|
newPiece.gameObject.SetActive(true);
|
|
|
|
newPiece.anim.Play(animNameToUse, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Shoot()
|
|
|
|
{
|
|
|
|
shooterAnim.Play("Shoot", 0, 0);
|
|
|
|
elevatorAnim.Play("MakeRod", 0, 0);
|
|
|
|
}
|
2022-03-07 09:16:31 +00:00
|
|
|
|
|
|
|
public void PlayPiano(float beat, float length, int semiTones)
|
|
|
|
{
|
2022-03-07 12:54:36 +00:00
|
|
|
var pianoPitch = Mathf.Pow(2f, (1f / 12f) * semiTones) *Conductor.instance.musicSource.pitch;
|
2022-03-07 09:34:38 +00:00
|
|
|
var pianoSource = Jukebox.PlayOneShotGame("builtToScaleDS/Piano", -1, pianoPitch, 0.8f, true);
|
2022-03-07 09:16:31 +00:00
|
|
|
|
2022-03-10 03:59:48 +00:00
|
|
|
pianoSource.SetLoopParams(beat + length, 0.1f);
|
2022-03-07 09:16:31 +00:00
|
|
|
}
|
2022-02-15 23:28:08 +00:00
|
|
|
}
|
|
|
|
}
|