Added autoshooting
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
+2
-17
@@ -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={
|
||||
|
||||
Reference in New Issue
Block a user