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.
98 lines
2.3 KiB
98 lines
2.3 KiB
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<SlotSymbol> children = GetChildren()
|
|
.OfType<SlotSymbol>() // Filter to only include Node2D or derived nodes
|
|
.OrderBy(child => child.Position.Y) // Sort by Y value
|
|
.ToList();
|
|
|
|
GD.Print("slot type: " + children[3].SlotType);
|
|
return children[3];
|
|
}
|
|
|
|
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 void ReplaceCurrentOption(SlotSymbol newOption)
|
|
{
|
|
SlotSymbol currentOption = GetActiveSlotSymbol();
|
|
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);
|
|
}
|
|
*/
|
|
}
|
|
}
|