You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.5 KiB

using Godot;
using System;
using System.Collections.Generic;
2 days ago
using System.Linq;
using System.Threading.Tasks;
public partial class Wheel : Sprite2D
{
public float Speed;
bool _spinning = false;
2 days ago
public bool Spinning { get => _spinning; set => _spinning = value; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
2 days ago
public SlotSymbol GetActiveSlotSymbol()
{
List<SlotSymbol> children = GetChildren()
.OfType<SlotSymbol>() // 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;
2 days ago
}
public async void Spin(float extraLength)
{
2 days ago
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)
2 days ago
{
SlotSymbol currentOption = GetActiveSlotSymbol();
currentOption.PeelUp();
await ToSignal(GetTree().CreateTimer(OptionPicker.SLIDE_DELAY + OptionPicker.SLIDE_TIME), SceneTreeTimer.SignalName.Timeout);
2 days ago
currentOption.SlotType = newOption.SlotType;
currentOption.Texture = newOption.Texture;
2 days ago
}
2 days ago
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
2 days ago
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)
{
2 days ago
Spinning = false;
Speed = 0;
}
}
if (Speed <= 0)
2 days ago
{
Spinning = false;
return;
2 days ago
}
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);
}
*/
}
}