@onready var gun_cooldown_timer: Timer = $GunCooldownTimer @export var cooldown = 0.25 @export var bullet_scene: PackedScene var can_shoot = true |
func _ready() -> void: start() func start() -> void: position = Vector2(screensize.x / 2, screensize.y - 64) gun_cooldown_timer.wait_time = cooldown |
func shoot() -> void: if not can_shoot: return can_shoot = false gun_cooldown_timer.start() var bullet_scene_instance = bullet_scene.instantiate() get_tree().root.add_child(bullet_scene_instance) bullet_scene_instance.start(position + Vector2(0, -8)) |
func _process(delta) -> void: ... ... position = position.clamp((ship_size / 2), screensize - (ship_size / 2)) if Input.is_action_pressed("shoot"): shoot() |
func _on_gun_cooldown_timer_timeout() -> void: can_shoot = true |