package com.zombie.game.ecs.components;

import lombok.Data;

/** Component storing entity position and facing angle / 存储实体位置和朝向角度的组件 */
@Data
public class Position {
    // X coordinate / X坐标
    private float x;
    // Y coordinate / Y坐标
    private float y;
    // Facing angle in radians / 朝向角度（弧度）
    private float angle;

    // Default constructor initializing to origin / 默认构造函数，初始化为原点
    public Position() {
        this.x = 0;
        this.y = 0;
        this.angle = 0;
    }

    // Constructor with position only / 仅带位置的构造函数
    public Position(float x, float y) {
        this.x = x;
        this.y = y;
        this.angle = 0;
    }

    // Constructor with position and angle / 带位置和角度的构造函数
    public Position(float x, float y, float angle) {
        this.x = x;
        this.y = y;
        this.angle = angle;
    }

    // Calculates Euclidean distance to a point / 计算到某点的欧几里得距离
    public float distanceTo(float px, float py) {
        float dx = px - x;
        float dy = py - y;
        return (float) Math.sqrt(dx * dx + dy * dy);
    }
}
