Bladeren bron

Merge pull request #46 from StraToN/controller-support

Add support for controller
Rémi Verschelde 5 jaren geleden
bovenliggende
commit
72ab8c9075
4 gewijzigde bestanden met toevoegingen van 62 en 8 verwijderingen
  1. 6 1
      menu/menu.gd
  2. 12 1
      menu/menu.tscn
  3. 12 6
      player/player.gd
  4. 32 0
      project.godot

+ 6 - 1
menu/menu.gd

@@ -1,14 +1,17 @@
 extends Spatial
 
+func _ready():
+	$ui/main/play.grab_focus()
+
 func _on_play_pressed():
 	$ui/main.hide()
 	$ui/loading.show()
 	$begin_load_timer.start()
 
-
 func _on_settings_pressed():
 	$ui/main.hide()
 	$ui/settings.show()
+	$ui/settings/cancel.grab_focus()
 	
 	if settings.gi_quality == settings.GIQuality.HIGH:
 		$ui/settings/gi_high.pressed=true
@@ -49,6 +52,7 @@ func _on_quit_pressed():
 
 func _on_apply_pressed():
 	$ui/main.show()
+	$ui/main/play.grab_focus()
 	$ui/settings.hide()
 	
 	if $ui/settings/gi_high.pressed:
@@ -88,6 +92,7 @@ func _on_apply_pressed():
 
 func _on_cancel_pressed():
 	$ui/main.show()
+	$ui/main/play.grab_focus()
 	$ui/settings.hide()
 
 

+ 12 - 1
menu/menu.tscn

@@ -259,8 +259,16 @@ anchor_right = 1.0
 anchor_bottom = 1.0
 
 [node name="main" type="Control" parent="ui"]
+anchor_top = -0.00189865
 anchor_right = 1.0
-anchor_bottom = 1.0
+anchor_bottom = 0.998101
+margin_left = -4.10107
+margin_top = 2.05054
+margin_right = -4.10107
+margin_bottom = 2.05054
+__meta__ = {
+"_edit_use_anchors_": false
+}
 
 [node name="play" type="TextureButton" parent="ui/main"]
 margin_left = 100.0
@@ -270,6 +278,9 @@ margin_bottom = 440.0
 texture_normal = ExtResource( 7 )
 texture_pressed = ExtResource( 7 )
 texture_hover = ExtResource( 8 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
 
 [node name="settings" type="TextureButton" parent="ui/main"]
 margin_left = 100.0

+ 12 - 6
player/player.gd

@@ -1,6 +1,7 @@
 extends KinematicBody
 
-const CAMERA_ROTATION_SPEED = 0.001
+const CAMERA_MOUSE_ROTATION_SPEED = 0.001
+const CAMERA_CONTROLLER_ROTATION_SPEED = 1.0
 const CAMERA_X_ROT_MIN = -40
 const CAMERA_X_ROT_MAX = 30
 
@@ -32,8 +33,17 @@ func _ready():
 	orientation = $"Scene Root".global_transform
 	orientation.origin = Vector3()
 
+func rotate_camera(move):
+	$camera_base.rotate_y(-move.x)
+	$camera_base.orthonormalize() # After relative transforms, camera needs to be renormalized.
+	camera_x_rot += move.y
+	camera_x_rot = clamp(camera_x_rot, deg2rad(CAMERA_X_ROT_MIN), deg2rad(CAMERA_X_ROT_MAX))
+	$camera_base/camera_rot.rotation.x = camera_x_rot
 
 func _physics_process(delta):
+	var camera_move = Vector2(Input.get_action_strength("view_right") - Input.get_action_strength("view_left"),
+								Input.get_action_strength("view_up") - Input.get_action_strength("view_down"))
+	rotate_camera(camera_move * delta * CAMERA_CONTROLLER_ROTATION_SPEED)
 	var motion_target = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), 
 								Input.get_action_strength("move_forward") - Input.get_action_strength("move_back"))
 	motion = motion.linear_interpolate(motion_target, MOTION_INTERPOLATE_SPEED * delta)
@@ -155,11 +165,7 @@ func _physics_process(delta):
 
 func _input(event):
 	if event is InputEventMouseMotion:
-		$camera_base.rotate_y(-event.relative.x * CAMERA_ROTATION_SPEED)
-		$camera_base.orthonormalize() # After relative transforms, camera needs to be renormalized.
-		camera_x_rot += event.relative.y * CAMERA_ROTATION_SPEED
-		camera_x_rot = clamp(camera_x_rot, deg2rad(CAMERA_X_ROT_MIN), deg2rad(CAMERA_X_ROT_MAX))
-		$camera_base/camera_rot.rotation.x = camera_x_rot
+		rotate_camera(event.relative * CAMERA_MOUSE_ROTATION_SPEED)
 	
 	if event.is_action_pressed("quit"):
 		get_tree().quit()

+ 32 - 0
project.godot

@@ -67,24 +67,28 @@ ui_left={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
 , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
  ]
 }
 ui_right={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
 , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
  ]
 }
 ui_up={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
 , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
  ]
 }
 ui_down={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
 , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
  ]
 }
 ui_page_up={
@@ -110,41 +114,69 @@ ui_end={
 move_left={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
  ]
 }
 move_right={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
  ]
 }
 move_forward={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
  ]
 }
 move_back={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
  ]
 }
 jump={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
  ]
 }
 aim={
 "deadzone": 0.5,
 "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":6,"pressure":0.0,"pressed":false,"script":null)
  ]
 }
 shoot={
 "deadzone": 0.5,
 "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
  ]
 }
 quit={
 "deadzone": 0.5,
 "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
+ ]
+}
+view_left={
+"deadzone": 0.5,
+"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":2,"axis_value":-1.0,"script":null)
+ ]
+}
+view_right={
+"deadzone": 0.5,
+"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":2,"axis_value":1.0,"script":null)
+ ]
+}
+view_up={
+"deadzone": 0.5,
+"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":3,"axis_value":1.0,"script":null)
+ ]
+}
+view_down={
+"deadzone": 0.5,
+"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":3,"axis_value":-1.0,"script":null)
  ]
 }