diff --git a/project.godot b/project.godot index 4f40095..8fce970 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,14 @@ config/features=PackedStringArray("4.2", "GL Compatibility") window/size/viewport_width=1280 window/size/viewport_height=800 +[input] + +joy_fire={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) +] +} + [rendering] textures/canvas_textures/default_texture_filter=0 diff --git a/scenes/spaceship/CharacterBody2D.gd b/scenes/spaceship/CharacterBody2D.gd index c167c3e..d02099d 100644 --- a/scenes/spaceship/CharacterBody2D.gd +++ b/scenes/spaceship/CharacterBody2D.gd @@ -28,6 +28,8 @@ func _on_node_added(node): func _process(delta): var input_direction = Vector2.ZERO + + # Keyboard input support if Input.is_action_pressed("ui_left"): input_direction.x -= 1 $AnimatedSprite2D.play("spaceleft") @@ -42,7 +44,15 @@ func _process(delta): if Input.is_action_pressed("ui_down"): input_direction.y += 1 + # Joystick input support + var joystick_direction = Vector2( + Input.get_joy_axis(0, JOY_AXIS_LEFT_X), + Input.get_joy_axis(0, JOY_AXIS_LEFT_Y) + ) + + input_direction += joystick_direction input_direction = input_direction.normalized() + velocity += input_direction * acceleration * delta if velocity.length() > max_speed: velocity = velocity.normalized() * max_speed @@ -50,9 +60,10 @@ func _process(delta): velocity = velocity.move_toward(Vector2.ZERO, friction * delta) move_and_slide() - if Input.is_action_just_pressed("ui_select"): + if Input.is_action_just_pressed("ui_select") or Input.is_action_just_pressed("joy_fire"): fire() + func fire(): if current_fire_count > 0: var num_lasers = 1 # Количество лазеров по умолчанию