From a4c91668ad2ed0c7417d552bbcc7d7e6fb4bf216 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Thu, 28 Jan 2021 12:42:26 +0100 Subject: [PATCH] Add full controller support Had to remap controlls for movement to not use ui controlls. Also had to rework the chameleon movement code a slight bit. --- Enteties/Chameleon/Chameleon.tscn | 26 +++++++++++------------ Enteties/Chameleon/chameleon.gd | 7 ++++--- project.godot | 34 +++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Enteties/Chameleon/Chameleon.tscn b/Enteties/Chameleon/Chameleon.tscn index 895676e..2639341 100644 --- a/Enteties/Chameleon/Chameleon.tscn +++ b/Enteties/Chameleon/Chameleon.tscn @@ -23,10 +23,15 @@ animations = [ { "name": "Walk_evolved", "speed": 6.0 }, { -"frames": [ ExtResource( 2 ), ExtResource( 3 ) ], -"loop": true, -"name": "Walk", -"speed": 6.0 +"frames": [ ExtResource( 4 ) ], +"loop": false, +"name": "Idle", +"speed": 1.0 +}, { +"frames": [ ExtResource( 11 ) ], +"loop": false, +"name": "Jump_evolved", +"speed": 1.0 }, { "frames": [ ExtResource( 10 ) ], "loop": false, @@ -38,15 +43,10 @@ animations = [ { "name": "Idle_evolved", "speed": 5.0 }, { -"frames": [ ExtResource( 11 ) ], -"loop": false, -"name": "Jump_evolved", -"speed": 1.0 -}, { -"frames": [ ExtResource( 4 ) ], -"loop": false, -"name": "Idle", -"speed": 1.0 +"frames": [ ExtResource( 2 ), ExtResource( 3 ) ], +"loop": true, +"name": "Walk", +"speed": 6.0 } ] [sub_resource type="CapsuleShape2D" id=2] diff --git a/Enteties/Chameleon/chameleon.gd b/Enteties/Chameleon/chameleon.gd index b96821a..8516ee5 100644 --- a/Enteties/Chameleon/chameleon.gd +++ b/Enteties/Chameleon/chameleon.gd @@ -35,16 +35,17 @@ func _on_evolving(): evolve_anim = "_evolved" func horizontal_move(direction: int): - sprite.flip_h = direction > 0 + if direction != 0: + sprite.flip_h = direction > 0 sprite.play("Walk" + evolve_anim) camo.disable() func get_horizontal_input() -> float: - return -Input.get_action_strength("ui_left") + Input.get_action_strength("ui_right") + return -Input.get_action_strength("move_left") + Input.get_action_strength("move_right") func _input(event): - if is_on_floor() && event.is_action_pressed("ui_up"): + if is_on_floor() && event.is_action_pressed("move_jump"): velocity.y = JUMP_HEIGHT camo.disable() diff --git a/project.godot b/project.godot index 6139742..56803e3 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,13 @@ window/size/height=720 [input] +ui_select={ +"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":3,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) + ] +} ui_cancel={ "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) @@ -44,7 +51,6 @@ 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(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) ] } @@ -52,7 +58,6 @@ 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(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) ] } @@ -60,9 +65,7 @@ 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(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(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(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"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={ @@ -71,11 +74,30 @@ ui_down={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777238,"unicode":0,"echo":false,"script":null) , 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) + ] +} +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(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(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) ] } move_right={ "deadzone": 0.5, -"events": [ ] +"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(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(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) + ] +} +move_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(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":0,"pressure":0.0,"pressed":false,"script":null) +, 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) + ] } [layer_names]