Skip to content

Commit

Permalink
Feat/mouse sensitivity (#3)
Browse files Browse the repository at this point in the history
* Slider affects sensitivity

* Slider working as expected

* Pause is by default invisible

* Adjusted menu so it doesn't auto resize

* Using constant instead of repeating string
  • Loading branch information
telmotrooper authored Jun 25, 2021
1 parent adf57ab commit c987d4b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
6 changes: 2 additions & 4 deletions my-3d-squash-the-creeps/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var horizontal = 0
var vertical = 0
var v_min = -70 # Looking up
var v_max = 15 # Look down
var h_sensitivity = 0.5
var v_sensitivity = 0.5
var h_acceleration = 10
var v_acceleration = 10

Expand All @@ -16,8 +14,8 @@ func _ready():

func _input(event):
if event is InputEventMouseMotion:
horizontal -= event.relative.x * h_sensitivity
vertical -= event.relative.y * v_sensitivity
horizontal -= event.relative.x * GameState.mouse_sensitivity
vertical -= event.relative.y * GameState.mouse_sensitivity

func _physics_process(delta):
#print(vertical) # It's useful to print the current value when trying to find the proper values for 'min' and 'max'.
Expand Down
1 change: 1 addition & 0 deletions my-3d-squash-the-creeps/GameState.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
extends Node

var Audio: Node
export var mouse_sensitivity := 0.5
40 changes: 28 additions & 12 deletions my-3d-squash-the-creeps/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,46 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -112.0
margin_top = -77.0
margin_right = 112.0
margin_bottom = 77.0
margin_left = -139.0
margin_top = -99.0
margin_right = 139.0
margin_bottom = 99.0
custom_constants/separation = 10
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ResumeButton" type="Button" parent="UserInterface/Pause/VBoxContainer"]
margin_top = 35.0
margin_right = 224.0
margin_bottom = 72.0
margin_right = 278.0
margin_bottom = 37.0
text = "Resume"

[node name="ToggleFullscreenButton" type="Button" parent="UserInterface/Pause/VBoxContainer"]
margin_right = 12.0
margin_bottom = 37.0
margin_top = 47.0
margin_right = 278.0
margin_bottom = 84.0
text = "Toggle Fullscreen"

[node name="SensitivityLabel" type="Label" parent="UserInterface/Pause/VBoxContainer"]
margin_top = 94.0
margin_right = 278.0
margin_bottom = 125.0
text = "Mouse Sensitivity: "

[node name="SensitivitySlider" type="HSlider" parent="UserInterface/Pause/VBoxContainer"]
margin_top = 135.0
margin_right = 278.0
margin_bottom = 151.0
min_value = 0.1
max_value = 1.0
step = 0.1
value = 0.1

[node name="ExitButton" type="Button" parent="UserInterface/Pause/VBoxContainer"]
margin_top = 82.0
margin_right = 224.0
margin_bottom = 119.0
margin_top = 161.0
margin_right = 278.0
margin_bottom = 198.0
text = "Exit"

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
Expand Down Expand Up @@ -249,5 +264,6 @@ transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 3.5,
[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
[connection signal="pressed" from="UserInterface/Pause/VBoxContainer/ResumeButton" to="UserInterface/Pause" method="_on_ResumeButton_pressed"]
[connection signal="pressed" from="UserInterface/Pause/VBoxContainer/ToggleFullscreenButton" to="UserInterface/Pause" method="_on_ToggleFullscreenButton_pressed"]
[connection signal="value_changed" from="UserInterface/Pause/VBoxContainer/SensitivitySlider" to="UserInterface/Pause" method="_on_SensitivitySlider_value_changed"]
[connection signal="pressed" from="UserInterface/Pause/VBoxContainer/ExitButton" to="UserInterface/Pause" method="_on_ExitButton_pressed"]
[connection signal="body_entered" from="Boundary" to="Boundary" method="_on_Boundary_body_entered"]
11 changes: 11 additions & 0 deletions my-3d-squash-the-creeps/Pause.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
extends Control

const sensitivity_text = "Mouse Sensitivity: %.1f"

func _ready():
$VBoxContainer/SensitivityLabel.text = sensitivity_text % GameState.mouse_sensitivity
$VBoxContainer/SensitivitySlider.value = GameState.mouse_sensitivity

func _on_SensitivitySlider_value_changed(value):
GameState.mouse_sensitivity = value
$VBoxContainer/SensitivityLabel.text = sensitivity_text % value


func pause():
get_tree().paused = not get_tree().paused
visible = get_tree().paused
Expand Down

0 comments on commit c987d4b

Please sign in to comment.