|
|
|
using Godot;
|
|
|
|
using Godot.NativeInterop;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
public partial class SlotMachine : Sprite2D
|
|
|
|
{
|
|
|
|
[Export] public Wheel[] Wheels;
|
|
|
|
int _spins;
|
|
|
|
int _points;
|
|
|
|
|
|
|
|
bool _isSpinning = false;
|
|
|
|
|
|
|
|
public int Spins
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _spins;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_spins = value;
|
|
|
|
GetNode<SpinsUI>("%Spins").Text = _spins + " spins";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Points
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _points;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_points = value;
|
|
|
|
GetNode<Label>("%Points").Text = _points.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
Spins = 9;
|
|
|
|
GetOptionPicker().Show(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
|
|
|
if (_isSpinning)
|
|
|
|
{
|
|
|
|
bool stillSpinning = false;
|
|
|
|
foreach (Wheel wheel in Wheels)
|
|
|
|
{
|
|
|
|
if (wheel.Spinning)
|
|
|
|
stillSpinning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stillSpinning == false)
|
|
|
|
{
|
|
|
|
Score();
|
|
|
|
|
|
|
|
_isSpinning = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Score()
|
|
|
|
{
|
|
|
|
List<SlotSymbol> slots = new List<SlotSymbol>();
|
|
|
|
int points = 0;
|
|
|
|
|
|
|
|
bool x2 = false;
|
|
|
|
|
|
|
|
foreach (Wheel wheel in Wheels)
|
|
|
|
{
|
|
|
|
SlotSymbol newSlotSymbol = wheel.GetActiveSlotSymbol();
|
|
|
|
int matches = 0;
|
|
|
|
|
|
|
|
foreach (SlotSymbol otherSlot in slots)
|
|
|
|
{
|
|
|
|
if (otherSlot.SlotType == newSlotSymbol.SlotType && newSlotSymbol.SlotType != SlotSymbol.Type.SPIN && newSlotSymbol.SlotType != SlotSymbol.Type.X2)
|
|
|
|
{
|
|
|
|
matches++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (newSlotSymbol.SlotType == SlotSymbol.Type.SEVEN)
|
|
|
|
{
|
|
|
|
points += 7;
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.SPIN)
|
|
|
|
{
|
|
|
|
Spins++;
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.X2)
|
|
|
|
{
|
|
|
|
x2 = true;
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.CHERRY)
|
|
|
|
{
|
|
|
|
if (matches == 2)
|
|
|
|
{
|
|
|
|
points += 15;
|
|
|
|
}
|
|
|
|
else if (matches == 1)
|
|
|
|
{
|
|
|
|
points += 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
points += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.BANANA)
|
|
|
|
{
|
|
|
|
if (matches == 2)
|
|
|
|
{
|
|
|
|
points += 20;
|
|
|
|
}
|
|
|
|
else if (matches == 1)
|
|
|
|
{
|
|
|
|
points += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.BELL)
|
|
|
|
{
|
|
|
|
if (matches == 2)
|
|
|
|
{
|
|
|
|
points += 75;
|
|
|
|
}
|
|
|
|
else if (matches == 1)
|
|
|
|
{
|
|
|
|
points += 25;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (newSlotSymbol.SlotType == SlotSymbol.Type.BAR)
|
|
|
|
{
|
|
|
|
if (matches == 2)
|
|
|
|
{
|
|
|
|
points += 150;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
slots.Add(newSlotSymbol);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x2)
|
|
|
|
{
|
|
|
|
points *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetNode<Label>("%Readout").Text = "+" + points.ToString();
|
|
|
|
Points += points;
|
|
|
|
GetOptionPicker().Reset();
|
|
|
|
GetOptionPicker().Show(true);
|
|
|
|
HideReadout();
|
|
|
|
}
|
|
|
|
|
|
|
|
async void HideReadout()
|
|
|
|
{
|
|
|
|
await ToSignal(GetTree().CreateTimer(1.5f), SceneTreeTimer.SignalName.Timeout);
|
|
|
|
GetNode<Label>("%Readout").Text = "";
|
|
|
|
}
|
|
|
|
OptionPicker GetOptionPicker()
|
|
|
|
{
|
|
|
|
return GetNode<OptionPicker>("%OptionPicker");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
{
|
|
|
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
|
|
|
{
|
|
|
|
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter || keyEvent.Keycode == Key.Space)
|
|
|
|
{
|
|
|
|
Spin();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_isSpinning == false)
|
|
|
|
{
|
|
|
|
if (keyEvent.Keycode == Key.Key1)
|
|
|
|
{
|
|
|
|
Wheels[0].ReplaceCurrentOption(GetOptionPicker().Select(0));
|
|
|
|
}
|
|
|
|
if (keyEvent.Keycode == Key.Key2)
|
|
|
|
{
|
|
|
|
Wheels[1].ReplaceCurrentOption(GetOptionPicker().Select(1));
|
|
|
|
}
|
|
|
|
if (keyEvent.Keycode == Key.Key3)
|
|
|
|
{
|
|
|
|
Wheels[2].ReplaceCurrentOption(GetOptionPicker().Select(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Spin()
|
|
|
|
{
|
|
|
|
if (Spins <= 0 || _isSpinning)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetOptionPicker().Show(false);
|
|
|
|
GetNode<Label>("%Readout").Text = "";
|
|
|
|
_isSpinning = true;
|
|
|
|
Spins--;
|
|
|
|
float extraLength = 0f;
|
|
|
|
|
|
|
|
foreach (Wheel wheel in Wheels)
|
|
|
|
{
|
|
|
|
wheel.Spin(extraLength);
|
|
|
|
extraLength += 1f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|