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.

78 lines
1.8 KiB

using Godot;
using System;
public partial class SlotSymbol : Sprite2D
{
public enum Type
{
BANANA,
BELL,
BAR,
SEVEN,
CHERRY,
2 days ago
X2,
SPIN
}
[Export] public Type SlotType;
public override void _Ready()
{
}
public void PeelUp()
{
var tween = CreateTween();
tween.SetParallel(false);
tween.TweenProperty(this, "position", Position - new Vector2(0, 309), OptionPicker.SLIDE_DELAY + OptionPicker.SLIDE_TIME);
tween.TweenProperty(this, "position", Position, 0f);
//tween.TweenCallback(Callable.From(() => GD.Print("")));
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
const float WRAPAROUND_DISTANCE = 109 * 6;
if (GlobalPosition.Y < 320 - 184)
{
Position = new Vector2(Position.X, Position.Y + WRAPAROUND_DISTANCE);
}
if (GlobalPosition.Y > 320 + 218)
{
Position = new Vector2(Position.X, Position.Y - WRAPAROUND_DISTANCE);
}
}
2 days ago
public void SetToRandom()
{
SlotType = GetRandomEnumValue<Type>();
Texture2D texture = (Texture2D)ResourceLoader.Load("res://sprites/" + SlotType.ToString() + ".png");
// Assign the texture to the Sprite
if (texture != null)
{
this.Texture = texture;
}
}
private T GetRandomEnumValue<T>() where T : Enum
{
// Get all values of the enum
Array values = Enum.GetValues(typeof(T));
// Use Godot's random number generator
RandomNumberGenerator rng = new RandomNumberGenerator();
rng.Randomize();
// Pick a random index
int randomIndex = rng.RandiRange(0, values.Length - 1);
// Return the randomly selected enum value
return (T)values.GetValue(randomIndex);
}
}