Browse Source

first playable

master
Josh 2 days ago
parent
commit
5d7b8517af
  1. BIN
      .vs/slots/v17/.suo
  2. 40
      OptionPicker.cs
  3. 48
      SlotMachine.cs
  4. 33
      SlotSymbol.cs
  5. 6
      Wheel.cs
  6. 46
      game.tscn
  7. 0
      sprites/BAR.png
  8. 6
      sprites/BAR.png.import
  9. 0
      sprites/BELL.png
  10. 6
      sprites/BELL.png.import
  11. 0
      sprites/CHERRY.png
  12. 6
      sprites/CHERRY.png.import
  13. 0
      sprites/SEVEN.png
  14. 6
      sprites/SEVEN.png.import
  15. BIN
      sprites/SPIN.png
  16. 34
      sprites/SPIN.png.import
  17. BIN
      sprites/X2.png
  18. 34
      sprites/X2.png.import

BIN
.vs/slots/v17/.suo

Binary file not shown.

40
OptionPicker.cs

@ -0,0 +1,40 @@
using Godot;
using System;
public partial class OptionPicker : Node2D
{
// 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)
{
}
public void Reset()
{
foreach (Node child in GetChildren())
{
if (child is SlotSymbol slotSymbol)
{
slotSymbol.SetToRandom();
}
}
}
public void Show(bool visible)
{
foreach (CanvasItem child in GetChildren())
{
child.Visible = visible;
}
}
public SlotSymbol Select(int index)
{
Show(false);
return GetChildren()[index] as SlotSymbol;
}
}

48
SlotMachine.cs

@ -2,6 +2,7 @@ using Godot;
using Godot.NativeInterop;
using System;
using System.Collections.Generic;
using System.Numerics;
public partial class SlotMachine : Sprite2D
{
@ -40,6 +41,8 @@ public partial class SlotMachine : Sprite2D
public override void _Ready()
{
Spins = 7;
GetOptionPicker().Show(false);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
@ -68,22 +71,35 @@ public partial class SlotMachine : Sprite2D
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)
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;
}
slots.Add(newSlotSymbol);
if (matches == 1) {
@ -93,11 +109,22 @@ public partial class SlotMachine : Sprite2D
{
points += 400;
}
}
if (x2)
{
points *= 2;
}
GetNode<Label>("%Readout").Text = points.ToString();
Points += points;
GetOptionPicker().Reset();
GetOptionPicker().Show(true);
}
OptionPicker GetOptionPicker()
{
return GetNode<OptionPicker>("%OptionPicker");
}
public override void _Input(InputEvent @event)
@ -108,6 +135,23 @@ public partial class SlotMachine : Sprite2D
{
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));
}
}
}
}
@ -115,6 +159,8 @@ public partial class SlotMachine : Sprite2D
{
if (Spins <= 0 || _isSpinning)
return;
GetOptionPicker().Show(false);
GetNode<Label>("%Readout").Text = "";
_isSpinning = true;
Spins--;

33
SlotSymbol.cs

@ -9,7 +9,8 @@ public partial class SlotSymbol : Sprite2D
BAR,
SEVEN,
CHERRY,
BLANK
X2,
SPIN
}
[Export] public Type SlotType;
@ -33,4 +34,34 @@ public partial class SlotSymbol : Sprite2D
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);
}
}

6
Wheel.cs

@ -39,6 +39,12 @@ public partial class Wheel : Sprite2D
//Export] public Godot.Collections.Array Symbols;
[Export] public SlotSymbol[] SlotSymbols;
public void ReplaceCurrentOption(SlotSymbol newOption)
{
SlotSymbol currentOption = GetActiveSlotSymbol();
currentOption.SlotType = newOption.SlotType;
currentOption.Texture = newOption.Texture;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)

46
game.tscn

