@@ -41,52 +41,85 @@ var actions := [
4141 "roll_left" , "roll_right" ,
4242]
4343
44+ # Track which actions are currently pressed
45+ var pressed_actions := {}
46+
4447func _ready () -> void :
4548 main_scene = get_node_or_null (main_scene_path )
4649 if main_scene == null :
4750 main_scene = get_tree ().current_scene
4851 _ensure_default_actions ()
52+
53+ # Initialize pressed actions tracking
54+ for action in actions :
55+ pressed_actions [action ] = false
4956
50- func _physics_process ( _delta : float ) -> void :
57+ func _input ( event : InputEvent ) -> void :
5158 var ship := _get_active_ship ()
5259 if ship == null :
5360 return
54-
55- # Early return if no relevant inputs are pressed
56- var has_input := false
57-
5861
62+ # Handle primary action (spacebar) - immediate response
63+ if event .is_action_pressed ("action_primary" ):
64+ ship .computer .emulator .set_memory (0x020A , 255 )
65+ get_viewport ().set_input_as_handled ()
66+ return
67+ elif event .is_action_released ("action_primary" ):
68+ ship .computer .emulator .set_memory (0x020A , 0 )
69+ get_viewport ().set_input_as_handled ()
70+ return
71+
72+ # Handle movement actions
73+ var action_changed := false
5974 for action in actions :
60- if Input .is_action_pressed (action ):
61- has_input = true
75+ if event .is_action_pressed (action ):
76+ if not pressed_actions [action ]:
77+ pressed_actions [action ] = true
78+ action_changed = true
79+ elif event .is_action_released (action ):
80+ if pressed_actions [action ]:
81+ pressed_actions [action ] = false
82+ action_changed = true
83+
84+ # Only update thrusters if an action state changed
85+ if action_changed :
86+ _update_thrusters (ship )
87+ get_viewport ().set_input_as_handled ()
88+
89+ func _update_thrusters (ship : Node ) -> void :
90+ # Check if any movement actions are pressed
91+ var has_movement_input := false
92+ for action in actions :
93+ if pressed_actions [action ]:
94+ has_movement_input = true
6295 break
6396
64- if not has_input :
97+ # If no movement inputs, clear thrusters
98+ if not has_movement_input :
99+ ship .computer .emulator .set_memory (REG [0 ], 0 )
100+ ship .computer .emulator .set_memory (REG [1 ], 0 )
101+ ship .computer .emulator .set_memory (REG [2 ], 0 )
102+ ship .computer .emulator .set_memory (REG [3 ], 0 )
65103 return
66- # Compute thruster masks from held inputs
104+
105+ # Compute thruster masks from pressed actions
67106 var masks := _compute_thruster_masks ()
68-
69- # Write thrusters (zeros if no input)
107+
108+ # Write thrusters
70109 for i in range (4 ):
71110 ship .computer .emulator .set_memory (REG [i ], masks [i ])
72111
73- # Primary action (continuous)
74- if Input .is_action_pressed ("action_primary" ):
75- ship .computer .emulator .set_memory (0x020A , 255 )
76- elif Input .is_action_just_released ("action_primary" ):
77- ship .computer .emulator .set_memory (0x020A , 0 )
78-
79112func _compute_thruster_masks () -> Array :
80113 var masks := [0 , 0 , 0 , 0 ]
81114
82115 # OR all pressed action patterns together
83- for a in actions :
84- if Input . is_action_pressed ( a ) :
85- var pattern : Array = ACTION_MAP [a ]
116+ for action in actions :
117+ if pressed_actions [ action ] :
118+ var pattern : Array = ACTION_MAP [action ]
86119 for i in range (4 ):
87120 masks [i ] |= int (pattern [i ])
88121
89- # Cancel opposed bits per quad (don’ t fire LEFT & RIGHT or TOP & BOTTOM together)
122+ # Cancel opposed bits per quad (don' t fire LEFT & RIGHT or TOP & BOTTOM together)
90123 for i in range (4 ):
91124 var m : Variant = masks [i ]
92125 if (m & RIGHT ) != 0 and (m & LEFT ) != 0 :
0 commit comments