|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public partial class SlotSymbol : Sprite2D
|
|
|
|
{
|
|
|
|
public enum Type
|
|
|
|
{
|
|
|
|
BANANA,
|
|
|
|
BELL,
|
|
|
|
BAR,
|
|
|
|
SEVEN,
|
|
|
|
CHERRY,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|