extends Node2D @export var roda_berputar : bool = true @export var sprite_rusak_setengah : Texture2D @export var sprite_hancur_total : Texture2D # --- BAGIAN PELURU --- @export var peluru_scene : PackedScene = preload("res://pelururiflemusuh.tscn") var health = 100 var is_destroyed = false @onready var body_sprite = $StaticBody2D/body @onready var anim_player = $AnimationPlayer @onready var roda_kiri = $StaticBody2D/roda1 @onready var roda_kanan = $StaticBody2D/roda2 # --- AMBIL TITIK TEMBAK --- @onready var titik_tembak = $TitikTembak # 🎵 BARU: AMBIL REFERENSI NODE AUDIO UNTUK SENAPAN MOBIL KEDUA @onready var audio_tembakan = $AudioStreamPlayer func _ready(): if roda_berputar and anim_player: anim_player.play("berputar") # --- MEKANISME MENEMBAK --- func mulai_menembak(): if is_destroyed: return # Tunggu 5 detik awal sebelum tembakan pertama await get_tree().create_timer(5.0).timeout _loop_tembakan() func _loop_tembakan(): while not is_destroyed and visible: # Mekanisme 5 peluru beruntun for i in range(5): if is_destroyed: break _eksekusi_tembak_peluru() await get_tree().create_timer(0.2).timeout # Jeda 5 detik sebelum rentetan berikutnya await get_tree().create_timer(5.0).timeout func _eksekusi_tembak_peluru(): if peluru_scene and titik_tembak: # 🎵 BARU: Mainkan suara rifle setiap kali satu peluru keluar (Total 5 kali beruntun) if audio_tembakan: audio_tembakan.play() var peluru = peluru_scene.instantiate() peluru.global_position = titik_tembak.global_position # Damage mobil 2 peluru.damage = 3 # Arah peluru agak serong nanjak ke kiri if "direction" in peluru: peluru.direction = Vector2(-1, -0.1).normalized() get_tree().current_scene.add_child(peluru) # --- LOGIKA NYAWA KHUSUS MOBIL KEDUA --- func kurangi_nyawa(_jumlah): if is_destroyed: return health -= 2 print("HP Mobil Kedua: ", health) if health <= 50 and health > 0: if sprite_rusak_setengah: body_sprite.texture = sprite_rusak_setengah body_sprite.scale = Vector2(1.077, 1.052) elif health <= 0: hancurkan_mobil() func hancurkan_mobil(): is_destroyed = true if anim_player: anim_player.stop() if sprite_hancur_total: body_sprite.texture = sprite_hancur_total body_sprite.scale = Vector2(1.077, 1.052) var body = get_node_or_null("StaticBody2D") if body: for child in body.get_children(): if child is CollisionPolygon2D or child is CollisionShape2D: child.set_deferred("disabled", true)