Browse Source

basic scoring

master
Josh 2 days ago
parent
commit
287cde8e27
  1. 1
      .gitignore
  2. BIN
      .vs/slots/FileContentIndex/2c1cb54c-884e-46af-88be-dbb8b2b2cd87.vsidx
  3. BIN
      .vs/slots/FileContentIndex/6af12eb4-b31e-4107-84ad-4cdf8492e115.vsidx
  4. BIN
      .vs/slots/FileContentIndex/e07062da-369f-4b06-ac47-2208fc8c53f6.vsidx
  5. 0
      .vs/slots/FileContentIndex/read.lock
  6. BIN
      .vs/slots/v17/.suo
  7. 102
      SlotMachine.cs
  8. 15
      SpinsUI.cs
  9. 24
      Wheel.cs
  10. 50
      game.tscn

1
.gitignore

@ -1,3 +1,4 @@
# Godot 4+ specific ignores
.godot/
/android/
.vs/slots/FileContentIndex

BIN
.vs/slots/FileContentIndex/2c1cb54c-884e-46af-88be-dbb8b2b2cd87.vsidx

Binary file not shown.

BIN
.vs/slots/FileContentIndex/6af12eb4-b31e-4107-84ad-4cdf8492e115.vsidx

Binary file not shown.

BIN
.vs/slots/FileContentIndex/e07062da-369f-4b06-ac47-2208fc8c53f6.vsidx

Binary file not shown.

0
.vs/slots/FileContentIndex/read.lock

BIN
.vs/slots/v17/.suo

Binary file not shown.

102
SlotMachine.cs

@ -1,23 +1,123 @@
using Godot;
using Godot.NativeInterop;
using System;
using System.Collections.Generic;
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 = 7;
}
// 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;
foreach (Wheel wheel in Wheels)
{
SlotSymbol newSlotSymbol = wheel.GetActiveSlotSymbol();
int matches = 0;
foreach (SlotSymbol otherSlot in slots)
{
if (otherSlot.SlotType == newSlotSymbol.SlotType)
{
matches++;
}
if (newSlotSymbol.SlotType == SlotSymbol.Type.SEVEN)
{
points += 7;
}
}
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)
@ -27,5 +127,3 @@ public partial class SlotMachine : Sprite2D
}
}
}
}
}

15
SpinsUI.cs

@ -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)
{
}
}

24
Wheel.cs

@ -1,20 +1,34 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public partial class Wheel : Sprite2D
{
public float Speed;
bool _spinning = false;
public bool Spinning { get => _spinning; set => _spinning = value; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
public SlotSymbol GetActiveSlotSymbol()
{
List<SlotSymbol> children = GetChildren()
.OfType<SlotSymbol>() // Filter to only include Node2D or derived nodes
.OrderBy(child => child.Position.Y) // Sort by Y value
.ToList();
GD.Print("slot type: " + children[3].SlotType);
return children[3];
}
public async void Spin(float extraLength)
{
_spinning = true;
Spinning = true;
Speed = (float)GD.RandRange(1200f, 2000f);
await ToSignal(GetTree().CreateTimer(2.0f + extraLength), SceneTreeTimer.SignalName.Timeout);
@ -25,10 +39,11 @@ public partial class Wheel : Sprite2D
//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)
if (Spinning == false)
return;
float dt = (float)delta;
@ -42,13 +57,16 @@ public partial class Wheel : Sprite2D
if (originalMod < 2)
{
_spinning = false;
Spinning = false;
Speed = 0;
}
}
if (Speed <= 0)
{
Spinning = false;
return;
}
this.Position += new Vector2(0f, Speed * dt);

50
game.tscn

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://bxnxpcc3hwrrf"]
[gd_scene load_steps=12 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"]
@ -9,6 +9,10 @@
[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"]
[ext_resource type="Script" path="res://SpinsUI.cs" id="10_1u7q7"]
[sub_resource type="LabelSettings" id="LabelSettings_my47k"]
font_size = 33
[node name="Game" type="Node2D"]
@ -49,7 +53,7 @@ SlotType = 1
position = Vector2(-120, 143)
texture = ExtResource("2_epvcj")
script = ExtResource("5_3my0i")
SlotType = 1
SlotType = 3
[node name="wheel2" type="Sprite2D" parent="slot machine" node_paths=PackedStringArray("SlotSymbols")]
position = Vector2(127, 0)
@ -83,7 +87,7 @@ SlotType = 1
position = Vector2(-120, 143)
texture = ExtResource("2_epvcj")
script = ExtResource("5_3my0i")
SlotType = 1
SlotType = 3
[node name="wheel3" type="Sprite2D" parent="slot machine" node_paths=PackedStringArray("SlotSymbols")]
position = Vector2(259, 0)
@ -117,8 +121,46 @@ SlotType = 1
position = Vector2(-120, 143)
texture = ExtResource("2_epvcj")
script = ExtResource("5_3my0i")
SlotType = 1
SlotType = 3
[node name="slot-front" type="Sprite2D" parent="slot machine"]
position = Vector2(2, -3)
texture = ExtResource("6_u8o3a")
[node name="ColorRect" type="ColorRect" parent="slot machine"]
offset_left = -279.679
offset_top = -346.019
offset_right = -239.679
offset_bottom = -306.019
scale = Vector2(14.16, 1)
color = Color(0.247059, 0.231373, 0.576471, 1)
[node name="Spins" type="Label" parent="."]
unique_name_in_owner = true
offset_left = 110.0
offset_top = 586.0
offset_right = 231.0
offset_bottom = 632.0
text = "Spins: 2"
label_settings = SubResource("LabelSettings_my47k")
script = ExtResource("10_1u7q7")
[node name="Readout" type="Label" parent="."]
unique_name_in_owner = true
offset_left = 358.0
offset_top = 586.0
offset_right = 479.0
offset_bottom = 632.0
label_settings = SubResource("LabelSettings_my47k")
horizontal_alignment = 2
script = ExtResource("10_1u7q7")
[node name="Points" type="Label" parent="."]
unique_name_in_owner = true
offset_left = 225.0
offset_top = 24.0
offset_right = 346.0
offset_bottom = 70.0
text = "000000"
label_settings = SubResource("LabelSettings_my47k")
horizontal_alignment = 2

Loading…
Cancel
Save