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.
67 lines
1.5 KiB
67 lines
1.5 KiB
using Godot;
|
|
using System;
|
|
|
|
public partial class SlotSymbol : Sprite2D
|
|
{
|
|
public enum Type
|
|
{
|
|
BELL,
|
|
BAR,
|
|
SEVEN,
|
|
CHERRY,
|
|
X2,
|
|
SPIN
|
|
}
|
|
|
|
[Export] public Type SlotType;
|
|
|
|
public override void _Ready()
|
|
{
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
const float WRAPAROUND_DISTANCE = 109 * 5;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|