summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/CardSlideGame.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/CardSlideGame.cs')
-rw-r--r--Client/Assembly-CSharp/CardSlideGame.cs190
1 files changed, 190 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/CardSlideGame.cs b/Client/Assembly-CSharp/CardSlideGame.cs
new file mode 100644
index 0000000..3c423a5
--- /dev/null
+++ b/Client/Assembly-CSharp/CardSlideGame.cs
@@ -0,0 +1,190 @@
+using System;
+using System.Collections;
+using UnityEngine;
+
+public class CardSlideGame : Minigame
+{
+ private Color gray = new Color(0.45f, 0.45f, 0.45f);
+
+ private Color green = new Color(0f, 0.8f, 0f);
+
+ private CardSlideGame.TaskStages State;
+
+ private Controller myController = new Controller();
+
+ private FloatRange XRange = new FloatRange(-2.38f, 2.38f);
+
+ public FloatRange AcceptedTime = new FloatRange(0.4f, 0.6f);
+
+ public Collider2D col;
+
+ public SpriteRenderer redLight;
+
+ public SpriteRenderer greenLight;
+
+ public TextRenderer StatusText;
+
+ public AudioClip AcceptSound;
+
+ public AudioClip[] CardMove;
+
+ public AudioClip WalletOut;
+
+ public float dragTime;
+
+ private bool moving;
+
+ private enum TaskStages
+ {
+ Before,
+ Animating,
+ Inserted,
+ After
+ }
+
+ public void Update()
+ {
+ if (this.MyNormTask.IsComplete)
+ {
+ return;
+ }
+ this.myController.Update();
+ Vector3 localPosition = this.col.transform.localPosition;
+ switch (this.myController.CheckDrag(this.col, false))
+ {
+ case DragState.NoTouch:
+ if (this.State == CardSlideGame.TaskStages.Inserted)
+ {
+ localPosition.x = Mathf.Lerp(localPosition.x, this.XRange.min, Time.deltaTime * 4f);
+ }
+ break;
+ case DragState.TouchStart:
+ this.dragTime = 0f;
+ break;
+ case DragState.Dragging:
+ if (this.State == CardSlideGame.TaskStages.Inserted)
+ {
+ Vector2 vector = this.myController.DragPosition - base.transform.position;
+ vector.x = this.XRange.Clamp(vector.x);
+ if (vector.x - localPosition.x > 0.01f)
+ {
+ this.dragTime += Time.deltaTime;
+ this.redLight.color = this.gray;
+ this.greenLight.color = this.gray;
+ if (!this.moving)
+ {
+ this.moving = true;
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.CardMove.Random<AudioClip>(), false, 1f);
+ }
+ }
+ }
+ localPosition.x = vector.x;
+ }
+ break;
+ case DragState.Released:
+ this.moving = false;
+ if (this.State == CardSlideGame.TaskStages.Before)
+ {
+ this.State = CardSlideGame.TaskStages.Animating;
+ base.StartCoroutine(this.InsertCard());
+ }
+ else if (this.State == CardSlideGame.TaskStages.Inserted)
+ {
+ if (this.XRange.max - localPosition.x < 0.05f)
+ {
+ if (this.AcceptedTime.Contains(this.dragTime))
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.AcceptSound, false, 1f);
+ }
+ this.State = CardSlideGame.TaskStages.After;
+ this.StatusText.Text = "Accepted. Thank you.";
+ base.StartCoroutine(this.PutCardBack());
+ if (this.MyNormTask)
+ {
+ this.MyNormTask.NextStep();
+ }
+ this.redLight.color = this.gray;
+ this.greenLight.color = this.green;
+ }
+ else
+ {
+ if (this.AcceptedTime.max < this.dragTime)
+ {
+ this.StatusText.Text = "Too slow. Try again";
+ }
+ else
+ {
+ this.StatusText.Text = "Too fast. Try again.";
+ }
+ this.redLight.color = Color.red;
+ this.greenLight.color = this.gray;
+ }
+ }
+ else
+ {
+ this.StatusText.Text = "Bad read. Try again.";
+ this.redLight.color = Color.red;
+ this.greenLight.color = this.gray;
+ }
+ }
+ break;
+ }
+ this.col.transform.localPosition = localPosition;
+ }
+
+ private IEnumerator PutCardBack()
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.WalletOut, false, 1f);
+ }
+ Vector3 pos = this.col.transform.localPosition;
+ Vector3 targ = new Vector3(-1.11f, -1.9f, pos.z);
+ float time = 0f;
+ for (;;)
+ {
+ float t = Mathf.Min(1f, time / 0.6f);
+ this.col.transform.localPosition = Vector3.Lerp(pos, targ, t);
+ this.col.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.75f, t);
+ if (time > 0.6f)
+ {
+ break;
+ }
+ yield return null;
+ time += Time.deltaTime;
+ }
+ base.StartCoroutine(base.CoStartClose(0.75f));
+ yield break;
+ }
+
+ private IEnumerator InsertCard()
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.WalletOut, false, 1f);
+ }
+ Vector3 pos = this.col.transform.localPosition;
+ Vector3 targ = new Vector3(this.XRange.min, 0.75f, pos.z);
+ float time = 0f;
+ for (;;)
+ {
+ float t = Mathf.Min(1f, time / 0.6f);
+ this.col.transform.localPosition = Vector3.Lerp(pos, targ, t);
+ this.col.transform.localScale = Vector3.Lerp(Vector3.one * 0.75f, Vector3.one, t);
+ if (time > 0.6f)
+ {
+ break;
+ }
+ yield return null;
+ time += Time.deltaTime;
+ }
+ this.StatusText.Text = "Please swipe card";
+ this.greenLight.color = this.green;
+ this.State = CardSlideGame.TaskStages.Inserted;
+ yield break;
+ }
+}