aboutsummaryrefslogtreecommitdiffstats
path: root/godot/scenes/Die.gd
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--godot/scenes/Die.gd66
1 files changed, 66 insertions, 0 deletions
diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd
new file mode 100644
index 0000000..5e238f1
--- /dev/null
+++ b/godot/scenes/Die.gd
@@ -0,0 +1,66 @@
+extends Spatial
+
+var camrot_h = 0
+var camrot_v = 0
+var camrot_v_locked_val = 0
+var cam_v_min = -90
+var cam_v_max = 90
+var sensitivity = 0.5
+var dice_is_moving = false
+var last_frame_position = Vector3(1.0,1.0,1.0)
+var dragging = false
+var mouse_origin = Vector2(0,0)
+var dice_launch_force = 0
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+ $CamRoot/Horizontal/Vertical/Camera.add_exception(self)
+ $CamRoot.set_as_toplevel(true)
+
+
+func _input(event):
+ if event is InputEventMouseMotion:
+ camrot_h += -event.relative.x * sensitivity
+ camrot_v += -event.relative.y * sensitivity
+
+ if dice_is_moving == false:
+ if event is InputEventMouseMotion and dragging:
+ # While dragging, move the sprite with the mouse.
+ dice_launch_force = mouse_origin.distance_to(event.global_position)
+ camrot_v = camrot_v_locked_val
+ elif event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ mouse_origin = event.global_position
+ camrot_v_locked_val = camrot_v
+ if not dragging and event.pressed:
+ dragging = true
+ # Stop dragging if the button is released.
+ elif dragging and not event.pressed:
+ dragging = false
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+
+
+
+
+
+func _physics_process(delta):
+ camrot_v = clamp(camrot_v, cam_v_min, cam_v_max)
+
+ $CamRoot/Horizontal.rotation_degrees.y = camrot_h
+ $CamRoot/Horizontal/Vertical.rotation_degrees.x = camrot_v
+ $CamRoot.translation.x = translation.x
+ $CamRoot.translation.y = translation.y
+ $CamRoot.translation.z = translation.z
+
+ if last_frame_position != Vector3(translation.x, translation.y, translation.x):
+ dice_is_moving = true
+ else:
+ dice_is_moving = false
+
+ last_frame_position = Vector3(translation.x, translation.y, translation.x)
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+# pass