import javax.swing.*;
import java.awt.*;

public class GamePanel extends JPanel {
    private Player player;
    private Target target;
    private Timer timer;

    public GamePanel() {
        player = new Player(100, 100); // 玩家初始位置
        target = new Target(300, 300); // 目标初始位置
        timer = new Timer(30, e -> updateAim()); // 每30ms更新一次瞄准方向
        timer.start();
    }

    private void updateAim() {
        // 更新玩家的瞄准方向
        player.updateAim(target.getX(), target.getY(), 10); // 平滑因子为10
        repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.fillRect(player.getAimX() - 2, player.getAimY() - 2, 5, 5); // 绘制瞄准方向
        g.setColor(Color.GREEN);
        g.fillRect(player.getX(), player.getY(), 20, 20); // 绘制玩家
        g.setColor(Color.RED);
        g.fillRect(target.getX(), target.getY(), 20, 20); // 绘制目标
    }
}