diff options
Diffstat (limited to 'godot/scenes/Die.gd')
-rw-r--r-- | godot/scenes/Die.gd | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd index 66eb02c..f7d51d5 100644 --- a/godot/scenes/Die.gd +++ b/godot/scenes/Die.gd @@ -14,7 +14,8 @@ var mouse_origin = Vector2(0,0) var die_launch_force_magnitude = 0 var die_launch_force_direction = Vector3(0,0,0) var die_launch_force = Vector3(0,0,0) -var die_launch_force_multiplier = 0.001 +var die_launch_force_multiplier = 0.05 +var die_launch_force_magnitude_max = 500 var left_pressed = false var mat @@ -39,6 +40,8 @@ func _ready(): _game = get_node("/root/Game") mat = get_physics_material_override() previous_bounciness = mat.get_bounce() + $PowerUI/PowerBar.hide() + $PowerUI/PowerBar.max_value = die_launch_force_magnitude_max func _input(event): @@ -58,24 +61,30 @@ func _input(event): if event is InputEventMouseButton and dice_is_moving == false: if event.is_pressed() and left_pressed == false: - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - mouse_origin = event.global_position - camrot_v_locked_val = camrot_v left_pressed = true + camrot_v_locked_val = camrot_v + #Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + #mouse_origin = event.global_position + die_launch_force_magnitude = 0 + $PowerUI/PowerBar.show() + else: left_pressed = false - die_launch_force_magnitude = -(mouse_origin.y - event.global_position.y) + #die_launch_force_magnitude = -(mouse_origin.y - event.global_position.y) die_launch_force_direction = $CamRoot/Horizontal/Vertical/Camera.get_global_transform().basis die_launch_force_direction = -die_launch_force_direction.z - die_launch_force = die_launch_force_direction * die_launch_force_magnitude * die_launch_force_multiplier - self.apply_impulse(global_transform.origin, die_launch_force) - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - _game.add_stroke() + die_launch_force = die_launch_force_direction * clamp(die_launch_force_magnitude, 0, die_launch_force_magnitude_max) * die_launch_force_multiplier + self.apply_central_impulse(die_launch_force) + $PowerUI/PowerBar.hide() + #Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + # add one to counter if event is InputEventMouseMotion: camrot_h += -event.relative.x * sensitivity if left_pressed: camrot_v = camrot_v_locked_val + die_launch_force_magnitude += event.relative.y * sensitivity + $PowerUI/PowerBar.value = die_launch_force_magnitude else: camrot_v += -event.relative.y * sensitivity @@ -89,15 +98,11 @@ func _physics_process(delta): $CamRoot.translation.y = translation.y + 5 $CamRoot.translation.z = translation.z - if last_frame_position != Vector3(translation.x, translation.y, translation.x): - dice_is_moving = true - else: + if dice_is_moving == true and angular_velocity.length() < 0.01 and linear_velocity.length() < 0.01: dice_is_moving = false - - if angular_velocity.length() == 0: - get_buff_from_upwards_side() - - last_frame_position = Vector3(translation.x, translation.y, translation.x) + get_buff_from_upwards_side() + elif dice_is_moving == false and angular_velocity.length() >= 0.01 and linear_velocity.length() >= 0.01: + dice_is_moving = true # Called every frame. 'delta' is the elapsed time since the previous frame. |