using System.Collections; using System.Collections.Generic; using System.ComponentModel; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/Puzzles/MemGameCards.cs")] public partial class MemGameCards : Area2D, Interacteable { private MemoryGame parent; public Sprite2D sprite; public bool flipped; public int id = 1; public override void _Ready() { sprite = GetParent(); parent = sprite.GetParent(); } public void Reset() { flipped = false; Coroutine.Start(FlipAnim(0)); } public void Interact() { if (parent.running && !flipped) { Main.inEvent = Coroutine.Start(FlipCard()); } Player.instance.canInput = true; } private IEnumerator FlipCard() { Party.StopMoving(); Coroutine c = Coroutine.Start(FlipAnim(id)); while (!c.done) { yield return null; } if (parent.last != null) { if (!parent.flipped.Contains(id)) { Audio.PlaySound("snd_error.wav"); for (float a = 0f; a < 30f; a += Main.deltaTime) { yield return null; } parent.lives--; parent.last.Reset(); parent.flipped.RemoveAt(parent.flipped.Count - 1); for (float a = 0f; a < 30f; a += Main.deltaTime) { yield return null; } c = Coroutine.Start(FlipAnim(0)); while (!c.done) { yield return null; } } else { Audio.PlaySound("snd_shineselect.wav"); parent.flipped.Add(id); flipped = true; } parent.last = null; if (parent.flipped.Count == 18 || parent.lives == 0) { for (float a = 0f; a < 30f; a += Main.deltaTime) { yield return null; } Main.inEvent = Coroutine.Start(parent.EndGame(parent.flipped.Count == 18)); } } else { parent.flipped.Add(id); flipped = true; parent.last = this; } } public IEnumerator FlipAnim(int changeTo, bool noSound = false) { if (!noSound) { Audio.PlaySound("snd_wing_ch1.wav", 1.1f); } float a = 0f; float b; for (b = 10f; a < b; a += Main.deltaTime) { sprite.Scale = new Vector2(Mathf.Lerp(1f, 0f, a / b), 1f); yield return null; } sprite.Frame = changeTo; b = 0f; for (a = 10f; b < a; b += Main.deltaTime) { sprite.Scale = new Vector2(Mathf.Lerp(0f, 1f, b / a), 1f); yield return null; } sprite.Scale = Vector2.One; } }