using Godot; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; public partial class Wheel : Sprite2D { public float Speed; bool _spinning = false; public bool Spinning { get => _spinning; set => _spinning = value; } // Called when the node enters the scene tree for the first time. public override void _Ready() { } public SlotSymbol GetActiveSlotSymbol() { List children = GetChildren() .OfType() // Filter to only include Node2D or derived nodes .OrderBy(child => child.Position.Y) // Sort by Y value .ToList(); SlotSymbol symbol = children[4]; GD.Print("slot type: " + symbol.SlotType); return symbol; } public async void Spin(float extraLength) { Spinning = true; Speed = (float)GD.RandRange(1200f, 2000f); await ToSignal(GetTree().CreateTimer(2.0f + extraLength), SceneTreeTimer.SignalName.Timeout); Tween tween = GetTree().CreateTween(); tween.TweenProperty(this, "Speed", 0, 1.0f); } //Export] public Godot.Collections.Array Symbols; [Export] public SlotSymbol[] SlotSymbols; public async void ReplaceCurrentOption(SlotSymbol newOption) { SlotSymbol currentOption = GetActiveSlotSymbol(); currentOption.PeelUp(); await ToSignal(GetTree().CreateTimer(OptionPicker.SLIDE_DELAY + OptionPicker.SLIDE_TIME), SceneTreeTimer.SignalName.Timeout); currentOption.SlotType = newOption.SlotType; currentOption.Texture = newOption.Texture; } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { if (Spinning == false) return; float dt = (float)delta; float minSpeed = 100f; const float SPACING = 109f; float originalMod = this.Position.Y % SPACING; if (Speed <= minSpeed) { Speed = minSpeed; if (originalMod < 2) { Spinning = false; Speed = 0; } } if (Speed <= 0) { Spinning = false; return; } this.Position += new Vector2(0f, Speed * dt); /* //check if we overshot the target if (Speed <= minSpeed && this.Position.Y % SPACING > originalMod) { _spinning = false; Speed = 0f; } */ /* const float Y_WRAPAROUND = 464; if (Position.Y > Y_WRAPAROUND) { Position -= new Vector2(0f, Y_WRAPAROUND); } */ } }