Josh
2 days ago
11 changed files with 211 additions and 29 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
*/ |
|||
} |
|||
} |
@ -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") |
|||
|
Loading…
Reference in new issue