extends CharacterBody2D const SPEED = 70.0 const JUMP_VELOCITY = -200.0 var HP:int = 50 @onready var Player = $"../Playar" @onready var MIKU = $"." @onready var cooldown = $timeJUMP @onready var cooldownFIRE = $timerFIRE const Bullet_scene1 = preload("res://scene/entities/bullet.tscn")# 把 Bullet.tscn 拖进来 #@export var bullet_count: int = 5 # 一次发射几颗子弹 #@export var spread_angle: float = 65.0# 散射总角度(度) #@export var bullet_speed: float = 600.0 #@onready var muzzle: Marker2D = $Muzzle # 枪口位置(可选,没有就用玩家坐标) #@onready var FLAG:Marker2D = $FLAG #var was_on_floor = false#定义为布尔值 #func shoot(): # var angle_step = 0.0 # if bullet_count > 1: # angle_step = spread_angle / (bullet_count - 1) # var start_angle = -spread_angle / 2.0 # if is_instance_valid(Player) and is_instance_valid(MIKU): # for i in range(bullet_count): # var Bullet = Bullet_scene1.instantiate() # var current_angle = start_angle + i * angle_step # Bullet.global_position =muzzle.global_position # Bullet.target_position = Player.global_position # var direction = (Bullet.target_position - Bullet.global_position).normalized() # var rotated_direction = direction.rotated(deg_to_rad(current_angle)) # Bullet.target_position = Player.global_position + rotated_direction * 1000 # get_tree().current_scene.add_child(Bullet) # cooldownFIRE.start() var was_on_floor := false var is_dead := false func _ready() -> void: add_to_group("enemy") was_on_floor = false # 第一帧交给 _physics_process 判定 func _physics_process(delta: float) -> void: if not is_on_floor(): #重力 velocity += get_gravity() * delta var direction := signf(Player.global_position.x - global_position.x) velocity.x = direction * SPEED if is_on_floor(): velocity.y = JUMP_VELOCITY elif is_on_floor(): # 只有站在地上时才刹车,空中保留惯性 velocity.x = 0 move_and_slide() if is_on_floor() and not was_on_floor: cooldown.start() was_on_floor = is_on_floor() func take_damage(amount: int) -> void: if is_dead: return HP = max(HP - amount, 0) if HP <= 0: die() func die() -> void: is_dead = true call_deferred("queue_free") func _on_jiance_body_entered(body: Node2D) -> void: pass # Replace with function body.