diff --git a/addons/block_code/simple_nodes/simple_character/simple_character.gd b/addons/block_code/simple_nodes/simple_character/simple_character.gd index 1b4da5f1..674095f2 100644 --- a/addons/block_code/simple_nodes/simple_character/simple_character.gd +++ b/addons/block_code/simple_nodes/simple_character/simple_character.gd @@ -14,22 +14,20 @@ const Types = preload("res://addons/block_code/types/types.gd") @export var speed: Vector2 = Vector2(300, 300) -const PLAYER_KEYS = { - "player_1": +const PLAYER_KEYS = [ { "up": KEY_W, "down": KEY_S, "left": KEY_A, "right": KEY_D, }, - "player_2": { "up": KEY_UP, "down": KEY_DOWN, "left": KEY_LEFT, "right": KEY_RIGHT, } -} +] const PLAYER_JOYSTICK_BUTTONS = { "up": JOY_BUTTON_DPAD_UP, @@ -121,27 +119,26 @@ func _setup_actions(): if Engine.is_editor_hint() or InputMap.has_action("player_1_left"): return - for player in PLAYER_KEYS: - for action in PLAYER_KEYS[player]: + for i in PLAYER_KEYS.size(): + for action in PLAYER_KEYS[i]: + var player = "player_%d" % [i + 1] var action_name = player + "_" + action InputMap.add_action(action_name) - var device = int(player.split("_")[-1]) - 1 - #keyboard event var e = InputEventKey.new() - e.physical_keycode = PLAYER_KEYS[player][action] + e.physical_keycode = PLAYER_KEYS[i][action] InputMap.action_add_event(action_name, e) #controller d-pad event var ej = InputEventJoypadButton.new() - ej.device = device + ej.device = i ej.button_index = PLAYER_JOYSTICK_BUTTONS[action] InputMap.action_add_event(action_name, ej) #controller left stick event var ejm = InputEventJoypadMotion.new() - ejm.device = device + ejm.device = i ejm.axis = PLAYER_JOYSTICK_MOTION[action]["axis"] ejm.axis_value = PLAYER_JOYSTICK_MOTION[action]["axis_value"] InputMap.action_add_event(action_name, ejm) @@ -163,7 +160,7 @@ func move_with_player_buttons(player: String, kind: String, delta: float): if not is_on_floor(): velocity.y += gravity * delta else: - if not _jumping and Input.is_physical_key_pressed(PLAYER_KEYS[player]["up"]): + if not _jumping and direction.y < 0: _jumping = true velocity.y -= speed.y else: