Josh
2 days ago
10 changed files with 190 additions and 16 deletions
@ -1,3 +1,4 @@ |
|||||
# Godot 4+ specific ignores |
# Godot 4+ specific ignores |
||||
.godot/ |
.godot/ |
||||
/android/ |
/android/ |
||||
|
.vs/slots/FileContentIndex |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,31 +1,129 @@ |
|||||
using Godot; |
using Godot; |
||||
|
using Godot.NativeInterop; |
||||
using System; |
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
public partial class SlotMachine : Sprite2D |
public partial class SlotMachine : Sprite2D |
||||
{ |
{ |
||||
[Export] public Wheel[] Wheels; |
[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() |
public override void _Ready() |
||||
{ |
{ |
||||
|
Spins = 7; |
||||
} |
} |
||||
|
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta) |
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; |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
public override void _Input(InputEvent @event) |
|
||||
|
private void Score() |
||||
{ |
{ |
||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed) |
List<SlotSymbol> slots = new List<SlotSymbol>(); |
||||
|
int points = 0; |
||||
|
|
||||
|
foreach (Wheel wheel in Wheels) |
||||
{ |
{ |
||||
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter) |
SlotSymbol newSlotSymbol = wheel.GetActiveSlotSymbol(); |
||||
|
int matches = 0; |
||||
|
foreach (SlotSymbol otherSlot in slots) |
||||
{ |
{ |
||||
float extraLength = 0f; |
if (otherSlot.SlotType == newSlotSymbol.SlotType) |
||||
|
{ |
||||
|
matches++; |
||||
|
} |
||||
|
|
||||
foreach (Wheel wheel in Wheels) |
if (newSlotSymbol.SlotType == SlotSymbol.Type.SEVEN) |
||||
{ |
{ |
||||
wheel.Spin(extraLength); |
points += 7; |
||||
extraLength += 1f; |
|
||||
} |
} |
||||
} |
} |
||||
|
slots.Add(newSlotSymbol); |
||||
|
|
||||
|
if (matches == 1) { |
||||
|
points += 100; |
||||
|
} |
||||
|
else if (matches == 2) |
||||
|
{ |
||||
|
points += 400; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
GetNode<Label>("%Readout").Text = points.ToString(); |
||||
|
Points += points; |
||||
|
} |
||||
|
|
||||
|
public override void _Input(InputEvent @event) |
||||
|
{ |
||||
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed) |
||||
|
{ |
||||
|
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter) |
||||
|
{ |
||||
|
Spin(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void Spin() |
||||
|
{ |
||||
|
if (Spins <= 0 || _isSpinning) |
||||
|
return; |
||||
|
GetNode<Label>("%Readout").Text = ""; |
||||
|
_isSpinning = true; |
||||
|
Spins--; |
||||
|
float extraLength = 0f; |
||||
|
|
||||
|
foreach (Wheel wheel in Wheels) |
||||
|
{ |
||||
|
wheel.Spin(extraLength); |
||||
|
extraLength += 1f; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,15 @@ |
|||||
|
using Godot; |
||||
|
using System; |
||||
|
public partial class SpinsUI : Label |
||||
|
{ |
||||
|
// Called when the node enters the scene tree for the first time.
|
||||
|
public override void _Ready() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
public override void _Process(double delta) |
||||
|
{ |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue