From 19fc024b4c80cc0016ac5f36c5f487d27cfcbe5d Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 7 Sep 2022 11:52:26 -0500 Subject: [PATCH] Add dice roller --- Scenes/HUD.tscn | 49 ++++++++++++++++++++++++++++++++++++------- Scripts/DiceRoller.gd | 10 +++++++++ devlog.md | 1 + 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 Scripts/DiceRoller.gd diff --git a/Scenes/HUD.tscn b/Scenes/HUD.tscn index 8190e91..4456d31 100644 --- a/Scenes/HUD.tscn +++ b/Scenes/HUD.tscn @@ -1,22 +1,57 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=16 format=2] [ext_resource path="res://Assets/white-1.png" type="Texture" id=1] [ext_resource path="res://Assets/black-1.png" type="Texture" id=2] +[ext_resource path="res://Assets/white-6.png" type="Texture" id=3] +[ext_resource path="res://Assets/white-5.png" type="Texture" id=4] +[ext_resource path="res://Assets/white-3.png" type="Texture" id=5] +[ext_resource path="res://Assets/white-2.png" type="Texture" id=6] +[ext_resource path="res://Assets/white-4.png" type="Texture" id=7] +[ext_resource path="res://Assets/black-3.png" type="Texture" id=8] +[ext_resource path="res://Assets/black-5.png" type="Texture" id=9] +[ext_resource path="res://Assets/black-6.png" type="Texture" id=10] +[ext_resource path="res://Assets/black-2.png" type="Texture" id=11] +[ext_resource path="res://Assets/black-4.png" type="Texture" id=12] +[ext_resource path="res://Scripts/DiceRoller.gd" type="Script" id=13] + +[sub_resource type="SpriteFrames" id=1] +animations = [ { +"frames": [ ExtResource( 1 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="SpriteFrames" id=2] +animations = [ { +"frames": [ ExtResource( 2 ), ExtResource( 11 ), ExtResource( 8 ), ExtResource( 12 ), ExtResource( 9 ), ExtResource( 10 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] [node name="HUD" type="CanvasLayer"] -[node name="Control" type="Control" parent="."] +[node name="DiceRoller" type="Control" parent="."] anchor_left = 1.0 anchor_right = 1.0 margin_left = -307.0 margin_bottom = 65.0 +script = ExtResource( 13 ) -[node name="Dice1" type="Sprite" parent="Control"] +[node name="Dice1" type="AnimatedSprite" parent="DiceRoller"] position = Vector2( 179.876, 32.8762 ) scale = Vector2( 0.0621776, 0.0621776 ) -texture = ExtResource( 1 ) +frames = SubResource( 1 ) -[node name="Dice2" type="Sprite" parent="Control"] -position = Vector2( 241.876, 32.8762 ) +[node name="Dice2" type="AnimatedSprite" parent="DiceRoller"] +position = Vector2( 246, 33 ) scale = Vector2( 0.0621776, 0.0621776 ) -texture = ExtResource( 2 ) +frames = SubResource( 2 ) + +[node name="Button" type="Button" parent="DiceRoller"] +margin_left = 54.0 +margin_top = 9.0 +margin_right = 143.0 +margin_bottom = 57.0 +text = "Roll" diff --git a/Scripts/DiceRoller.gd b/Scripts/DiceRoller.gd new file mode 100644 index 0000000..f702b7f --- /dev/null +++ b/Scripts/DiceRoller.gd @@ -0,0 +1,10 @@ +extends Control + +onready var rng = RandomNumberGenerator.new() + +func _ready(): + $Button.connect("pressed", self, "roll") + +func roll(): + $Dice1.frame = rng.randi_range(0, 6) + $Dice2.frame = rng.randi_range(0, 6) diff --git a/devlog.md b/devlog.md index 611a863..2a1bcab 100644 --- a/devlog.md +++ b/devlog.md @@ -5,6 +5,7 @@ - Docks - Placement on corners - MP framework (at least the board) +- Roll dice ## Dane - 08/26/22 @ 2:27 pm