diff options
Diffstat (limited to 'stage/dice_throw')
-rw-r--r-- | stage/dice_throw/dice.gd | 18 | ||||
-rw-r--r-- | stage/dice_throw/dice.tscn | 81 | ||||
-rw-r--r-- | stage/dice_throw/dice_configuration.gd | 10 | ||||
-rw-r--r-- | stage/dice_throw/dice_configuration.gd.uid | 1 | ||||
-rw-r--r-- | stage/dice_throw/dice_face.gd | 3 | ||||
-rw-r--r-- | stage/dice_throw/dice_face_configuration.gd | 6 | ||||
-rw-r--r-- | stage/dice_throw/dice_face_configuration.gd.uid | 1 | ||||
-rw-r--r-- | stage/dice_throw/dice_throw.gd | 44 |
8 files changed, 133 insertions, 31 deletions
diff --git a/stage/dice_throw/dice.gd b/stage/dice_throw/dice.gd index 291710c..88fdbb8 100644 --- a/stage/dice_throw/dice.gd +++ b/stage/dice_throw/dice.gd @@ -1,3 +1,4 @@ +class_name Dice extends RigidBody3D @@ -5,6 +6,17 @@ var previous_position: Vector3 var previous_rotation: Vector3 var is_moving := false +@export var configuration: DiceConfiguration + + +func _ready() -> void: + %DiceFaceFront.configuration = configuration.front_face + %DiceFaceBack.configuration = configuration.back_face + %DiceFaceTop.configuration = configuration.top_face + %DiceFaceBottom.configuration = configuration.bottom_face + %DiceFaceLeft.configuration = configuration.left_face + %DiceFaceRight.configuration = configuration.right_face + func roll(direction := Vector3(1.0, 1.0, 1.0), strength: float = 20) -> void: var position_impulse := Vector3( @@ -24,10 +36,10 @@ func roll(direction := Vector3(1.0, 1.0, 1.0), strength: float = 20) -> void: apply_torque_impulse(rotation_impulse) -func get_top() -> Node3D: +func get_top() -> DiceFace: var top := -pow(2, 8) - var face: Node3D - for node: Node3D in $Faces.get_children(): + var face: DiceFace + for node: DiceFace in $Faces.get_children(): if top < node.global_transform.origin.y: top = node.global_transform.origin.y face = node diff --git a/stage/dice_throw/dice.tscn b/stage/dice_throw/dice.tscn index 38f13d0..5834cfb 100644 --- a/stage/dice_throw/dice.tscn +++ b/stage/dice_throw/dice.tscn @@ -1,13 +1,61 @@ -[gd_scene load_steps=13 format=3 uid="uid://dnq7fpof6w0mj"] +[gd_scene load_steps=22 format=3 uid="uid://dnq7fpof6w0mj"] [ext_resource type="Script" uid="uid://bajtxq3ucs8f4" path="res://stage/dice_throw/dice.gd" id="1_gwnix"] [ext_resource type="Texture2D" uid="uid://blanietpri1be" path="res://icon.svg" id="2_6tbdd"] +[ext_resource type="Script" uid="uid://dnklife8p0m35" path="res://stage/dice_throw/dice_face_configuration.gd" id="2_6vba1"] [ext_resource type="PackedScene" uid="uid://y1hkmpd41rrq" path="res://stage/dice_throw/dice_face.tscn" id="2_ee854"] +[ext_resource type="Script" uid="uid://6rit5abkk1rw" path="res://stage/dice_throw/dice_configuration.gd" id="3_juxel"] [ext_resource type="Texture2D" uid="uid://dtltt171temec" path="res://stage/assets/tinyBlocks.png" id="3_t0umq"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_m7tx2"] bounce = 0.5 +[sub_resource type="Resource" id="Resource_arxo3"] +script = ExtResource("2_6vba1") +type = "move" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_ms37x"] +script = ExtResource("2_6vba1") +type = "attack" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_tk6el"] +script = ExtResource("2_6vba1") +type = "move" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_l28ne"] +script = ExtResource("2_6vba1") +type = "defend" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_eguj2"] +script = ExtResource("2_6vba1") +type = "ability" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_c3r23"] +script = ExtResource("2_6vba1") +type = "attack" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_inr58"] +script = ExtResource("3_juxel") +front_face = SubResource("Resource_tk6el") +back_face = SubResource("Resource_arxo3") +top_face = SubResource("Resource_c3r23") +bottom_face = SubResource("Resource_ms37x") +left_face = SubResource("Resource_l28ne") +right_face = SubResource("Resource_eguj2") +metadata/_custom_type_script = "uid://6rit5abkk1rw" + [sub_resource type="BoxMesh" id="BoxMesh_gof22"] [sub_resource type="BoxShape3D" id="BoxShape3D_tqijt"] @@ -36,6 +84,7 @@ region = Rect2(72, 144, 18, 18) physics_material_override = SubResource("PhysicsMaterial_m7tx2") gravity_scale = 2.0 script = ExtResource("1_gwnix") +configuration = SubResource("Resource_inr58") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] mesh = SubResource("BoxMesh_gof22") @@ -45,43 +94,47 @@ shape = SubResource("BoxShape3D_tqijt") [node name="Faces" type="Node3D" parent="."] -[node name="DiceFace" parent="Faces" instance=ExtResource("2_ee854")] +[node name="DiceFaceFront" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(0.7, 0, 0, 0, 0.7, 0, 0, 0, 0.7, 0, 0, 0.51) texture = ExtResource("2_6tbdd") up_rotation = Vector3(-90, 0, 0) -type = "move" -[node name="Sprite3D2" type="Sprite3D" parent="Faces"] +[node name="DiceFaceBack" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.51) pixel_size = 0.05 texture = SubResource("AtlasTexture_0hsac") -metadata/up = Vector3(90, 0, 180) -metadata/type = "move" +up_rotation = Vector3(90, 0, 180) -[node name="Sprite3D3" type="Sprite3D" parent="Faces"] +[node name="DiceFaceLeft" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.51, 0, 0) pixel_size = 0.05 texture = SubResource("AtlasTexture_2rcxj") -metadata/up = Vector3(0, -90, 90) -metadata/type = "attack" +up_rotation = Vector3(0, -90, 90) -[node name="Sprite3D4" type="Sprite3D" parent="Faces"] +[node name="DiceFaceRight" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -0.51, 0, 0) pixel_size = 0.05 texture = SubResource("AtlasTexture_l100r") -metadata/up = Vector3(0, 90, -90) -metadata/type = "attack" +up_rotation = Vector3(0, 90, -90) -[node name="Sprite3D5" type="Sprite3D" parent="Faces"] +[node name="DiceFaceTop" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.51, 0) pixel_size = 0.05 texture = SubResource("AtlasTexture_l8don") +up_rotation = Vector3(0, 180, 0) metadata/up = Vector3(0, 180, 0) metadata/type = "defend" -[node name="Sprite3D6" type="Sprite3D" parent="Faces"] +[node name="DiceFaceBottom" parent="Faces" instance=ExtResource("2_ee854")] +unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, -0.51, 0) pixel_size = 0.05 texture = SubResource("AtlasTexture_ug301") +up_rotation = Vector3(180, 0, 0) metadata/up = Vector3(180, 0, 0) metadata/type = "ability" diff --git a/stage/dice_throw/dice_configuration.gd b/stage/dice_throw/dice_configuration.gd new file mode 100644 index 0000000..48a7d22 --- /dev/null +++ b/stage/dice_throw/dice_configuration.gd @@ -0,0 +1,10 @@ +class_name DiceConfiguration +extends Resource + + +@export var front_face: DiceFaceConfiguration +@export var back_face: DiceFaceConfiguration +@export var top_face: DiceFaceConfiguration +@export var bottom_face: DiceFaceConfiguration +@export var left_face: DiceFaceConfiguration +@export var right_face: DiceFaceConfiguration diff --git a/stage/dice_throw/dice_configuration.gd.uid b/stage/dice_throw/dice_configuration.gd.uid new file mode 100644 index 0000000..e82d430 --- /dev/null +++ b/stage/dice_throw/dice_configuration.gd.uid @@ -0,0 +1 @@ +uid://6rit5abkk1rw diff --git a/stage/dice_throw/dice_face.gd b/stage/dice_throw/dice_face.gd index 6403a4c..f314a3f 100644 --- a/stage/dice_throw/dice_face.gd +++ b/stage/dice_throw/dice_face.gd @@ -1,5 +1,6 @@ +class_name DiceFace extends Sprite3D @export var up_rotation: Vector3 -@export var type: String +@export var configuration: DiceFaceConfiguration diff --git a/stage/dice_throw/dice_face_configuration.gd b/stage/dice_throw/dice_face_configuration.gd new file mode 100644 index 0000000..e75dd90 --- /dev/null +++ b/stage/dice_throw/dice_face_configuration.gd @@ -0,0 +1,6 @@ +class_name DiceFaceConfiguration +extends Resource + + +@export var type: String +@export var value: int diff --git a/stage/dice_throw/dice_face_configuration.gd.uid b/stage/dice_throw/dice_face_configuration.gd.uid new file mode 100644 index 0000000..3ffc129 --- /dev/null +++ b/stage/dice_throw/dice_face_configuration.gd.uid @@ -0,0 +1 @@ +uid://dnklife8p0m35 diff --git a/stage/dice_throw/dice_throw.gd b/stage/dice_throw/dice_throw.gd index d06a8f7..c6573be 100644 --- a/stage/dice_throw/dice_throw.gd +++ b/stage/dice_throw/dice_throw.gd @@ -8,21 +8,23 @@ func _ready() -> void: %Side.position.x = -%Side.size.x %move.text = "Move: %s" % str(Network.current_player.current_move_points) + %attack.text = "Attack: %s" % str(Network.current_player.current_attack_points) + %defend.text = "Defend: %s" % str(Network.current_player.current_defend_points) + %ability.text = "Ability: %s" % str(Network.current_player.current_ability_points) func _on_dice_throw_3d_throw_finished() -> void: await get_tree().create_timer(0.25).timeout - var dices := %DiceThrow3D/Dice.get_children() - var top_faces := [] + var dices: Array[Dice] + dices.assign(%DiceThrow3D/Dice.get_children()) + var top_faces: Array[DiceFace] = [] var tween := create_tween().set_parallel() - #tween.tween_property(%Camera3D, "rotation_degrees", Vector3(-90, 0, 0), 0.5) - #tween.tween_property(%Camera3D, "position", Vector3(0, %Camera3D.position.y, 0), 0.5) - + # move to center and rotate to camera for idx in dices.size(): - var dice: RigidBody3D = dices[idx] + var dice := dices[idx] dice.freeze = true tween.tween_property( @@ -32,20 +34,21 @@ func _on_dice_throw_3d_throw_finished() -> void: 0.25 ) - var face: Node3D = dice.get_top() + var face := dice.get_top() top_faces.append(face) - var up_rotation: Vector3 = face.get_meta("up") + var up_rotation: Vector3 = face.up_rotation var transform_vector: Vector3 if up_rotation.y != 0 and up_rotation.z != 0: transform_vector = Vector3(0, 0, 60) * sign(up_rotation.y) else: transform_vector = Vector3(60, 0, 0) * (-1 if up_rotation.y > 0 else 1) - tween.tween_property(dice, "rotation_degrees", face.get_meta("up") + transform_vector, 0.25) + tween.tween_property(dice, "rotation_degrees", face.up_rotation + transform_vector, 0.25) await tween.finished await get_tree().create_timer(0.25).timeout + # show sidebar tween = create_tween().set_parallel() tween.tween_property(%Side, "position", Vector2(0, %Side.position.y), 0.25) for dice in dices: @@ -56,17 +59,32 @@ func _on_dice_throw_3d_throw_finished() -> void: await tween.finished await get_tree().create_timer(0.25).timeout + # move to labels tween = create_tween().set_parallel() for idx in dices.size(): - var dice: RigidBody3D = dices[idx] - var node := get_node("%" + top_faces[idx].get_meta("type")) + var dice := dices[idx] + var top_face := top_faces[idx] + var node := get_node("%" + top_face.configuration.type) var p3d = %Camera3D.project_position(node.position + node.size * 0.5, 1) tween.tween_property(dice, "position", p3d, 0.25) tween.tween_property(dice, "scale", Vector3(0.1, 0.1, 0.1), 0.25) - if top_faces[idx].get_meta("type") == "move": - Network.current_player.set_current_move_points(Network.current_player.current_move_points + 1) + if top_face.configuration.type == "move": + #Network.current_player.set_current_move_points(Network.current_player.current_move_points + 1) + Network.current_player.current_move_points += top_face.configuration.value %move.text = "Move: %s" % str(Network.current_player.current_move_points) + elif top_face.configuration.type == "attack": + #Network.current_player.set_current_attack_points(Network.current_player.current_attack_points + 1) + Network.current_player.current_attack_points += top_face.configuration.value + %attack.text = "Attack: %s" % str(Network.current_player.current_attack_points) + elif top_face.configuration.type == "defend": + #Network.current_player.set_current_defend_points(Network.current_player.current_defend_points + 1) + Network.current_player.current_defend_points += top_face.configuration.value + %defend.text = "Defend: %s" % str(Network.current_player.current_defend_points) + elif top_face.configuration.type == "ability": + #Network.current_player.set_current_ability_points(Network.current_player.current_ability_points + 1) + Network.current_player.current_ability_points += top_face.configuration.value + %ability.text = "Ability: %s" % str(Network.current_player.current_ability_points) await tween.finished for dice in dices: |