public class Bullet {
    private int x, y; // 子弹当前位置
    private int targetX, targetY; // 目标位置
    private int speed; // 子弹速度
    private boolean isVisible; // 子弹是否可见

    public Bullet(int startX, int startY, int targetX, int targetY, int speed) {
        this.x = startX;
        this.y = startY;
        this.targetX = targetX;
        this.targetY = targetY;
        this.speed = speed;
        this.isVisible = true;
    }

    public void update() {
        if (!isVisible) return;

        // 计算子弹与目标的相对位置
        int dx = targetX - x;
        int dy = targetY - y;

        // 计算移动方向
        double distance = Math.sqrt(dx * dx + dy * dy);
        if (distance > speed) {
            x += (int) (dx / distance * speed);
            y += (int) (dy / distance * speed);
        } else {
            // 如果距离小于速度，直接到达目标位置
            x = targetX;
            y = targetY;
            isVisible = false; // 假设子弹命中后消失
        }
    }

    public boolean isVisible() {
        return isVisible;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}