Skip to content

Commit 350d793

Browse files
committed
Add shooting cooldown for turret
1 parent ec770b9 commit 350d793

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

game/ship_skeleton/cell_modifications/base_player_turret.gd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
class_name BasePlayerTurret
22
extends Node2D
33

4+
@export var _attack_cooldown := 1.0
5+
6+
var _can_shoot := true
7+
48
@onready var shooting_pos: Marker2D = %ShootingPos
9+
@onready var attack_cooldown_timer: Timer = %AttackCooldownTimer
10+
511

12+
func _ready() -> void:
13+
attack_cooldown_timer.timeout.connect(func():
14+
_can_shoot = true
15+
)
616

7-
func _unhandled_input(event: InputEvent) -> void:
8-
if event.is_action_pressed(&"shoot"):
17+
func _physics_process(delta: float) -> void:
18+
if Input.is_action_pressed(&"shoot") and _can_shoot:
19+
_can_shoot = false
20+
attack_cooldown_timer.start(_attack_cooldown)
921
# NOTE. For player will shot straight for now. For AI perhaps could rotate turrets.
1022
#var direction := shooting_pos.global_position.direction_to(get_global_mouse_position())
1123
var direction := Vector2.RIGHT.rotated(global_rotation)

game/ship_skeleton/cell_modifications/base_player_turret.tscn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ texture = ExtResource("3_jnh57")
1919
[node name="ShootingPos" type="Marker2D" parent="." unique_id=1957190253]
2020
unique_name_in_owner = true
2121
position = Vector2(35, 0)
22+
23+
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=1691874727]
24+
unique_name_in_owner = true
25+
one_shot = true

0 commit comments

Comments
 (0)