diff --git a/game/controllers/player_controller.gd b/game/controllers/player_controller.gd index d000e34..9281ab0 100644 --- a/game/controllers/player_controller.gd +++ b/game/controllers/player_controller.gd @@ -4,24 +4,15 @@ extends Node signal accelerate(direction: Vector2, delta: float) -signal shoot(weapon_index: int) +signal shoot() signal blink(direction: Vector2) -const WEAPON_ACTIONS := { - 0: "shoot_weapon_1", - 1: "shoot_weapon_2", -} - - func _physics_process(delta: float) -> void: var input_direction := _get_input_direction() accelerate.emit(input_direction, delta) - - for index : int in WEAPON_ACTIONS: - if Input.is_action_pressed(WEAPON_ACTIONS[index]): - shoot.emit(index) + shoot.emit() func _input(event: InputEvent) -> void: diff --git a/game/entities/ships/abstract_ship.gd b/game/entities/ships/abstract_ship.gd index c30eed7..ca4f080 100644 --- a/game/entities/ships/abstract_ship.gd +++ b/game/entities/ships/abstract_ship.gd @@ -75,6 +75,11 @@ func accelerate(direction: Vector2, delta: float) -> void: velocity = velocity.normalized() * max_speed +func shoot() -> void: + for weapon in _weapons: + weapon.shoot(velocity) + + func _get_new_speed(accel: float, decel: float, current_speed: float) -> float: if is_zero_approx(accel): if absf(current_speed) < decel: diff --git a/game/entities/ships/enemies/abstract_enemy_ship.gd b/game/entities/ships/enemies/abstract_enemy_ship.gd index b7c7bb7..aa95652 100644 --- a/game/entities/ships/enemies/abstract_enemy_ship.gd +++ b/game/entities/ships/enemies/abstract_enemy_ship.gd @@ -24,11 +24,6 @@ func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void: weapon.set_belonging(AbstractWeapon.Belonging.ENEMY) -func _on_enemy_controller_shoot() -> void: - for weapon in _weapons: - weapon.shoot(velocity) - - func _on_visible_on_screen_notifier_2d_screen_entered() -> void: is_on_screen = true diff --git a/game/entities/ships/enemies/abstract_enemy_ship.tscn b/game/entities/ships/enemies/abstract_enemy_ship.tscn index 056a927..c155567 100644 --- a/game/entities/ships/enemies/abstract_enemy_ship.tscn +++ b/game/entities/ships/enemies/abstract_enemy_ship.tscn @@ -16,6 +16,6 @@ ship = NodePath("..") [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." index="5"] [connection signal="accelerate" from="EnemyController" to="." method="accelerate"] -[connection signal="shoot" from="EnemyController" to="." method="_on_enemy_controller_shoot"] +[connection signal="shoot" from="EnemyController" to="." method="shoot"] [connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_entered"] [connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/game/entities/ships/player/player_ship.gd b/game/entities/ships/player/player_ship.gd index 92b9ad2..8e1d377 100644 --- a/game/entities/ships/player/player_ship.gd +++ b/game/entities/ships/player/player_ship.gd @@ -22,12 +22,6 @@ func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void: weapon.set_belonging(AbstractWeapon.Belonging.PLAYER) -func _on_player_controller_shoot(weapon_index: int) -> void: - if weapon_index >= _weapons.size(): return - - _weapons[weapon_index].shoot(velocity) - - func _blink(direction: Vector2) -> void: if not blink_timer.is_stopped(): return diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index 1808c07..f887a90 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -61,10 +61,10 @@ one_shot = true emitting = false amount = 2 texture = SubResource("AtlasTexture_34rhw") -lifetime = 0.09999999999999999 +lifetime = 0.1 one_shot = true process_material = SubResource("ParticleProcessMaterial_pjmi2") [connection signal="accelerate" from="PlayerController" to="." method="accelerate"] [connection signal="blink" from="PlayerController" to="." method="_blink"] -[connection signal="shoot" from="PlayerController" to="." method="_on_player_controller_shoot"] +[connection signal="shoot" from="PlayerController" to="." method="shoot"] diff --git a/project.godot b/project.godot index 28d343f..e388b50 100644 --- a/project.godot +++ b/project.godot @@ -298,26 +298,11 @@ move_right={ , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } -shoot_weapon_1={ -"deadzone": 0.2, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":2,"echo":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) -] -} -shoot_weapon_2={ +blink={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":1,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":2,"echo":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null) -] -} -blink={ -"deadzone": 0.2, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":1,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194438,"key_label":0,"unicode":48,"location":0,"echo":false,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } next_reactor_scheme={