Skip to content

Commit

Permalink
Vertical Elements: Add ups/downs and their animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronoAndross committed Oct 26, 2020
1 parent 539398b commit ee51579
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 1 deletion.
1 change: 1 addition & 0 deletions Assets/Scripts/HitResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class HitResult
{
public bool WasHit;
public float Difference; // In milliseconds, + is early and - is late
public bool WasProcessed = false;
}

public enum HitGrade
Expand Down
95 changes: 95 additions & 0 deletions Assets/Scripts/Screens/GameplayScreen/CaretManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using UnityEngine;
public class CaretManager
{
private int upCaretsDegreeRotateTop = 0;
private int upCaretsDegreeRotateMid = 0;
private int upCaretsDegreeRotateBot = 0;
private int upCaretsFrame = 0;
private int downCaretsDegreeRotateTop = 0;
private int downCaretsDegreeRotateMid = 0;
private int downCaretsDegreeRotateBot = 0;
private int downCaretsFrame = 0;
private const int ROTATE_DEG_Y = 6;
private const int ROTATE_DEF_HALF_ROT = 180;

public CaretManager()
{
}

public void Enable(GameObject CanvasObj)
{
CanvasObj.transform.Find("UpCarets").gameObject.SetActive(true);
CanvasObj.transform.Find("DownCarets").gameObject.SetActive(true);
}

public void Disable(GameObject CanvasObj)
{
CanvasObj.transform.Find("UpCarets").gameObject.SetActive(false);
CanvasObj.transform.Find("DownCarets").gameObject.SetActive(false);
}

public void TriggerCarets(StyleStar.Motion currMotion)
{
if (currMotion == StyleStar.Motion.Down)
{
downCaretsDegreeRotateTop += ROTATE_DEF_HALF_ROT;
downCaretsFrame += 60;
}
else if (currMotion == StyleStar.Motion.Up)
{
upCaretsDegreeRotateTop += ROTATE_DEF_HALF_ROT;
upCaretsFrame += 60;
}
}

public void AnimateCarets(GameObject CanvasObj)
{
var downCarets = CanvasObj.transform.Find("DownCarets");
if (downCaretsDegreeRotateTop > 0)
{
downCarets.Find("DownCaret0").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
if (downCaretsFrame % 60 == 45) // 0.25 seconds
downCaretsDegreeRotateMid += ROTATE_DEF_HALF_ROT;
downCaretsDegreeRotateTop -= ROTATE_DEG_Y;

}
if (downCaretsDegreeRotateMid > 0)
{
downCarets.Find("DownCaret1").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
if (downCaretsFrame % 60 == 30) // 0.5 seconds
downCaretsDegreeRotateBot += ROTATE_DEF_HALF_ROT;
downCaretsDegreeRotateMid -= ROTATE_DEG_Y;
}
if (downCaretsDegreeRotateBot > 0)
{
downCarets.Find("DownCaret2").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
downCaretsDegreeRotateBot -= ROTATE_DEG_Y;
}
if (downCaretsFrame >= 1)
downCaretsFrame--;

var upCarets = CanvasObj.transform.Find("UpCarets");
if (upCaretsDegreeRotateTop > 0)
{
upCarets.Find("UpCaret0").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
if (upCaretsFrame % 60 == 45) // 0.25 seconds
upCaretsDegreeRotateMid += ROTATE_DEF_HALF_ROT;
upCaretsDegreeRotateTop -= ROTATE_DEG_Y;

}
if (upCaretsDegreeRotateMid > 0)
{
upCarets.Find("UpCaret1").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
if (upCaretsFrame % 60 == 30) // 0.5 seconds
upCaretsDegreeRotateBot += ROTATE_DEF_HALF_ROT;
upCaretsDegreeRotateMid -= ROTATE_DEG_Y;
}
if (upCaretsDegreeRotateBot > 0)
{
upCarets.Find("UpCaret2").transform.Rotate(new Vector3(0, 1, 0), ROTATE_DEG_Y);
upCaretsDegreeRotateBot -= ROTATE_DEG_Y;
}
if (upCaretsFrame >= 1)
upCaretsFrame--;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Screens/GameplayScreen/CaretManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Assets/Scripts/Screens/GameplayScreen/GameplayDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GameplayDisplay : MonoBehaviour
private RectTransform loadingLeft;
private RectTransform loadingRight;


private CaretManager caretManager = new CaretManager();

private float transitionStartTime = -1;
private bool loadStarted = false;
Expand Down Expand Up @@ -66,6 +66,7 @@ void Start()
GameObject.Find("RightHold").GetComponent<MeshRenderer>().sortingLayerName = "Rightold";
GameObject.Find("LeftSlide").GetComponent<MeshRenderer>().sortingLayerName = "LeftHold";
GameObject.Find("RightSlide").GetComponent<MeshRenderer>().sortingLayerName = "RightHold";
caretManager.Enable(CanvasObj);
}

// Update is called once per frame
Expand Down Expand Up @@ -100,7 +101,14 @@ void Update()
mark.Draw(currentBeat);

foreach (var motion in motions)
{
motion.Draw(currentBeat);
if (motion.HitResult.WasHit && !motion.HitResult.WasProcessed)
{
caretManager.TriggerCarets(motion.Motion);
motion.HitResult.WasProcessed = true;
}
}

foreach (var hold in holds)
hold.Draw(currentBeat);
Expand All @@ -112,6 +120,8 @@ void Update()
// Draw foot markers
TouchCollection.Draw();

caretManager.AnimateCarets(CanvasObj);

// Update UI
CanvasObj.transform.Find("ScrollNumMajor").gameObject.SetText(((int)Math.Floor(GameState.ScrollSpeed)).ToString("D1"));
CanvasObj.transform.Find("ScrollNumMinor").gameObject.SetText("." + ((int)((GameState.ScrollSpeed - Math.Truncate(GameState.ScrollSpeed)) * 10)).ToString("D1"));
Expand Down Expand Up @@ -143,6 +153,7 @@ void Update()
}
break;
case TransitionState.EnteringLoadingScreen:
caretManager.Disable(CanvasObj);
ratio = DrawLoadingScreenTransition(true);
if (ratio <= 0.0f)
{
Expand Down
Binary file added Assets/Textures/DownCaret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions Assets/Textures/DownCaret.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Textures/UpCaret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions Assets/Textures/UpCaret.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee51579

Please sign in to comment.