#ifndef PINGPONG_BALL_H
#define PINGPONG_BALL_H

#include <godot_cpp/classes/character_body2d.hpp>
#include <vector>

namespace godot {

// ═══════════════════════════════════════════════════════
// 视觉常量 — 以后替换为 Sprite2D 时删除本段
// (颜色值定义在 pingpong_ball.cpp 中)
// ═══════════════════════════════════════════════════════
static constexpr int BALL_TRAIL_LENGTH = 8;
static constexpr float BALL_RADIUS = 10.0f;
static constexpr float BALL_SPEED_INCREMENT = 1.03f;
static constexpr float BALL_MAX_SPEED = 800.0f;

class PingPongBall : public CharacterBody2D {
    GDCLASS(PingPongBall, CharacterBody2D)

private:
    float speed = 350.0f;
    float initial_speed = 350.0f;
    Vector2 direction = Vector2(1.0f, 0.0f);
    bool is_active = false;

    // 拖尾位置记录（视觉层）
    std::vector<Vector2> trail_positions;

protected:
    static void _bind_methods();

public:
    PingPongBall();
    ~PingPongBall();

    void _physics_process(double delta) override;
    void _ready() override;
    void _draw() override;

    // 重置球到屏幕中央，以随机角度发射
    void reset();

    // 活跃状态控制
    void set_active(bool p_active);
    bool get_active() const;

    // 属性 getter/setter
    void set_speed(float p_speed);
    float get_speed() const;

    void set_initial_speed(float p_speed);
    float get_initial_speed() const;

    // 信号: scored(int which) — 0=左边得分, 1=右边得分
};

}

#endif // PINGPONG_BALL_H
