diff --git a/.vs/slots/DesignTimeBuild/.dtbcache.v2 b/.vs/slots/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 0000000..b070215 Binary files /dev/null and b/.vs/slots/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/slots/FileContentIndex/2c1cb54c-884e-46af-88be-dbb8b2b2cd87.vsidx b/.vs/slots/FileContentIndex/2c1cb54c-884e-46af-88be-dbb8b2b2cd87.vsidx new file mode 100644 index 0000000..0b32014 Binary files /dev/null and b/.vs/slots/FileContentIndex/2c1cb54c-884e-46af-88be-dbb8b2b2cd87.vsidx differ diff --git a/.vs/slots/FileContentIndex/6af12eb4-b31e-4107-84ad-4cdf8492e115.vsidx b/.vs/slots/FileContentIndex/6af12eb4-b31e-4107-84ad-4cdf8492e115.vsidx new file mode 100644 index 0000000..322cca7 Binary files /dev/null and b/.vs/slots/FileContentIndex/6af12eb4-b31e-4107-84ad-4cdf8492e115.vsidx differ diff --git a/.vs/slots/FileContentIndex/e07062da-369f-4b06-ac47-2208fc8c53f6.vsidx b/.vs/slots/FileContentIndex/e07062da-369f-4b06-ac47-2208fc8c53f6.vsidx new file mode 100644 index 0000000..5764a59 Binary files /dev/null and b/.vs/slots/FileContentIndex/e07062da-369f-4b06-ac47-2208fc8c53f6.vsidx differ diff --git a/.vs/slots/FileContentIndex/read.lock b/.vs/slots/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/slots/v17/.suo b/.vs/slots/v17/.suo new file mode 100644 index 0000000..562cb31 Binary files /dev/null and b/.vs/slots/v17/.suo differ diff --git a/SlotMachine.cs b/SlotMachine.cs new file mode 100644 index 0000000..f1d5468 --- /dev/null +++ b/SlotMachine.cs @@ -0,0 +1,31 @@ +using Godot; +using System; + +public partial class SlotMachine : Sprite2D +{ + [Export] public Wheel[] Wheels; + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + public override void _Input(InputEvent @event) + { + if (@event is InputEventKey keyEvent && keyEvent.Pressed) + { + if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter) + { + float extraLength = 0f; + + foreach (Wheel wheel in Wheels) + { + wheel.Spin(extraLength); + extraLength += 1f; + } + } + } + } +} diff --git a/SlotSymbol.cs b/SlotSymbol.cs new file mode 100644 index 0000000..7e4a6e9 --- /dev/null +++ b/SlotSymbol.cs @@ -0,0 +1,36 @@ +using Godot; +using System; + +public partial class SlotSymbol : Sprite2D +{ + public enum Type + { + BELL, + BAR, + SEVEN, + CHERRY, + BLANK + } + + [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); + } + } +} diff --git a/Wheel.cs b/Wheel.cs index 7b0e2fc..a35992d 100644 --- a/Wheel.cs +++ b/Wheel.cs @@ -1,33 +1,74 @@ using Godot; using System; +using System.Collections.Generic; +using System.Threading.Tasks; public partial class Wheel : Sprite2D { - float _speed; - // Called when the node enters the scene tree for the first time. - public override void _Ready() + public float Speed; + bool _spinning = false; + // Called when the node enters the scene tree for the first time. + public override void _Ready() { - _speed = 1000f; } + public async void Spin(float extraLength) + { + _spinning = true; + Speed = (float)GD.RandRange(1200f, 2000f); + await ToSignal(GetTree().CreateTimer(2.0f + extraLength), SceneTreeTimer.SignalName.Timeout); + + Tween tween = GetTree().CreateTween(); + tween.TweenProperty(this, "Speed", 0, 1.0f); + } + + //Export] public Godot.Collections.Array Symbols; + [Export] public SlotSymbol[] SlotSymbols; + // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) - { + { + if (_spinning == false) + return; float dt = (float)delta; - _speed -= dt * 250f; + float minSpeed = 100f; + const float SPACING = 109f; - if (_speed <= 0) - return; + float originalMod = this.Position.Y % SPACING; + if (Speed <= minSpeed) { + Speed = minSpeed; - this.Position += new Vector2(0f, _speed * dt); + if (originalMod < 2) + { + _spinning = false; + Speed = 0; + } + } + + if (Speed <= 0) + return; + this.Position += new Vector2(0f, Speed * dt); + + /* + //check if we overshot the target + if (Speed <= minSpeed && this.Position.Y % SPACING > originalMod) + { + _spinning = false; + Speed = 0f; + } + */ + + + /* const float Y_WRAPAROUND = 464; if (Position.Y > Y_WRAPAROUND) { Position -= new Vector2(0f, Y_WRAPAROUND); } - } + */ + } } \ No newline at end of file diff --git a/game.tscn b/game.tscn index 63c5422..ddae43b 100644 --- a/game.tscn +++ b/game.tscn @@ -1,50 +1,124 @@ -[gd_scene load_steps=8 format=3 uid="uid://bxnxpcc3hwrrf"] +[gd_scene load_steps=10 format=3 uid="uid://bxnxpcc3hwrrf"] [ext_resource type="Texture2D" uid="uid://45e6o8fnn5g6" path="res://sprites/slot-machine1.png" id="1_67gbi"] [ext_resource type="Texture2D" uid="uid://cl1qwesnw8di7" path="res://sprites/slot-symbol2.png" id="2_epvcj"] +[ext_resource type="Script" path="res://SlotMachine.cs" id="2_fbgsk"] [ext_resource type="Script" path="res://Wheel.cs" id="2_p4s0j"] [ext_resource type="Texture2D" uid="uid://bqupkucthyf6k" path="res://sprites/slot-symbol1.png" id="3_mqf40"] [ext_resource type="Texture2D" uid="uid://b7512aakq5qsn" path="res://sprites/slot-symbol3.png" id="4_cdn8h"] +[ext_resource type="Script" path="res://SlotSymbol.cs" id="5_3my0i"] [ext_resource type="Texture2D" uid="uid://b746l2ipvabqy" path="res://sprites/slot-symbol4.png" id="5_gusk3"] [ext_resource type="Texture2D" uid="uid://dhid2cal2tbv2" path="res://sprites/slot-machine4.png" id="6_u8o3a"] [node name="Game" type="Node2D"] -[node name="slot-reference" type="Sprite2D" parent="."] +[node name="slot machine" type="Sprite2D" parent="." node_paths=PackedStringArray("Wheels")] position = Vector2(288, 320) texture = ExtResource("1_67gbi") +script = ExtResource("2_fbgsk") +Wheels = [NodePath("wheel"), NodePath("wheel2"), NodePath("wheel3")] -[node name="wheel" type="Sprite2D" parent="slot-reference"] +[node name="wheel" type="Sprite2D" parent="slot machine" node_paths=PackedStringArray("SlotSymbols")] script = ExtResource("2_p4s0j") +SlotSymbols = [NodePath("Slot-symbol1"), NodePath("Slot-symbol2"), NodePath("Slot-symbol3"), NodePath("Slot-symbol4"), NodePath("Slot-symbol5")] -[node name="top repeat" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-120, -422) +[node name="Slot-symbol1" type="Sprite2D" parent="slot machine/wheel"] +position = Vector2(-126, -293) +texture = ExtResource("3_mqf40") +script = ExtResource("5_3my0i") +SlotType = 2 + +[node name="Slot-symbol2" type="Sprite2D" parent="slot machine/wheel"] +position = Vector2(-130, -184) +texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 3 + +[node name="Slot-symbol3" type="Sprite2D" parent="slot machine/wheel"] +position = Vector2(-123, -75) +texture = ExtResource("4_cdn8h") +script = ExtResource("5_3my0i") + +[node name="Slot-symbol4" type="Sprite2D" parent="slot machine/wheel"] +position = Vector2(-120, 34) texture = ExtResource("5_gusk3") +script = ExtResource("5_3my0i") +SlotType = 1 + +[node name="Slot-symbol5" type="Sprite2D" parent="slot machine/wheel"] +position = Vector2(-120, 143) +texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 1 -[node name="Slot-symbol1" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-126, -304) +[node name="wheel2" type="Sprite2D" parent="slot machine" node_paths=PackedStringArray("SlotSymbols")] +position = Vector2(127, 0) +script = ExtResource("2_p4s0j") +SlotSymbols = [NodePath("Slot-symbol1"), NodePath("Slot-symbol2"), NodePath("Slot-symbol3"), NodePath("Slot-symbol4"), NodePath("Slot-symbol5")] + +[node name="Slot-symbol1" type="Sprite2D" parent="slot machine/wheel2"] +position = Vector2(-126, -293) texture = ExtResource("3_mqf40") +script = ExtResource("5_3my0i") +SlotType = 2 -[node name="Slot-symbol2" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-130, -190) +[node name="Slot-symbol2" type="Sprite2D" parent="slot machine/wheel2"] +position = Vector2(-130, -184) texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 3 -[node name="Slot-symbol3" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-123, -76) +[node name="Slot-symbol3" type="Sprite2D" parent="slot machine/wheel2"] +position = Vector2(-123, -75) texture = ExtResource("4_cdn8h") +script = ExtResource("5_3my0i") + +[node name="Slot-symbol4" type="Sprite2D" parent="slot machine/wheel2"] +position = Vector2(-120, 34) +texture = ExtResource("5_gusk3") +script = ExtResource("5_3my0i") +SlotType = 1 + +[node name="Slot-symbol5" type="Sprite2D" parent="slot machine/wheel2"] +position = Vector2(-120, 143) +texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 1 + +[node name="wheel3" type="Sprite2D" parent="slot machine" node_paths=PackedStringArray("SlotSymbols")] +position = Vector2(259, 0) +script = ExtResource("2_p4s0j") +SlotSymbols = [NodePath("Slot-symbol1"), NodePath("Slot-symbol2"), NodePath("Slot-symbol3"), NodePath("Slot-symbol4"), NodePath("Slot-symbol5")] -[node name="top repeat2" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-123, -537) +[node name="Slot-symbol1" type="Sprite2D" parent="slot machine/wheel3"] +position = Vector2(-126, -293) +texture = ExtResource("3_mqf40") +script = ExtResource("5_3my0i") +SlotType = 2 + +[node name="Slot-symbol2" type="Sprite2D" parent="slot machine/wheel3"] +position = Vector2(-130, -184) +texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 3 + +[node name="Slot-symbol3" type="Sprite2D" parent="slot machine/wheel3"] +position = Vector2(-123, -75) texture = ExtResource("4_cdn8h") +script = ExtResource("5_3my0i") -[node name="Slot-symbol5" type="Sprite2D" parent="slot-reference/wheel"] +[node name="Slot-symbol4" type="Sprite2D" parent="slot machine/wheel3"] position = Vector2(-120, 34) texture = ExtResource("5_gusk3") +script = ExtResource("5_3my0i") +SlotType = 1 -[node name="bottom repeat" type="Sprite2D" parent="slot-reference/wheel"] -position = Vector2(-126, 143) -texture = ExtResource("3_mqf40") +[node name="Slot-symbol5" type="Sprite2D" parent="slot machine/wheel3"] +position = Vector2(-120, 143) +texture = ExtResource("2_epvcj") +script = ExtResource("5_3my0i") +SlotType = 1 -[node name="slot-front" type="Sprite2D" parent="slot-reference"] +[node name="slot-front" type="Sprite2D" parent="slot machine"] position = Vector2(2, -3) texture = ExtResource("6_u8o3a") diff --git a/project.godot b/project.godot index 878bf6d..1319fc8 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="slots" run/main_scene="res://game.tscn" -config/features=PackedStringArray("4.3", "Forward Plus") +config/features=PackedStringArray("4.3", "C#", "Forward Plus") config/icon="res://icon.svg" [dotnet]