@ -1,15 +1,16 @@
[gd_scene load_steps=12 format=3 uid="uid://bxnxpcc3hwrrf"]
[gd_scene load_steps=13 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="Texture2D" uid="uid://cl1qwesnw8di7" path="res://sprites/CHERRY.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="Texture2D" uid="uid://bqupkucthyf6k" path="res://sprites/SEVEN.png" id="3_mqf40"]
[ext_resource type="Texture2D" uid="uid://b7512aakq5qsn" path="res://sprites/BELL.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://b746l2ipvabqy" path="res://sprites/BAR.png" id="5_gusk3"]
[ext_resource type="Texture2D" uid="uid://dhid2cal2tbv2" path="res://sprites/slot-machine4.png" id="6_u8o3a"]
[ext_resource type="Script" path="res://SpinsUI.cs" id="10_1u7q7"]
[ext_resource type="Script" path="res://OptionPicker.cs" id="11_uyb7w"]
[sub_resource type="LabelSettings" id="LabelSettings_my47k"]
font_size = 33
@ -164,3 +165,38 @@ offset_bottom = 70.0
text = "000000"
label_settings = SubResource("LabelSettings_my47k")
horizontal_alignment = 2
[node name="PayTable" type="Label" parent="."]
unique_name_in_owner = true
offset_left = 785.0
offset_top = 126.0
offset_right = 906.0
offset_bottom = 172.0
text = "7 = 7
pair = 100
3 of a kind = 500"
label_settings = SubResource("LabelSettings_my47k")
horizontal_alignment = 2
[node name="OptionPicker" type="Node2D" parent="."]
unique_name_in_owner = true
position = Vector2(5, 317)
script = ExtResource("11_uyb7w")
[node name="Option1" type="Sprite2D" parent="OptionPicker"]
position = Vector2(157, 216)
texture = ExtResource("3_mqf40")
script = ExtResource("5_3my0i")
SlotType = 2
[node name="Option2" type="Sprite2D" parent="OptionPicker"]
position = Vector2(288, 216)
texture = ExtResource("3_mqf40")
script = ExtResource("5_3my0i")
SlotType = 2
[node name="Option3" type="Sprite2D" parent="OptionPicker"]
position = Vector2(415, 216)
texture = ExtResource("3_mqf40")
script = ExtResource("5_3my0i")
SlotType = 2

0
sprites/slot-symbol4.png → sprites/BAR.png

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

6
sprites/slot-symbol4.png.import → sprites/BAR.png.import

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://b746l2ipvabqy"
path="res://.godot/imported/slot-symbol4.png-6a8ada69d03d68fee5694feaaa49f8a5.ctex"
path="res://.godot/imported/BAR.png-3c4692c1bbeaa1b1e8a4d9e1dfc1945b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/slot-symbol4.png"
dest_files=["res://.godot/imported/slot-symbol4.png-6a8ada69d03d68fee5694feaaa49f8a5.ctex"]
source_file="res://sprites/BAR.png"
dest_files=["res://.godot/imported/BAR.png-3c4692c1bbeaa1b1e8a4d9e1dfc1945b.ctex"]
[params]

0
sprites/slot-symbol3.png → sprites/BELL.png

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

6
sprites/slot-symbol3.png.import → sprites/BELL.png.import

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://b7512aakq5qsn"
path="res://.godot/imported/slot-symbol3.png-1b313b4e8fefcdd028c5950af0574b07.ctex"
path="res://.godot/imported/BELL.png-eccb1fbb618a8c2bc08b1defe3139f6e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/slot-symbol3.png"
dest_files=["res://.godot/imported/slot-symbol3.png-1b313b4e8fefcdd028c5950af0574b07.ctex"]
source_file="res://sprites/BELL.png"
dest_files=["res://.godot/imported/BELL.png-eccb1fbb618a8c2bc08b1defe3139f6e.ctex"]
[params]

0
sprites/slot-symbol2.png → sprites/CHERRY.png

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

6
sprites/slot-symbol2.png.import → sprites/CHERRY.png.import

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cl1qwesnw8di7"
path="res://.godot/imported/slot-symbol2.png-1583861ad4568db66c67a72d2418382a.ctex"
path="res://.godot/imported/CHERRY.png-246458a2f6cbef2950e58ba949e5acbd.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/slot-symbol2.png"
dest_files=["res://.godot/imported/slot-symbol2.png-1583861ad4568db66c67a72d2418382a.ctex"]
source_file="res://sprites/CHERRY.png"
dest_files=["res://.godot/imported/CHERRY.png-246458a2f6cbef2950e58ba949e5acbd.ctex"]
[params]

0
sprites/slot-symbol1.png → sprites/SEVEN.png

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

6
sprites/slot-symbol1.png.import → sprites/SEVEN.png.import

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://bqupkucthyf6k"
path="res://.godot/imported/slot-symbol1.png-112584ad197cfe60b649a7c8ec359c57.ctex"
path="res://.godot/imported/SEVEN.png-f8fdcdce3ddb31c272c50ac037c85ada.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/slot-symbol1.png"
dest_files=["res://.godot/imported/slot-symbol1.png-112584ad197cfe60b649a7c8ec359c57.ctex"]
source_file="res://sprites/SEVEN.png"
dest_files=["res://.godot/imported/SEVEN.png-f8fdcdce3ddb31c272c50ac037c85ada.ctex"]
[params]

BIN
sprites/SPIN.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

34
sprites/SPIN.png.import

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://drejcc82kh6f8"
path="res://.godot/imported/SPIN.png-724f4a40a5c86f8bf6aa669cfbdbd3cf.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/SPIN.png"
dest_files=["res://.godot/imported/SPIN.png-724f4a40a5c86f8bf6aa669cfbdbd3cf.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/X2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

34
sprites/X2.png.import

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bgvashh2kxkkf"
path="res://.godot/imported/X2.png-790ad0a05e5e92e653745ecdcbfed3ef.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/X2.png"
dest_files=["res://.godot/imported/X2.png-790ad0a05e5e92e653745ecdcbfed3ef.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Loading…
Cancel
Save